Belkadan Software

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:

  1. 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).
  2. Drag the icon for a GenericToolbar instance into your nib document's object window (NOT the window you want to attach the toolbar to).
  3. Connect your instance of NSWindow to the instance of GenericToolbar ("toolbar" outlet).
  4. 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.
  5. 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:
    • NSToolbarSeparatorItemIdentifier
    • NSToolbarSpaceItemIdentifier
    • NSToolbarFlexibleSpaceItemIdentifier
    • NSToolbarShowColorsItemIdentifier
    • NSToolbarShowFontsItemIdentifier
    • NSToolbarCustomizeToolbarItemIdentifier
    • NSToolbarPrintItemIdentifier
  6. 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.
  7. 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.
  8. 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.
    1. Add the eight source code files to your project (in the Source Code folder)
      • GenericToolbar.h/.m
      • GenericToolbarItem.h/.m
      • GenericToolbarDataSource.h/.m
      • GenericToolbarNibConnector.h/.m
    2. 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.
    3. Add the GenericToolbar static library to your project (libGenericToolbar.a).
  9. For the GenericToolbar API, look in the docs folder. Most users won't need to touch this.
  10. Build and run!

Uninstallation

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!

Missing Features

Credits