manual item enabling
manual item enabling
- Subject: manual item enabling
- From: Kurt Bigler via Cocoa-dev <email@hidden>
- Date: Sun, 24 Nov 2019 13:28:06 -0800
I have an app in final stages of conversion from Carbon to Cocoa. It uses a
legacy architecture for menu item enabling that originated with the Think Class
Library. It is not really practical to consider redoing the entire
implementation so I am retrofitting it. The method used is to make a pass
through what is equivalent to the responder chain and have each object do its
piece of updating the entire menu hierarchy. In other words there is no
separation by item, no per-menu-item callbacks to establish an individual items
state.
I would have thought that unchecking auto-enabling in all menus in the xib would
have let me do what I need. This actually works perfectly for menu items
selected with the mouse, but I can't get enabling to work correctly for key
equivalents.
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. I found something to override that let me accomplish that aspect.
The last possible moment for key equivalents is a keyDown event.
Unfortunately Cocoa doesn't seem to let me catch this event and act on it to
update menus prior to key equivalent processing.
First I tried just overriding sendEvent in an NSApplication subclass. There
were some additional troubles with this approach and I had better luck by
installing an event monitor for keyDown events. The symptom is still that the
menus are apparently not updated "in time" for the system to decide that the
current event should be processed as a key equivalent. So what happens is if an
item was disabled and needs to be enabled and its key equivalent is typed, the
menu command is not executed, but the menu is updated and a repeated typing of
the same key equivalent then works.
I even tried having the event monitor absorb the event and re-queue it via
postEvent:atStart:, but that method still produced the same behavior.
It gives me the impression that the menu item state updating is somehow being
deferred, e.g., maybe until the event queue is empty or something. I haven't
yet tried requeuing the event on a timer.
I'll appreciate any thoughts at all. I would not have thought that this legacy
approach to menu enabling would be so obscure as to be unsupportable in Cocoa.
Thanks in advance.
-Kurt Bigler
_______________________________________________
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