views:

123

answers:

1

I have an application with many NSToolbarItems. Only 5 or so are needed at any one time so it seems like the best way to fit them on the screen and make them easy to get to is to hide/display only the NSToolbarItems depending on the context.

I can't find either through google or in the Apple doc's how to do this. Is there a way? (Short of actually writing a custom nstoolbar!)

NB: I am worried this is a little bit "anti" the user interface standards, but I cannot think of a better way to handle large number of buttons that are all needed by the user, except maybe a tool window thingy.

+2  A: 

You can go through all the items with -[NSToolbar items], and remove unwanted ones with -[NSToolbar removeItemAtIndex:], Although apple does say this:

Typically, you should not call this method (-[NSToolbar removeItemAtIndex:]); you should let the user reconfigure the toolbar.

Usually you just disable the toolbar items that can't be used in the current context.

Tom Dalling
Thanks for the pointer. I knew I was going to get at least some comments back on the "Usability" of this. The problem is in any given context there are five usable/sensible buttons and more than sixty unusable/nonsensical buttons. (ie imagine one screen you are drawing a car with car components, and another screen you are painting colors on a map, and another screen you are measuring the distances between points on a map. You need all of the buttons but not all at the same time.
Jacob
Maybe you'd be better off using an NSPanel/NSWindow that changes depending on the context instead of a toolbar. You'd probably want one NSViewController per context, and just switch the window's contentView when the context changes.
Tom Dalling
That has given me another idea! There could be a "sub" toolbar that sits inside the top of the drawing area that shows the relevant buttons. (With styling just like the Finder does when your browsing a server, ie the "Connecting... (connect as)" bar)
Jacob