advertisement

Article:
  Creating Toolbars for Mac OS X
Subject:   My customized items are disabled...
Date:   2002-12-24 22:36:55
From:   anonymous2
I am trying to make my own app based on this... All that is done so far is this, but now my customized icons are disabled... Here is my code:


- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar
itemForItemIdentifier:(NSString *)itemIdentifier
willBeInsertedIntoToolbar:(BOOL)flag {
NSToolbarItem *item = [[NSToolbarItem alloc] initWithItemIdentifier:itemIdentifier];

if ( [itemIdentifier isEqualToString:@"Finder"] ) {
[item setLabel:@"Finder"];
[item setPaletteLabel:[item label]];
[item setImage:[NSImage imageNamed:@"Finder.icns"]];
[item setTarget:self];
[item setAction:@selector(finderprefs:)];
} else if ( [itemIdentifier isEqualToString:@"Background"] ) {
[item setLabel:@"Background"];
[item setPaletteLabel:[item label]];
[item setImage:[NSImage imageNamed:@"ScreenEffects.tiff"]];
[item setTarget:self];
[item setAction:@selector(screeneffectsprefs:)];
}

return [item autorelease];
}


- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar {
return [NSArray arrayWithObjects:NSToolbarSeparatorItemIdentifier,
NSToolbarSpaceItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
NSToolbarCustomizeToolbarItemIdentifier,
@"Finder", @"Background", nil];
}


- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar {
return [NSArray arrayWithObjects:@"Finder", @"Background",
NSToolbarFlexibleSpaceItemIdentifier,
NSToolbarCustomizeToolbarItemIdentifier, nil];
}


- (void)setupToolbar {
NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier:@"mainToolbar"];
[toolbar autorelease];
[toolbar setDelegate:self];
[toolbar setAllowsUserCustomization:YES];
[toolbar setAutosavesConfiguration:YES];
[mainWindow setToolbar:toolbar];
}


- (void)screeneffectsprefs {
viewSize = [screenEffectsView frame].size;

[mainWindow setContentView:mainView];
[mainWindow setContentSize:viewSize];
[mainWindow setContentView:screenEffectsView];
}


- (void)finderprefs {
viewSize = [finderView frame].size;

[mainWindow setContentView:mainView];
[mainWindow setContentSize:viewSize];
[mainWindow setContentView:finderView];
}