After some trial and error, I think I was able to figure this out and find a reasonable solution. I will post a quick answer here for future links for others facing the same problem.
This is just another Cocoa design flaw. NSToolbar has hard-coded behavior for setting the target / action for NSToolbarShowFontsItem and NSToolbarShowColorsItem for NSApplication, since documentation hints will never call validateToolbarItem: for these NSToolbarItem elements.
If you need those toolbar elements that have been tested, the trivial task is not to use the default font / color panel elements, but to minimize your own by invoking the same NSApplication actions (see below).
When using the default defaults, you can redirect the target / action to your object, and then call the original actions
- (void) toolbarWillAddItem:(NSNotification *)notification { NSToolbarItem *addedItem = [[notification userInfo] objectForKey: @"item"]; if([[addedItem itemIdentifier] isEqual: NSToolbarShowFontsItemIdentifier]) { [addedItem setTarget:self]; [addedItem setAction:@selector(toolbarOpenFontPanel:)]; } else if ([[addedItem itemIdentifier] isEqual: NSToolbarShowColorsItemIdentifier]) { [addedItem setTarget:self]; [addedItem setAction:@selector(toolbarOpenColorPanel:)]; } }
Now validateToolbarItem: will be called::
- (BOOL)validateToolbarItem:(NSToolbarItem *)theItem {
And here are the actions that will be called:
-(IBAction)toolbarOpenFontPanel:(id)sender { [NSApp orderFrontFontPanel:sender]; } -(IBAction)toolbarOpenColorPanel:(id)sender { [NSApp orderFrontColorPanel:sender]; }
I think that the engineers who designed it never thought that it would be necessary to check the elements of the font / color panel. Hover over your mouse.
source share