Re: Document-based app: UI item validation
Re: Document-based app: UI item validation
- Subject: Re: Document-based app: UI item validation
- From: Quincey Morris <email@hidden>
- Date: Sun, 21 Aug 2011 12:57:22 -0700
On Aug 21, 2011, at 12:22 , Luc Van Bogaert wrote:
> What I was trying to explain: I want to change the title of a menuitem, which opens a submenu. Of course the menu items in that submenu all have actions, but the action of the menuitem I'm trying to change is '' submenuAction".
OK, gotcha.
> So, in order to validate my menuitem in the normal way, do I understand correctly that I would have to subclass NSMenu and assign this new class to the menu that is opened by my menuitem, and that I could implement 'validateUserInterfaceItems' in my new subclass ?
I've had almost the same situation, except that I wanted to enable/disable the action-less menu item depending on whether any of the submenu items are enabled. (By default, a menu item with a submenu stays enabled, which makes sense from one point of view -- it still lets you look at the submenus. However, in this application (I decided), it adds an unwanted and ergonomically awkward step if the user has to open the submenu to find out if any item in the submenu can do anything right now.)
My solution was to assign the menu item (the one with the submenu) a dummy action that does nothing. Then I used the normal 'validateUserInterfaceItem:' mechanism to enable or disable the menu item with that action, based on whether all of the submenu items were enabled or not. You could use a similar approach to change the menu title instead of its enable status. It's certainly possible that there's some obscure, unwanted UI behavioral side-effect of doing this, but I haven't seen any.
For completeness, I'll add that if there's some genuine reason why you couldn't use the 'validateUserInterfaceItem:' mechanism to solve your problem, then the correct solution may well be to use a menu delegate after all. But in that case, I wouldn't use the window controller as the delegate, I'd use a global (singleton) object such as the app delegate instead. That would move you're app's knowledge of the menu structure (which is app-global knowledge more than document-specific knowledge) into an app-global place, and it would properly separate the menu-structuring behavior from the menu-validating behavior.
But unless you're forced into this more invasive approach, I'd suggest you try the dummy action solution.
_______________________________________________
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