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 Friday, August 29, 2003, at 03:06 PM, Eric Schlegel wrote:

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.

Right now I'm trying to get two things sorted out - the practical issues of this problem in a large application and the conceptual issues.

For the practical side of things I figured I would have to do something like you mentioned, but wanted to make sure there wasn't some obvious thing I was missing that would make life easier. Knowing that there isn't helps.

Conceptually I'm still strugging a bit with the fact that a generic application "object" has to know about all the commands all windows/custom controls/etc might implement in order to make sure they are disabled if these windows/etc aren't available.

For code I control I can just say register all of my commands in a table. But what happens if I load a plug-in which inserts a menu into my menubar with custom commands in it available only to the plug-in window?? (This isn't a real situation - I'm making it up so I can understand the conceptual model that we are supposed to be using with kEventCommandUpdateStatus.) My application doesn't know about the commands it put in there. Should it be the plug-in's responsibility to also install an application level handler to make sure its commands get disabled?

If that conceptually makes sense, should each "object" that introduces custom commands into the application also install its own application level handler to make sure its commands get disabled when appropriate, removing the need for the application object to know about custom window commands? This is probably not as efficient as the set lookup, but might provide better encapsulation?

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.

That is useful information for the future when 10.3 would be a reasonable minimum requirement for a product.

Thanks,
Jim
_______________________________________________
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: 
 >Re: Correct way to handle kEventCommandUpdateStatus? (From: Eric Schlegel <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.