> On Nov 25, 2019, at 1:26 AM, Allan Odgaard via Cocoa-dev > <cocoa-dev@lists.apple.com> wrote: > > 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.
That would probably work, but there are other cases where you’ll want to implement -menuNeedsUpdate as well; for example, if an Accessibility API client is inspecting your menus (VoiceOver, for example), it will want your application to update its menu state before returning the enabled/disabled state of each menu item. The only way to hook into that process and properly set the enabled state of your menu items is to use -menuNeedsUpdate; there’s no other place to intercept Accessibility calls. So Kurt, please do the work to use -menuNeedsUpdate, even if it means writing a caching layer between your delegate implementation and the rest of your app. -eric _______________________________________________ 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