Re: manual item enabling
Re: manual item enabling
- Subject: Re: manual item enabling
- From: Kurt Bigler via Cocoa-dev <email@hidden>
- Date: Sun, 24 Nov 2019 22:36:09 -0800
On 11/24/19 1:37:17 PM, Allan Odgaard via Cocoa-dev wrote:
On 24 Nov 2019, at 22:28, Kurt Bigler via Cocoa-dev wrote:
[…] The idea for least inefficiency given the global updating pass is to defer
(akin to lazy evaluation) the actual menu item updating until the last
possible moment. The last possible moment for mouse access is when the user
clicks in the menu bar.
Have a look at NSMenu’s delegate property which allows you to set a delegate
implementing the NSMenuDelegate protocol:
https://developer.apple.com/documentation/appkit/nsmenudelegate
With a menu delegate you can lazily update the menu (menuNeedsUpdate:) or you
can even bypass updating the menu for key events by implementing
menuHasKeyEquivalent:forEvent:target:action:.
I'm not sure that's relevant to my situation, so I want to clarify a little. My
menu updating code is not exactly monolithic, but distributed through an object
hierarchy there is a *single* sequence of calls to
[menuItem setEnabled: ...];
and
[menuItem setState: ...];
etc. which in that single sequence update everything under the menu bar, i.e. a
dozen or so menus and submenus totalling almost 200 items. In other words there
are several hundred such calls that come in quick succession, and always
together. All dynamically enabled menu items under the menu bar get updated.
There is no situation in which I want to update an item, or an entire menu, in
isolation. The code is not capable of that without a complete rewrite, which
would then also make it incompatible with another platform.
So I could do something like cache the entire menu state resulting from the
current legacy menu updating code, and then have the menu system query that
cached state, by telling it that every menu needed to be updated.
Such an approach would bridge the legacy method to what is maybe Cocoa's
preferred way of thinking, and is maybe not so bad but requires adding another
level of representation. So I was hoping to do something more straightforward,
and no less efficient given the restrictions of the legacy logic.
I don't need to bypass anything regarding key equivalents. I just need Cocoa to
not prevent or defer the effects of menu enabling on key shortcuts, as it
currently seems to do when I try to update menus manually, for no reasons I can
understand.
I hope that's a little clearer. Thanks!
-Kurt
_______________________________________________
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