On Oct 19, 2013, at 1:32 PM, Martin Hewitson <martin.hewit...@aei.mpg.de> wrote:
> I guess I didn’t understand correctly since my app delegate does not get > asked to validate the Close menu item. So far the only thing that get’s asked > to validate this is the tabbed window object. Even the window’s delegate is > not asked. > > The documentation states: > > For document-based applications, the default responder chain for the main > window consists of the following responders and delegates: > The main window’s first responder and the successive responder objects up the > view hierarchy > The main window itself > The window's NSWindowController object (which inherits from NSResponder) > The main window’s delegate. > The NSDocument object (if different from the main window’s delegate) > The application object, NSApp > The application object's delegate > The application's document controller (an NSDocumentController object, which > does not inherit from NSResponder) > > My NSPersistentDocument subclass is the main window’s delegate. > > Clearly my thinking is flawed, but where? If I want the Close menu item to > vary depending on the window that is key, and I have to do this with > validateMenuItem:, then the responder chain above seems to suggest that I > need to have a validateMenuItem: in each and every window in the app. I hope > that’s not the case…. https://developer.apple.com/library/mac/documentation/cocoa/Conceptual/MenuList/Articles/EnablingMenuItems.html > • If the menu item’s target is set, then NSMenu first checks to see if > that object implements the item’s action method. If it does not, then the > item is disabled. If the target does implement the item’s action method, > NSMenu first checks to see if that object implements validateMenuItem: or > validateUserInterfaceItem: method. If it does not, then the menu item is > enabled. If it does, then the enabled status of the menu item is determined > by the return value of the method. > • If the menu item’s target is not set (that is, if it is nil—typically > if the menu item is connected to First Responder) and the NSMenu object is > not a contextual menu, then NSMenu uses the responder chain (described in > “The Responder Chain” in Cocoa Event Handling Guide) to determine the target. > If there is no object in the responder chain that implements the item’s > action, the item is disabled. > If there is an object in the responder chain that implements the item’s > action, NSMenu then checks to see if that object implements the > validateMenuItem:orvalidateUserInterfaceItem: method. If it does not, then > the menu item is enabled. If it does, then the enabled status of the menu > item is determined by the return value of the method. Key phrase in both cases: "implements the item's action". If your Close menu item has an action method of performClose:, then any object (target or in the responder chain) must implement that action method before it will be asked to validate the menu item. _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com