[beginner] Please help! Insoluble (for me at least) toolbar problem
[beginner] Please help! Insoluble (for me at least) toolbar problem
- Subject: [beginner] Please help! Insoluble (for me at least) toolbar problem
- From: Erika <email@hidden>
- Date: Sun, 9 Mar 2003 03:50:49 +1100
Hello all,
I am trying to put a toolbar on my application, and am really stuck. I had been struggling with it all week, and have made a little progress, but have run out of things to try. Please excuse the cross-posting, but I am desperate for a solution.
I have searched the list archives for answers and sample code, looked at sample code from Apple, MacDevCentre and some other site whose name escapes me for the moment, commented out various things, but although I can get my first four custom items to show up in the toolbar, I cannot for the life of me persuade Apple's standard items to show up. The code just seems to grind to a halt as soon as it strikes one of Apple's standard items, and does not even skip them to load my last custom item. I cannot see any difference between my code and the sample code, but maybe some helpful list member can put their finger on it. The NSLog at the end of the - toolbar: itemForItemIdentifier: itemIdentifier willBeInsertedIntoToolbar: method logs my first four custom items and that's all. If I comment out Apple's standard items, all five of my custom items then show up and all five are logged. If I comment out all my custom items, nothing shows up at all - just a blank toolbar.
Sorry to be verbose, but I thought I'd better include all the code just in case. I have put the toolbar code in a separate category of my MyDocument class for the sake of clarity, but it was behaving just the same before I did that, so that is not the reason. I will only post the category and category header here:
/******************************************************************/
// ToolbarDelegateCategory.h
#import <Cocoa/Cocoa.h>
#import "MyDocument.h"
@interface MyDocument (ToolbarDelegateCategory)
- (void)setupToolbar;
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar
itemForItemIdentifier:(NSString *)itemIdentifier
willBeInsertedIntoToolbar:(BOOL)flag;
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar;
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar;
@end
/******************************************************************/
// ToolbarDelegateCategory.m
#import "ToolbarDelegateCategory.h"
@implementation MyDocument (ToolbarDelegateCategory)
- (void)setupToolbar
{
NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier:@"lToolbarIdentifier"];
[toolbar setVisible: YES];
[toolbar setAllowsUserCustomization: NO];
[toolbar setAutosavesConfiguration: NO];
[toolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
[toolbar setDelegate:self];
[[theTextView window] setToolbar:[toolbar autorelease]];
}
// toolbar item setup code here...
/*******************************************************************************/
- (NSToolbarItem *) toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag
{
NSToolbarItem *toolbarItem = [[NSToolbarItem alloc]initWithItemIdentifier:itemIdentifier];
if ([itemIdentifier isEqualToString:@"GoItem"])
{
[toolbarItem setLabel: @"Run"];
[toolbarItem setPaletteLabel:[toolbarItem label]];
[toolbarItem setToolTip: @"Run your programme"];
[toolbarItem setImage: [NSImage imageNamed: @"GO.tiff"]];
[toolbarItem setTarget: self];
[toolbarItem setAction: @selector(runInterpreter:)];
}
else if ([itemIdentifier isEqualToString:@"CheckItem"])
{
[toolbarItem setLabel: @"Check"];
[toolbarItem setPaletteLabel:[toolbarItem label]];
[toolbarItem setToolTip: @"Check your code"];
[toolbarItem setImage: [NSImage imageNamed: @"check.tiff"]];
[toolbarItem setTarget: self];
[toolbarItem setAction: @selector(runScanner:)];
}
else if ([itemIdentifier isEqualToString:@"LeftShiftItem"])
{
[toolbarItem setLabel: @"Left Shift"];
[toolbarItem setPaletteLabel:[toolbarItem label]];
[toolbarItem setToolTip: @"Shift selected code to the left"];
[toolbarItem setImage: [NSImage imageNamed: @"left.tiff"]];
[toolbarItem setTarget: self];
[toolbarItem setAction: @selector(edentCode:)];
}
else if ([itemIdentifier isEqualToString:@"RightShiftItem"])
{
[toolbarItem setLabel: @"Right Shift"];
[toolbarItem setPaletteLabel:[toolbarItem label]];
[toolbarItem setToolTip: @"Shift selected code to the right"];
[toolbarItem setImage: [NSImage imageNamed: @"right.tiff"]];
[toolbarItem setTarget: self];
[toolbarItem setAction: @selector(indentCode:)];
}
else if ([itemIdentifier isEqualToString:@"DrawerItem"])
{
[toolbarItem setLabel: @"Commands"];
[toolbarItem setPaletteLabel:[toolbarItem label]];
[toolbarItem setToolTip: @"Open list of commands and functions"];
[toolbarItem setImage: [NSImage imageNamed: @"drawer.tiff"]];
[toolbarItem setTarget: self];
[toolbarItem setAction: @selector(toggleDrawer:)];
}
else
{
toolbarItem = nil;
}
NSLog(@"returned toolbarItem: %@", toolbarItem); // test to see how many items are being created
return [toolbarItem autorelease];
}
/******************************************************************************/
- (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar // array of allowed items
{
return [NSArray arrayWithObjects: @"GoItem", @"CheckItem", @"LeftShiftItem", @"RightShiftItem", NSToolbarSeparatorItemIdentifier, NSToolbarFlexibleSpaceItemIdentifier, NSToolbarShowColorsItemIdentifier, NSToolbarPrintItemIdentifier, @"DrawerItem", nil];
}
- (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar // array of default items
{
return [NSArray arrayWithObjects: @"GoItem", @"CheckItem", @"LeftShiftItem", @"RightShiftItem", NSToolbarSeparatorItemIdentifier, NSToolbarFlexibleSpaceItemIdentifier, NSToolbarShowColorsItemIdentifier, NSToolbarPrintItemIdentifier, @"DrawerItem", nil];
}
@end
/******************************************************************/
--
_____________________________________________________________________
| Please do not be surprised or annoyed if I fail to answer |
| your post for some time. I am a chronic invalid, and am often |
| unable to use my computer for long periods (days, weeks or months). |
| Be assured that I will, however, reply as soon as I can if I can |
|_____________________________________________________________________|
best,
Erica Mackenzie
Megalong Valley,
N.S.W.
AUSTRALIA
________________________________________________________________
| Windows) 98 (n) - 32-bit extensions and graphical shell |
| for a 16-bit patch to an 8-bit operating system |
| originally coded for a 4-bit microprocessor |
| written by a 2-bit company |
| that can't stand 1 bit of competition. |
|________________________________________________________________|
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.