views:

327

answers:

2

I am looking to disable the Command + Click combination on a toolbar button (located top-right) in a Cocoa window. I would still like to let the user show and hide the toolbar, but I do not want them to be able to select a different display mode (e.g. small icons, no icons, etc).

Has anyone found a way to do this? Thanks in advance.

+1  A: 

Have you tried using a custom NSToolbar subclass that overrides setDisplayMode: and setSizeMode: to do nothing? That won't remove the menu items of course, or the UI in the customization sheet (assuming you aren't disabling that as well with setAllowsUserCustomization:), but it might prevent them from doing anything.

smorgan
Thanks. I subclassed NSToolbar and used -(BOOL)_allowsSizeMode and -(void)setDisplayMode.
thatinkjar
+2  A: 

You don't need to subclass NSToolbar to do this. In your NSWindowController subclass, put the following in your awakeFromNib:

- (void) awakeFromNib
{
  NSToolbar *tb = [[self window] toolbar];
  [tb setAllowsUserCustomization:NO];
}

You also have the added benefit of avoiding private API use.

sbooth
Unfortunately, this isn't enough. I want to allow the user to customise the items on the toolbar, but I want to disable small size icons, and the ability to have text labels, etc. I wanted to disable these options through the standard right-click menu, as well as the Command + Click action on the toolbar button (top-right of the window). To do this, I needed to subclass as indicated above. Thanks for taking the time to answer, though :)
thatinkjar