tony-

thanks for the suggestion, i decided to take another approach for now,
but in the future i will probably take the "represented object" approach.

thanks,
augusto.

On Jun 25, 2010, at 6:39 PM, Tony Romano wrote:

> What I do is create an object that represents the data you need for your 
> action.  During menuNeedsUpdate, instantiate an instance of the object that 
> will be used later and then call [menuItemName 
> setRepresentedObject:objectYouCreated] where menuItemName is the menuItem 
> object you need to associate the object with and objectYouCreate in the 
> entity object storing the data to be used later.  This item will live for the 
> life of the menu which includes the target handler.  In the target handler, 
> the parameter you get is the menu item. Just make a call to [sender 
> representedObject] and you get your object back.  Ref counting should be 
> straight forward.
> 
> 
> HTH,
> -Tony
> 
> On Jun 25, 2010, at 4:16 PM, Peter Ammon wrote:
> 
>> Unfortunately this isn't as easy as it should be.  Since the menu action can 
>> do anything, including trigger menu tracking again, it really does need to 
>> happen last.
>> 
>> I think your best option is to use performSelector:afterDelay: from within 
>> menuDidClose:.
>> 
>> Another possibility is to tie the lifetime of your resources to the menu 
>> items themselves (e.g. set them as the represented object of the menu item). 
>>  In SnowLeopard, we support the scenario of an NSMenuItem being removed from 
>> the menu after the item is selected by the user, but before the item's 
>> action fires.  This allows you to tear down the menu (for example, in 
>> NSMenuDidEndTrackingNotification): the NSMenuItem will be retained until its 
>> action fires.  However, this does not work in Leopard and earlier.
>> 
>> -Peter
>> 
>> On Jun 25, 2010, at 3:41 PM, augusto callejas wrote:
>> 
>>> peter-
>>> 
>>> actually i wanted to be notified before the menu is closed,
>>> because i'm freeing some resources when the menu is closed,
>>> but i'm depending on those resources to be around when it
>>> comes time to execute the menu item's action.  perhaps
>>> i can't free those resources and need to take care of that
>>> somewhere else?
>>> 
>>> thanks,
>>> augusto.
>>> 
>>> On Jun 25, 2010, at 3:26 PM, Peter Ammon wrote:
>>> 
>>>> 
>>>> On Jun 25, 2010, at 2:58 PM, augusto callejas wrote:
>>>> 
>>>>> hi-
>>>>> 
>>>>> i'm constructing an NSMenu with a delegate to handle menuDidClose.
>>>>> that menu has an NSMenuItem that had an action to handle when its 
>>>>> selected.
>>>>> when i select the menu item from the menu, it calls menuDidClose, and then
>>>>> the action of the NSMenuItem.  i would expect the other order, but the 
>>>>> documentation
>>>>> doesn't state what order these messages are sent.  is there a way to 
>>>>> specify what
>>>>> order these messages are sent?
>>>>> 
>>>>> thanks,
>>>>> augusto._______________________________________________
>>>> 
>>>> Hi Augusto,
>>>> 
>>>> The menu always closes before the action is sent.  Imagine the user 
>>>> choosing File->Open:  if the action were sent before the menu was closed, 
>>>> the File menu would remain open until the Open panel is dismissed.
>>>> 
>>>> If you want to be notified after the action is sent, perhaps you want 
>>>> NSMenuDidSendActionNotification.
>>>> 
>>>> Hope this helps,
>>>> -Peter
>>> 
>> 
>> _______________________________________________
>> 
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>> 
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>> 
>> Help/Unsubscribe/Update your Subscription:
>> http://lists.apple.com/mailman/options/cocoa-dev/tonyrom%40hotmail.com
>> 
>> This email sent to tony...@hotmail.com
>> 
> 
> -Tony
> 

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to