Re: menu action never being called?
Re: menu action never being called?
- Subject: Re: menu action never being called?
- From: Graham Cox <email@hidden>
- Date: Wed, 4 Nov 2009 12:50:21 +1100
On 04/11/2009, at 12:25 PM, David M. Cotter wrote:
i have a menu that lives in the menu bar (top level)
but i also use it in a context menu
when the context menu is about to be shown, i take the menu out of
the menu bar (substituting an empty menu by the same name so the
menu bar doesn't flicker with the menu suddenly missing) and stick
it in the context menu, then pop up the menu.
i've also got a menuAction selector set for all menu items, so i can
handle what happens manually, yes crazy but there's no way to change
it right now.
this procedure works for all *sub* menus from the menu bar, that is,
if the menu is a sub-menu off of a top level menu in the menu bar,
then temporarily relocating it to the context menu works fine, the
menuAction gets called.
however this fails when it is this main menu bar menu.
i traced it somewhere in NSSLMMenuEventHandler, in the normal case
it gets into
[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] but in
the fail case it never gets there.
i am totally at a loss here
This is surely because the way you're going about this is completely
unreasonable.
Menu items are pretty lightweight and easily created, so why go to all
the trouble of "borrowing" from the main menu bar when all you need to
do is to make a new menu item for your contextual menu and set its
selector/target directly. There is no problem with having any number
of menu items targeting the same target and selector.
For contextual menus, just override [NSView menuForEvent:] and build
whatever menu is appropriate.
Having a single dispatch selector for all menus is also bad design
(how do you tell which menu item is which? Please don't tell me you
have hundreds of different tags?). You say it can't be changed but
it's hard to see a case where it would be impossible to change. I
suggest you do migrate your code to having separate actions as soon as
possible - for one thing managing the proper state of menu items when
they all go to the same action is going to be much harder than it
needs to be, as well as making the code very confusing to read and
difficult to debug.
--Graham
_______________________________________________
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