• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSToolbar not enabled
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSToolbar not enabled


  • Subject: NSToolbar not enabled
  • From: Lincoln Green <email@hidden>
  • Date: Wed, 19 Mar 2008 15:09:51 -0500

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?
_______________________________________________


Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSToolbar not enabled
      • From: "Rob Napier" <email@hidden>
  • Prev by Date: Menu Item is not disabling
  • Next by Date: Re: Menu Item is not disabling
  • Previous by thread: Re: Menu Item is not disabling
  • Next by thread: Re: NSToolbar not enabled
  • Index(es):
    • Date
    • Thread