Re: populate/resize an already open NSMenu in background
Re: populate/resize an already open NSMenu in background
- Subject: Re: populate/resize an already open NSMenu in background
- From: Peter Ammon <email@hidden>
- Date: Fri, 19 Dec 2008 15:53:04 -0800
On Dec 19, 2008, at 1:21 PM, Martin Wierschin wrote:
Hi everyone,
I have a menu that needs to be populated on demand, so I've set an
NSMenu delegate and note the update request in "menuNeedsUpdate:".
The problem is that populating the menu can take quite a while, so
results need to be generated in the background and then added as
they come in. Think of something like the system Spotlight menu,
where file matches are appended as they are found.
The problem is that the NSMenu will not resize itself to show items
added from outside of "menuNeedsUpdate:".
If I call "update" and/or "resizeToFit" the menu does change its
display to show the changed/reordered items, but never resizes
itself beyond the capacity established in "menuNeedsUpdate".
Has anyone ever gotten this kind of thing to work? I do notice that
moving the mouse to hide the menu and then reshow it allows the
NSMenu to resize itself as needed. Perhaps I should look into faking
mouse events to trigger this kind of thing programmatically- seems
like a horrible hack.
It should not be necessary to fake mouse events. A common cause of
failure is that your menuNeedsUpdate: call leaves the menu empty. A
user cannot select from an empty menu, so menu tracking just ends in
that case. Make sure the menu item has at least one item, such as
"Building...", after the call to menuNeedsUpdate:.
Another possible cause is that you are populating the menu with a
timer or some run loop source that is only added in the default or
common run loop mode. Menu tracking happens in
NSEventTrackingRunLoopMode; make sure any timers you have that you
want to fire are added to the run loop in this mode.
A third possible cause is that you're on Tiger. Changing a menu while
it is open is only supported on Leopard.
If that doesn't solve it for you, please put together a sample showing
the problem and I'll take a look.
-Peter
_______________________________________________
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