FROM : Lincoln Green
DATE : Wed Mar 19 21:09:51 2008
I have the following code in an NSObject subclass, called LGObject.
static NSString *NewToolbarItemIdentifier = @"New";
static NSString *OpenToolbarItemIdentifier = @"Open";
static NSString *SaveToolbarItemIdentifier = @"Save";;
static NSString *PrintToolbarItemIdentifier = @"Print";
static NSString *FormatToolbarItemIdentifier = @"Format";
static NSString *InfoToolbarItemIdentifier = @"Info";
- (void)awakeFromNib
{
NSToolbar *toolbar = [[NSToolbar alloc]
initWithIdentifier:@"LGToolbar";];
// set initial toolbar properties
[toolbar setAllowsUserCustomization:YES];
[toolbar setAutosavesConfiguration:YES];
[toolbar setDisplayMode:NSToolbarDisplayModeIconAndLabel];
// set our controller as the toolbar delegate
[toolbar setDelegate:self];
// attach the toolbar to our window
[windowOut setToolbar:toolbar];
// clean up
[toolbar release];
}
- (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar {
return [NSArray arrayWithObjects:
NewToolbarItemIdentifier,
OpenToolbarItemIdentifier,
SaveToolbarItemIdentifier,
PrintToolbarItemIdentifier,
FormatToolbarItemIdentifier,
InfoToolbarItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
NSToolbarSpaceItemIdentifier,
NSToolbarSeparatorItemIdentifier, nil];
}
- (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *)toolbar
{
return [NSArray arrayWithObjects:NewToolbarItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
OpenToolbarItemIdentifier, nil];
}
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:
(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag
{
NSToolbarItem *toolbarItem = nil;
if ([itemIdentifier isEqualTo:NewToolbarItemIdentifier]) {
toolbarItem = [[NSToolbarItem alloc]
initWithItemIdentifier:itemIdentifier];
[toolbarItem setLabel:@"New"];
[toolbarItem setPaletteLabel:@"New"];
[toolbarItem setToolTip:@"New Document"];
[toolbarItem setImage:[NSImage imageNamed:@"Add.tiff"]];
[toolbarItem setTarget:fileOwnerOut];
[toolbarItem setAction:@selector(newDocument:)];
}
else if ([itemIdentifier isEqualTo:OpenToolbarItemIdentifier]) {
toolbarItem = [[NSToolbarItem alloc]
initWithItemIdentifier:itemIdentifier];
[toolbarItem setLabel:@"Open"];
[toolbarItem setPaletteLabel:@"Open"];
[toolbarItem setToolTip:@"Open Document"];
[toolbarItem setImage:[NSImage imageNamed:@"Folder.tiff"]];
[toolbarItem setTarget:fileOwnerOut];
[toolbarItem setAction:@selector(openDocument:)];
}
else if ([itemIdentifier isEqualTo:SaveToolbarItemIdentifier]) {
toolbarItem = [[NSToolbarItem alloc]
initWithItemIdentifier:itemIdentifier];
[toolbarItem setLabel:@"Save"];
[toolbarItem setPaletteLabel:@"Save"];
[toolbarItem setToolTip:@"Save Document"];
[toolbarItem setImage:[NSImage imageNamed:@"flag.tiff"]];
[toolbarItem setTarget:fileOwnerOut];
[toolbarItem setAction:@selector(saveDocument:)];
}
else if ([itemIdentifier isEqualTo:PrintToolbarItemIdentifier]) {
toolbarItem = [[NSToolbarItem alloc]
initWithItemIdentifier:itemIdentifier];
[toolbarItem setLabel:@"Print"];
[toolbarItem setPaletteLabel:@"Print"];
[toolbarItem setToolTip:@"Print Document"];
[toolbarItem setImage:[NSImage imageNamed:@"Print.png"]];
[toolbarItem setTarget:fileOwnerOut];
[toolbarItem setAction:@selector(printDocument:)];
}
else if ([itemIdentifier isEqualTo:InfoToolbarItemIdentifier]) {
toolbarItem = [[NSToolbarItem alloc]
initWithItemIdentifier:itemIdentifier];
[toolbarItem setLabel:@"New"];
[toolbarItem setPaletteLabel:@"New"];
[toolbarItem setToolTip:@"New Document"];
[toolbarItem setImage:[NSImage imageNamed:@"Add.tiff"]];
[toolbarItem setTarget:[infoWindowOut windowController]];
[toolbarItem setAction:@selector(showWindow:)];
}
else if ([itemIdentifier isEqualTo:FormatToolbarItemIdentifier]) {
toolbarItem = [[NSToolbarItem alloc]
initWithItemIdentifier:itemIdentifier];
[toolbarItem setLabel:@"Format"];
[toolbarItem setPaletteLabel:@"Format"];
[toolbarItem setToolTip:@"Format Drawer"];
[toolbarItem setImage:[NSImage imageNamed:@"Drawer.tiff"]];
[toolbarItem setTarget:formatDrawerOut];
[toolbarItem setAction:@selector(toggle:)];
}
return [toolbarItem autorelease];
}
However, the only toolbar items that work are the "Format", and
"Print". The "Info" item does not show up at all, and all the others
are disabled. fileOwnerOut is an outlet hooked up to my File's Owner
instance in IB. Any suggestions?
DATE : Wed Mar 19 21:09:51 2008
I have the following code in an NSObject subclass, called LGObject.
static NSString *NewToolbarItemIdentifier = @"New";
static NSString *OpenToolbarItemIdentifier = @"Open";
static NSString *SaveToolbarItemIdentifier = @"Save";;
static NSString *PrintToolbarItemIdentifier = @"Print";
static NSString *FormatToolbarItemIdentifier = @"Format";
static NSString *InfoToolbarItemIdentifier = @"Info";
- (void)awakeFromNib
{
NSToolbar *toolbar = [[NSToolbar alloc]
initWithIdentifier:@"LGToolbar";];
// set initial toolbar properties
[toolbar setAllowsUserCustomization:YES];
[toolbar setAutosavesConfiguration:YES];
[toolbar setDisplayMode:NSToolbarDisplayModeIconAndLabel];
// set our controller as the toolbar delegate
[toolbar setDelegate:self];
// attach the toolbar to our window
[windowOut setToolbar:toolbar];
// clean up
[toolbar release];
}
- (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar {
return [NSArray arrayWithObjects:
NewToolbarItemIdentifier,
OpenToolbarItemIdentifier,
SaveToolbarItemIdentifier,
PrintToolbarItemIdentifier,
FormatToolbarItemIdentifier,
InfoToolbarItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
NSToolbarSpaceItemIdentifier,
NSToolbarSeparatorItemIdentifier, nil];
}
- (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *)toolbar
{
return [NSArray arrayWithObjects:NewToolbarItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
OpenToolbarItemIdentifier, nil];
}
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:
(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag
{
NSToolbarItem *toolbarItem = nil;
if ([itemIdentifier isEqualTo:NewToolbarItemIdentifier]) {
toolbarItem = [[NSToolbarItem alloc]
initWithItemIdentifier:itemIdentifier];
[toolbarItem setLabel:@"New"];
[toolbarItem setPaletteLabel:@"New"];
[toolbarItem setToolTip:@"New Document"];
[toolbarItem setImage:[NSImage imageNamed:@"Add.tiff"]];
[toolbarItem setTarget:fileOwnerOut];
[toolbarItem setAction:@selector(newDocument:)];
}
else if ([itemIdentifier isEqualTo:OpenToolbarItemIdentifier]) {
toolbarItem = [[NSToolbarItem alloc]
initWithItemIdentifier:itemIdentifier];
[toolbarItem setLabel:@"Open"];
[toolbarItem setPaletteLabel:@"Open"];
[toolbarItem setToolTip:@"Open Document"];
[toolbarItem setImage:[NSImage imageNamed:@"Folder.tiff"]];
[toolbarItem setTarget:fileOwnerOut];
[toolbarItem setAction:@selector(openDocument:)];
}
else if ([itemIdentifier isEqualTo:SaveToolbarItemIdentifier]) {
toolbarItem = [[NSToolbarItem alloc]
initWithItemIdentifier:itemIdentifier];
[toolbarItem setLabel:@"Save"];
[toolbarItem setPaletteLabel:@"Save"];
[toolbarItem setToolTip:@"Save Document"];
[toolbarItem setImage:[NSImage imageNamed:@"flag.tiff"]];
[toolbarItem setTarget:fileOwnerOut];
[toolbarItem setAction:@selector(saveDocument:)];
}
else if ([itemIdentifier isEqualTo:PrintToolbarItemIdentifier]) {
toolbarItem = [[NSToolbarItem alloc]
initWithItemIdentifier:itemIdentifier];
[toolbarItem setLabel:@"Print"];
[toolbarItem setPaletteLabel:@"Print"];
[toolbarItem setToolTip:@"Print Document"];
[toolbarItem setImage:[NSImage imageNamed:@"Print.png"]];
[toolbarItem setTarget:fileOwnerOut];
[toolbarItem setAction:@selector(printDocument:)];
}
else if ([itemIdentifier isEqualTo:InfoToolbarItemIdentifier]) {
toolbarItem = [[NSToolbarItem alloc]
initWithItemIdentifier:itemIdentifier];
[toolbarItem setLabel:@"New"];
[toolbarItem setPaletteLabel:@"New"];
[toolbarItem setToolTip:@"New Document"];
[toolbarItem setImage:[NSImage imageNamed:@"Add.tiff"]];
[toolbarItem setTarget:[infoWindowOut windowController]];
[toolbarItem setAction:@selector(showWindow:)];
}
else if ([itemIdentifier isEqualTo:FormatToolbarItemIdentifier]) {
toolbarItem = [[NSToolbarItem alloc]
initWithItemIdentifier:itemIdentifier];
[toolbarItem setLabel:@"Format"];
[toolbarItem setPaletteLabel:@"Format"];
[toolbarItem setToolTip:@"Format Drawer"];
[toolbarItem setImage:[NSImage imageNamed:@"Drawer.tiff"]];
[toolbarItem setTarget:formatDrawerOut];
[toolbarItem setAction:@selector(toggle:)];
}
return [toolbarItem autorelease];
}
However, the only toolbar items that work are the "Format", and
"Print". The "Info" item does not show up at all, and all the others
are disabled. fileOwnerOut is an outlet hooked up to my File's Owner
instance in IB. Any suggestions?
| Related mails | Author | Date |
|---|---|---|
| Lincoln Green | Mar 19, 21:09 | |
| Rob Napier | Mar 20, 16:17 |






Cocoa mail archive

