Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable NSToolbar customisation via window's toolbar button?

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.

like image 678
thatinkjar Avatar asked Dec 30 '22 01:12

thatinkjar


1 Answers

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.

like image 165
sbooth Avatar answered Jan 18 '23 16:01

sbooth