Re: Setting key equivalent for menus depending on window
Re: Setting key equivalent for menus depending on window
- Subject: Re: Setting key equivalent for menus depending on window
- From: Ken Thomases <email@hidden>
- Date: Sun, 20 Oct 2013 15:29:15 -0500
On Oct 20, 2013, at 2:50 PM, Charles Srstka wrote:
> On Oct 20, 2013, at 2:37 PM, Ken Thomases <email@hidden> wrote:
>
>> On Oct 20, 2013, at 2:29 PM, Charles Srstka wrote:
>>
>>> -menuNeedsUpdate: has the same problem that -validateMenuItem: has. It doesn't get called until the menu is about to be actually drawn, which doesn't happen until the user clicks on your menu.
>>
>> This isn't correct. Menus are updated/validated when resolving keyboard shortcuts. What makes you think otherwise? Lots of things wouldn't work if that weren't so.
>
> Huh, I just tested this, and you're right. I stand corrected.
>
> However, this appears to be undocumented behavior, since the documentation clearly states that this is supposed to be invoked when the menu is being displayed:
>
> https://developer.apple.com/library/Mac/documentation/Cocoa/Reference/NSMenuDelegate_Protocol/Reference/Reference.html#//apple_ref/doc/uid/TP40008605-CH1-SW14
>
> menuNeedsUpdate:
> Invoked when a menu is about to be displayed at the start of a tracking session so the delegate can modify the menu.
>
> - (void)menuNeedsUpdate:(NSMenu *)menu
> Parameters
> menu
> The menu object that is about to be displayed.
>
> Given that this behavior is not guaranteed by the documentation, I'm not sure that it should be relied on.
Well, you're right about the documentation (although it says it will be called when the menu is about to be display, not that it won't be called under other circumstances). However, I will refer you to a WWDC video I've referenced before on this list: WWDC 2010 Session 145 - Key Event Handling in Cocoa Applications. It mentions -menuNeedsUpdate: being called around the 7:55 mark. It states it's called prior to display, for keyboard shortcut resolution, for accessibility, and for the Search field in the Help menu. (I wouldn't necessarily assume it's limited to those occasions, either.)
Regards,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden