diff --git a/ChangeLog b/ChangeLog index 70836600c..9a3c54440 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2004-02-29 Gregory John Casamento + + * Source/NSToolbar.m: Added code in + -[NSToolbar insertItemWithIdentifier:atIndex:] to properly + handle when a system defined identifier is passed to the toolbar. + 2004-03-01 Fred Kiefer * Header/AppKit/NSTableView.h: diff --git a/Source/NSToolbar.m b/Source/NSToolbar.m index 042a0b9a1..5544e9a39 100644 --- a/Source/NSToolbar.m +++ b/Source/NSToolbar.m @@ -410,6 +410,22 @@ static NSMutableArray *toolbars; } } +- (id) _toolbarItemForIdentifier: (NSString *)itemIdent +{ + id item = nil; + if([itemIdent isEqual: NSToolbarSeparatorItemIdentifier] || + [itemIdent isEqual: NSToolbarSpaceItemIdentifier] || + [itemIdent isEqual: NSToolbarFlexibleSpaceItemIdentifier] || + [itemIdent isEqual: NSToolbarShowColorsItemIdentifier] || + [itemIdent isEqual: NSToolbarShowFontsItemIdentifier] || + [itemIdent isEqual: NSToolbarCustomizeToolbarItemIdentifier] || + [itemIdent isEqual: NSToolbarPrintItemIdentifier]) + { + item = [[NSToolbarItem alloc] initWithItemIdentifier: itemIdent]; + } + return item; +} + /* * * The methods below handles the toolbar edition and broacasts each associated event @@ -434,25 +450,31 @@ static NSMutableArray *toolbars; if([allowedItems containsObject: itemIdentifier]) { - item = [_delegate toolbar: self - itemForItemIdentifier: itemIdentifier - willBeInsertedIntoToolbar: YES]; - + item = [self _toolbarItemForIdentifier: itemIdentifier]; + if(item == nil) + { + item = [_delegate toolbar: self + itemForItemIdentifier: itemIdentifier + willBeInsertedIntoToolbar: YES]; + } + if (item != nil) - { - [nc postNotificationName: NSToolbarWillAddItemNotification object: self]; - [item _setToolbar: self]; - [_items insertObject: item atIndex: index]; - if (!_build) // we reload the toolbarView each time a new item is added except when we build/create the toolbar - [_toolbarView _reload]; - - if (broadcast) - { - TRANSMIT(_insertItemWithItemIdentifier: itemIdentifier atIndex: index broadcast: NO); - } - } - } - + { + [nc postNotificationName: NSToolbarWillAddItemNotification object: self]; + [item _setToolbar: self]; + [_items insertObject: item atIndex: index]; + // We reload the toolbarView each time a new item is + // added except when we build/create the toolbar + if (!_build) + [_toolbarView _reload]; + + if (broadcast) + { + TRANSMIT(_insertItemWithItemIdentifier: itemIdentifier + atIndex: index broadcast: NO); + } + } + } } - (void) _removeItemAtIndex: (int)index broadcast: (BOOL)broadcast