Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Correct way to handle kEventCommandUpdateStatus?



On Aug 29, 2003, at 11:17 AM, Jim Correia wrote:

So given an application with a custom window which can respond to kCommandFoo and kCommandBar following this example my window should enable kCommandFoo and kCommandBar when appropriate. The application can always disable them so they aren't enabled if a window which can handle them is around.

However, this doesn't appear to scale well.

If my window can handle 100 commands, then the application also has to know about those specific 100 command ids so it can disable them if the event percolates up to the application.

Am I missing something in how this event should be handled conceptually? Is there a better way to deal with this situation?

I hadn't really thought about this particular issue before, but yes, this seems to be a valid concern to me. Your app does need to know about all the command IDs that would need to be disabled if no window is open to implement that command ID. As the set of command IDs grows larger, a simple switch statement could potentially be quite inefficient, depending on what kind of code the compiler generates.

You might consider having a little command management architecture that would keep, say, a CFSet of all the app's command IDs, using the command ID as the key. Your app handler could look up the command ID in the set (which should be much faster than a linear search over all command IDs) and disable the menu item if the command ID is present in the set.

In Panther, we've also got a new menu item attribute, kMenuItemAttrAutoDisable, which indicates that a menu item should be automatically disabled if all kEventCommandUpdateStatus handlers return eventNotHandledErr. You could set that attribute on your menu items and then you wouldn't need an application handler just to disable items.

-eric
_______________________________________________
carbon-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/carbon-development
Do not post admin requests to the list. They will be ignored.

References: 
 >Correct way to handle kEventCommandUpdateStatus? (From: Jim Correia <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.