GenericToolbar Palette for IB2
Tired of having to write your own toolbar delegate every time? Moaning about Interface Builder's lack of toolbar support? Finally, a toolbar that can be used in Interface Builder! GenericToolbar is easy to use, convenient, and totally free, which is a great combination for any developer. Coolest of all, GenericToolbar supports Interface Builder's "Test Interface" mode! To use GenericToolbar:
- Copy GenericToolbar.palette onto your hard drive, then double-click its icon to load the palette into Interface Builder. This loads both a template palette and the classes GenericToolbar and GenericToolbarItem. To ensure a unique class name, both classes are actually prefixed with
ComBelkadanGenerictoolbar_. This will show up in Interface Builder, but thanks to
#define, it won't in your code (if you
#import the header files).
- Drag the icon for a GenericToolbar instance into your nib document's object window (NOT the window you want to attach the toolbar to).
- Connect your instance of NSWindow to the instance of GenericToolbar ("toolbar" outlet).
- Set up your toolbar. You can drag new items into the toolbar from the GenericToolbar palette. (The item with dashed lines represents a customizable items, though you can change all of them if you want) Toolbar item actions are set using the usual method of connections: Control-click and drag.
- To use one of Apple's default toolbar items, just enter the identifier, leaving all other fields blank. This identifier can be any of the following:
- To make a custom view item, connect the item to the view of your choice. Set the size of the item as well to avoid a size of 0 by 0 pixels. There is an option that allows you to automatically resize to match the view: -1 by -1 pixels.
- To set the default or selectable items in the toolbar, just drag the item from the "All Items" box down to the bottom box. To disable an item, remember to turn off autovalidation too (this is part of Apple's behavior). To delete an item, drag it out of the box. To move an item, drag it to its new position. Make sure the mouse is not outside the box when you let go, or the item will be deleted. However, GenericToolbar has (almost) full undo support, so just press Command-Z to bring your item back.
- You have three options for adding GenericToolbar to your project. This IS necessary, even if you are not going to use the classes outside of the nib.
- Add the eight source code files to your project (in the Source Code folder)
- Add the GenericToolbar framework to your project. This must be recognized as a framework, but also copied into your final product. To do this, add a Copy Files build phase to your target, with the destination set to Frameworks. Then drag the framework into the Copy Files build phase. Make sure it still shows up in the Link phase. There is one advantage of this: localized error messages for toolbar decoding. At least, there would be if I knew any other languages to write error messages in.
- Add the GenericToolbar static library to your project (libGenericToolbar.a).
- For the GenericToolbar API, look in the docs folder. Most users won't need to touch this.
- Build and run!
To get rid of the GenericToolbar palette, go to Interface Builder's Preferences window and open the Palettes tab. Then select GenericToolbar (under Cocoa Framework) and click the Remove button. WARNING: Without GenericToolbar installed, you will not be able to open nib files that use GenericToolbar!
- Copy/Paste for toolbar items. Don't even bother trying this. It shouldn't matter, because duplicate items should only show up in one of the subsets anyway, and you can just drag another instance to the bottom.
- Duplicate toolbar items with custom views. This doesn't seem to be my fault, as its not my code that's causing this, but it would be nice to have it work. Right now it appears that Apple is at fault here: only normal items (with an image, not a view) can be used as duplicates.
- Fix the behavior of the toolbar editing window. For some reason, the window does not behave like Interface Builder's other editing windows (Command-W will not close it). I'm sorry for any inconvenience, but it shouldn't affect your overall outcome.
- Dave Dribin for discovering several flaws in toolbar autosaving and item bindings.
- Sailesh Agrawal for the DragMatrix class used extensively in the palette.