On 21 Aug 2011, at 19:34, Quincey Morris wrote:

> On Aug 21, 2011, at 09:59 , Luc Van Bogaert wrote:
> 
>> But this still leaves me with the question of how to reference my 
>> windowcontroller objects from the mainmenu nib? I need this because I want 
>> to modify the title of some menu items, depending on the state of the 
>> document windows. So I would like to make my windowcontroller objects menu 
>> delegates.
> 
> This isn't the ordinary way of getting this result.
> 
> The ordinary way is to implement 'validateUserInterfaceItem:' in each object 
> in the action responder chain that is responsible for some of the menu items. 
> In that method, the object checks to see if the item being "validated" is one 
> of the ones it it responsible for (which may be different at different times, 
> depending on the state of the document and/or the application). If so, it is 
> free to do anything it wants to the item, including changing the title.
> 
> This decentralizes control over menu items (and other UI items handled 
> through the same mechanism), which can make it hard to get a grasp on what 
> items are handled where, but also makes decentralization of the interface via 
> multiple nib files possible, which is the purpose you're trying to achieve.
> 
>> I thought about using an application delegate as file's owner in the 
>> mainmenu nib, and then target the menu items from this delegate. From the 
>> app delegate I can reference the window using keyWindow, but I haven't found 
>> a way to reference the windowcontroller objects...
> 
> Changing the main menu nib's Files Owner sounds like a terrible idea.
> 
> You're ignoring a fairly rich set of object interrelationships that eliminate 
> the need to invent odd ways of referencing things. There is a singleton 
> NSDocumentController that lists all the documents. Each document has a list 
> of its window controller. Each window controller has a reference to its 
> window. Windows have a "windowController" property. Window controllers have a 
> "document" property. What is it that you think is missing?
> 
> That's beside the point, though, because if you handle the menu item 
> validation the "ordinary way", you won't need to solve this unnecessary 
> problem.
> 

Thanks Quincey,

I have found a way to get what I want using the sharedDocumentController object 
and the current document's list of windows.

But actually, I'd prefer using 'validateUserInterfaceItems' as you suggest, 
except that some of the menu items that I want to change, are actually 
submenu's that don't send a message to my target object. So how would those get 
validated if they aren't using the target-action mechanism?


_______________________________________________

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]

Reply via email to