Connecting the Font Menu in Interface Builder 3

Q: How do I connect items in the Font or Format menu in Interface Builder 3?

A: Interface Builder 3 provides two standard menus, the Font menu and Format menu, which contain the items most users expect for font interactions. These include displaying the Font Panel, making selected text bold, italic, or underlined, showing the Color Panel, modifying text size, text alignment, kerning and ligature options, and more. AppKit includes a shared NSFontManager instance (a singleton) for each application. Cocoa's NSFontManager provides many of the actions in the font menu; the rest are handled by the first responder.

There are three main steps:

Adding the Font Menu

  • Open your application's Main Menu nib in Interface Builder 3.

  • In IB's Library panel, find the Font (or Format) Menu Item.

  • Drag it to your Main Menu.

Back to Top 

Add the NSFontManager shared instance.

This creates a custom object in your NIB file of type NSFontManager. At runtime, AppKit will create a single shared instance of NSFontManager. When the object in your nib is unarchived, the NSFontManager class will swap this instance out for the shared instance.

  • In IB's Library panel, find "Object"

  • Drag it to your nib.

  • Select the new Object.

  • Open IB's "Identity" Inspector (command-6)

  • In the custom class box, enter "NSFontManager"

Back to Top 

Connect the menu items

Some menu items in the Font and Format menus should be connected to the First Responder proxy, others to the Font Manager. The following table contains a reference of all the connections that have to be made for the Format menu to be fully functional. The Font menu is a subset of the Format menu.

Table 1: Format Menu Connections

Menu ItemDestinationSelector
Font Menu  
Show FontsFont ManagerorderFrontFontPanel:
BoldFont ManageraddFontTrait:
ItalicFont ManageraddFontTrait:
UnderlineFirst Responderunderline:
BiggerFont ManagermodifyFont:
SmallerFont ManagermodifyFont:
Kern Menu  
Use DefaultFirst ResponderuseStandardKerning:
Use NoneFirst ResponderturnOffKerning:
TightenFirst RespondertightenKerning:
LoosenFirst ResponderloosenKerning:
Ligature Menu  
Use DefaultFirst ResponderuseStandardLigatures:
Use NoneFirst ResponderturnOffLigatures:
Use AllFirst ResponderuseAllLigatures:
Baseline Menu  
Use DefaultFirst Responderunscript:
SuperscriptFirst Respondersuperscript:
SubscriptFirst Respondersubscript:
RaiseFirst ResponderraiseBaseline:
LowerFirst ResponderlowerBaseline:
Show ColorsFirst ResponderorderFrontColorPanel:
Copy StyleFirst RespondercopyFont:
Paste StyleFirst ResponderpasteFont:
Text Menu  
Align LeftFirst ResponderalignLeft:
CenterFirst ResponderalignCenter:
JustifyFirst ResponderalignJustified:
Align RightFirst ResponderalignRight:
Show RulerFirst RespondertoggleRuler:
Copy RulerFirst RespondercopyRuler:
Paste RulerFirst ResponderpasteRuler:

Back to Top 

Related Documentation

Back to Top 

Document Revision History

DateNotes
2008-01-21First Version

Posted: 2008-01-21


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.