NSMenu + setSubmenu
NSMenu + setSubmenu
- Subject: NSMenu + setSubmenu
- From: Brian Amerige <email@hidden>
- Date: Tue, 10 Jul 2007 17:47:51 -0400
Hi all,
I've got an NSMenu that's dynamic. Basically, depending on what's
selected in an NSTableView, it's items are changed. (Think of it as
an "Open With" item, similar to the Finder's).
The problem is, as of now, everytime the selection changes, the menu
needs to be updated with new relevant items. In my mind,
theoretically, the best solution would be to remove all the existing
items, then call a method (that doesn't exist for NSMenu) akin to
setItemArray:.
To accomplish something similar, previously I was enumerating through
the menu's itemArray, removing each item (as there is no
removeAllItems method in NSMenu), then enumerating over the new
itemArray and using addItem for each. This is a problem for a few
reasons. For one, having to enumerate to delete each item, then
enumerate to add items, is slow.
That in mind, I decided I'd try to just cache the submenu's
themselves, and swap it out with setSubmenu: when I need to.
But unfortunately, I get the call to update the menu from NSMenu's
delegate method, menuNeedsUpdate. So the basic workflow is:
user activates contextual menu -> hovers over "open with" item which
has an empty submenu -> I receive the empty submenu's menuNeedsUpdate
call -> I call setSubmenu on the "Open With" item -> Nothing appears
to visually happen.
This is because I'm calling setSubmenu in order to replace a menu
that's already been displayed.
However, when I click away and reactivate the menu, the submenu I set
before is visible. It's always one "setSubmenu" behind because I call
setSubmenu *after* the menu I'm replacing is displayed.
Thoughts and alternate solutions?
Brian Amerige: Software at Extendmac
email@hidden | aim - applejustworks
_______________________________________________
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