On 25 Nov 2019, at 7:36, Kurt Bigler via Cocoa-dev wrote:

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

A menu delegate is the officially supported way to populate a menu lazily, i.e. just before it is needed, either when the user opens it via mouse or presses a key equivalent that may trigger a menu item.

Is this not essentially what you want to do? Populate/update the menu just before it is needed, rather than in advance with dynamic validation?

Of course if your code is scattered and affects hundreds of menu items in different menus, it will require some work to bridge this API with what you have, but such is the case when you have code written for a different type of API.

However, going along with the line of thought shown in your original post, you probably want to use a NSMenu subclass as your application’s main menu and then overload performKeyEquivalent: as that would allow you to update the menu prior to calling super, but this makes assumptions about how the menu system is currently implemented so it can break, and I would strongly advise that you use a menu delegate instead.
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to