I've got a toolbar item that contains a view (an NSButton
) and the view's target is set to nil
, so it'll look up the responder chain when triggering the action. I'm having trouble trying how to validate against the first responder, though.
I've subclassed NSToolbarItem and implemented -(void)validate
. The references that I've found say that you should be able to get the first responder by calling [[[self view] window] firstResponder]
, then seeing if the responder chain implements either NSToolbarItemValidation
or NSUserInterfaceValidations
and calling the appropriate validation method.
However, when I call [[self view] window]
, I'm getting back nil
as the window, so I'm not able to retrieve the first responder.
I'm not sure if it makes a difference, but I'm creating the toolbar in the XIB instead of writing it in code.
Looking in NSToolbar.h, there's a ivar that references the containing window, so I could find the first responder by calling [[[self toolbar] valueForKey:@"window"] firstResponder]
, but that's a bit of a hack and I'd prefer to use something documented/stabler.