On 21 Aug 2011, at 21:57, Quincey Morris wrote: > 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 ? >
> 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. I've been trying to do this during the last half hour, but without success so far... I'll give it one more go tomorrow. > > 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. Using the app-delegate is what I've implemented at this moment, and this works just fine. If the other solution (see above) doesn't work, this is what I'll stick to. > > But unless you're forced into this more invasive approach, I'd suggest you > try the dummy action solution. > Thanks (again) for your help. _______________________________________________ Cocoa-dev mailing list ([email protected]) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
