Re: Menu items sensitive to modifiers
Re: Menu items sensitive to modifiers
- Subject: Re: Menu items sensitive to modifiers
- From: Greg Titus <email@hidden>
- Date: Sun, 14 Apr 2002 22:11:28 -0700
You can't do this via Cocoa alone. You need to use the Carbon
ChangeMenuItemAttributes() call with kMenuItemAttrDynamic.
If you link with OmniAppKit, and have multiple consecutive items in your
nib whose keyboard equivalents differ only by a modifier key, and give
them a tag of 1 in the inspector, then OmniAppKit will set up the menu
items for you so that they are dynamic based on the modifier. (For
instance, look in OmniWeb's Window menu in the nib versus when it is
running.)
The menu items dynamically replace each other, so to the rest of your
code (your -validateMenuItem: method, for instance) it will still be two
different menu items, so one can be enabled while the other isn't, and
so on, exactly as if you just had both of them in the menu still. (Which
you do.)
The source code for this is in +_setupDynamicMenus: in OAApplication.m.
Note that this uses the private _NSGetCarbonMenu() function, so BE
PREPARED FOR THIS TO BREAK in any future version of OS X.
Hope this helps,
--Greg
On Sunday, April 14, 2002, at 09:44 PM, email@hidden wrote:
I want to make a menu item change its title (and its enable state, in
some cases) when a modifier key is held down. This used to be a
reasonably common thing to do in MacOS <X, IIRC. But I can't figure
out any way to do it in Cocoa. My validateMenuItem: method doesn't get
called when the modifier keys change while the user is tracking the
menu. Neither does -[NSApplication sendEvent:]. It appears that a
private tracking loop is in effect, and I can't see a way to get in.
Am I missing something? Has anybody hacked up a way to do this? I
looked in the archives and didn't find anything relevant, and the docs
seem to be remarkably close-mouthed about the whole process of
autoenabling -- when exactly it gets done, who does it, etc.
Thanks for any help...
Ben Haller
Stick Software
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.