* Source/GSNibLoading.m:

* Source/NSToolbar.m:
* Source/GSToolbarCustomizationPalette.m:
* Source/GSToolbarView.m:
* Source/NSToolbarItem.m:
* Source/NSToolbarFrameworkPrivate.h:
* Headers/AppKit/NSToolbar.h: Implement -initWithCoder: for
NSToolbar. This required a bit more work that usual because
toolbars created with -initWithCoder can operate without a delegate.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@34189 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Eric Wasylishen 2011-11-18 20:15:53 +00:00
parent 115a372c27
commit 2992f4fa1d
7 changed files with 239 additions and 106 deletions

View file

@ -92,6 +92,10 @@ APPKIT_EXPORT NSString *NSToolbarWillAddItemNotification;
BOOL _customizationPaletteIsRunning;
BOOL _showsBaselineSeparator;
BOOL _build;
NSDictionary *_interfaceBuilderItemsByIdentifier;
NSArray *_interfaceBuilderAllowedItemIdentifiers;
NSArray *_interfaceBuilderDefaultItemIdentifiers;
NSArray *_interfaceBuilderSelectableItemIdentifiers;
}
// Instance methods

View file

@ -479,6 +479,11 @@ static BOOL _isInInterfaceBuilder = NO;
[_realObject setMaxSize: _maxSize];
[_realObject setTitle: _title];
if ([_viewClass isKindOfClass: [NSToolbar class]])
{
[_realObject setToolbar: _viewClass];
}
[_view _fixSubviews];
// FIXME What is the point of calling -setFrame:display: here? It looks

View file

@ -278,7 +278,6 @@
NSString *identifier = nil;
NSToolbarDisplayMode tag = [toolbar displayMode];
NSToolbarSizeMode size = [toolbar sizeMode];
id delegate = [toolbar delegate];
NSView *toolbarView;
NSRect toolbarFrame;
NSPoint bottomCenter;
@ -299,38 +298,22 @@
[_sizeCheckBox setState: NSOffState];
}
if (delegate == nil)
{
NSLog(@"The toolbar %@ needs a delegate to allow customization",
toolbar);
return;
}
itemIdentifiers = [delegate toolbarAllowedItemIdentifiers: toolbar];
itemIdentifiers = [toolbar _allowedItemIdentifiers];
e = [itemIdentifiers objectEnumerator];
while ((identifier = [e nextObject]) != nil)
{
NSToolbarItem *item = [toolbar _toolbarItemForIdentifier: identifier];
if(item == nil)
{
item = [delegate toolbar: toolbar
itemForItemIdentifier: identifier
willBeInsertedIntoToolbar: NO];
}
NSToolbarItem *item = [toolbar _toolbarItemForIdentifier: identifier
willBeInsertedIntoToolbar: NO];
NSLog(@"item %@ for ident %@", item, identifier);
[_allowedItems addObject: item];
}
itemIdentifiers = [delegate toolbarDefaultItemIdentifiers: toolbar];
itemIdentifiers = [toolbar _defaultItemIdentifiers];
e = [itemIdentifiers objectEnumerator];
while ((identifier = [e nextObject]) != nil)
{
NSToolbarItem *item = [toolbar _toolbarItemForIdentifier: identifier];
if(item == nil)
{
item = [delegate toolbar: toolbar
itemForItemIdentifier: identifier
willBeInsertedIntoToolbar: NO];
}
NSToolbarItem *item = [toolbar _toolbarItemForIdentifier: identifier
willBeInsertedIntoToolbar: NO];
[_defaultItems addObject: item];
}

View file

@ -151,7 +151,6 @@ static int draggedItemIndex = NSNotFound;
{
return [self overflowMenu];
}
return nil;
}
@ -327,7 +326,7 @@ static int draggedItemIndex = NSNotFound;
NSToolbarItem *item = [[info draggingSource] toolbarItem];
NSString *identifier = [item itemIdentifier];
NSToolbar *toolbar = [self toolbar];
NSArray *allowedItemIdentifiers = [[toolbar delegate] toolbarAllowedItemIdentifiers: toolbar];
NSArray *allowedItemIdentifiers = [toolbar _allowedItemIdentifiers];
int newIndex;
// don't accept any dragging if the customization palette isn't running for this toolbar
@ -889,4 +888,14 @@ static int draggedItemIndex = NSNotFound;
NSLog(@"Use of deprecated method %@", NSStringFromSelector(_cmd));
}
- (NSMenu *) menuForEvent: (NSEvent *)event
{
NSMenu *menu = [[[NSMenu alloc] initWithTitle: @""] autorelease];
NSMenuItem *customize = [menu insertItemWithTitle: _(@"Customize Toolbar") action:@selector(runCustomizationPalette:) keyEquivalent:@"" atIndex:0];
[customize setTarget: _toolbar];
return menu;
}
@end

View file

@ -510,7 +510,13 @@ static GSValidationCenter *vc = nil;
ASSIGN(_identifier, identifier);
_items = [[NSMutableArray alloc] init];
// Only set when loaded from a nib
_interfaceBuilderItemsByIdentifier = nil;
_interfaceBuilderAllowedItemIdentifiers = nil;
_interfaceBuilderDefaultItemIdentifiers = nil;
_interfaceBuilderSelectableItemIdentifiers = nil;
toolbarModel = [self _toolbarModel];
if (toolbarModel != nil)
@ -542,6 +548,53 @@ static GSValidationCenter *vc = nil;
return self;
}
- (NSArray *) _identifiersForItems: (NSArray*)items
{
NSMutableArray *result = [NSMutableArray arrayWithCapacity: [items count]];
NSEnumerator *e = [items objectEnumerator];
NSToolbarItem *item;
if (items == nil)
return nil;
while ((item = [e nextObject]) != nil)
{
[result addObject: [item itemIdentifier]];
}
return result;
}
- (id) initWithCoder: (NSCoder *)aCoder
{
self = [super initWithCoder: aCoder];
_identifier = [[aCoder decodeObjectForKey:@"NSToolbarIdentifier"] retain];
_items = [[NSMutableArray alloc] init];
_configurationDictionary = nil;
_customizationPaletteIsRunning = NO;
ASSIGN(_interfaceBuilderItemsByIdentifier, [aCoder decodeObjectForKey: @"NSToolbarIBIdentifiedItems"]);
ASSIGN(_interfaceBuilderAllowedItemIdentifiers, [self _identifiersForItems: [aCoder decodeObjectForKey: @"NSToolbarIBAllowedItems"]]);
ASSIGN(_interfaceBuilderDefaultItemIdentifiers, [self _identifiersForItems: [aCoder decodeObjectForKey: @"NSToolbarIBDefaultItems"]]);
ASSIGN(_interfaceBuilderSelectableItemIdentifiers, [self _identifiersForItems: [aCoder decodeObjectForKey: @"NSToolbarIBSelectableItems"]]);
// Store in list of toolbars
[toolbars addObject: self];
[self setAllowsUserCustomization: [aCoder decodeBoolForKey: @"NSToolbarAllowsUserCustomization"]];
[self setAutosavesConfiguration: [aCoder decodeBoolForKey: @"NSToolbarAutosavesConfiguration"]];
[self setDisplayMode: [aCoder decodeIntForKey: @"NSToolbarDisplayMode"]];
[self setShowsBaselineSeparator: [aCoder decodeBoolForKey: @"NSToolbarShowsBaselineSeparator"]];
[self setSizeMode: [aCoder decodeIntForKey: @"NSToolbarSizeMode"]];
[self setVisible: [aCoder decodeBoolForKey: @"NSToolbarPrefersToBeShown"]];
[self setDelegate: [aCoder decodeObjectForKey: @"NSToolbarDelegate"]];
return self;
}
//FIXME: encodeWithCoder
- (void) dealloc
{
//NSLog(@"Toolbar dealloc %@", self);
@ -553,6 +606,11 @@ static GSValidationCenter *vc = nil;
RELEASE(_configurationDictionary);
RELEASE(_items);
DESTROY(_interfaceBuilderItemsByIdentifier);
DESTROY(_interfaceBuilderAllowedItemIdentifiers);
DESTROY(_interfaceBuilderDefaultItemIdentifiers);
DESTROY(_interfaceBuilderSelectableItemIdentifiers);
if (_delegate != nil)
{
[nc removeObserver: _delegate name: nil object: self];
@ -563,7 +621,7 @@ static GSValidationCenter *vc = nil;
}
// FIXME: Hack
- (void) release
- (oneway void) release
{
// When a toolbar has no external references any more, it's necessary
// to remove the toolbar from the master list, so that it
@ -759,13 +817,22 @@ static GSValidationCenter *vc = nil;
{
#define CHECK_REQUIRED_METHOD(selector_name) \
if (![_delegate respondsToSelector: @selector(selector_name)]) \
[NSException raise: NSInternalInconsistencyException \
format: @"delegate does not respond to %@",@#selector_name]
[NSException raise: NSInternalInconsistencyException \
format: @"delegate does not respond to %@",@#selector_name]
CHECK_REQUIRED_METHOD(toolbar:itemForItemIdentifier:
willBeInsertedIntoToolbar:);
CHECK_REQUIRED_METHOD(toolbarAllowedItemIdentifiers:);
CHECK_REQUIRED_METHOD(toolbarDefaultItemIdentifiers:);
if (_interfaceBuilderItemsByIdentifier == nil)
{
CHECK_REQUIRED_METHOD(toolbar:itemForItemIdentifier:
willBeInsertedIntoToolbar:);
}
if (_interfaceBuilderAllowedItemIdentifiers == nil)
{
CHECK_REQUIRED_METHOD(toolbarAllowedItemIdentifiers:);
}
if (_interfaceBuilderDefaultItemIdentifiers == nil)
{
CHECK_REQUIRED_METHOD(toolbarDefaultItemIdentifiers:);
}
#define SET_DELEGATE_NOTIFICATION(notif_name) \
if ([_delegate respondsToSelector: @selector(toolbar##notif_name:)]) \
@ -780,18 +847,37 @@ static GSValidationCenter *vc = nil;
[self _build];
}
- (NSArray *) _selectableItemIdentifiers
{
NSArray *selectableIdentifiers = nil;
if (_delegate != nil &&
[_delegate respondsToSelector: @selector(toolbarSelectableItemIdentifiers:)])
{
selectableIdentifiers = [_delegate toolbarSelectableItemIdentifiers: self];
if (selectableIdentifiers == nil)
{
NSLog(@"Toolbar delegate returns no such selectable item identifiers");
}
}
if (selectableIdentifiers == nil)
{
selectableIdentifiers = _interfaceBuilderSelectableItemIdentifiers;
}
return selectableIdentifiers;
}
- (void) setSelectedItemIdentifier: (NSString *)identifier
{
NSArray *selectedItems;
NSArray *itemsToSelect;
NSEnumerator *e;
NSToolbarItem *item;
NSArray *selectableIdentifiers = nil;
NSArray *selectableIdentifiers;
BOOL updated = NO;
if (_delegate == nil)
return;
// First, we have to deselect the previous selected toolbar items
selectedItems = [[self items] objectsWithValue: [self selectedItemIdentifier]
forKey: @"_itemIdentifier"];
@ -801,25 +887,11 @@ static GSValidationCenter *vc = nil;
[item _setSelected: NO];
}
if ([_delegate respondsToSelector:
@selector(toolbarSelectableItemIdentifiers:)])
{
selectableIdentifiers =
[_delegate toolbarSelectableItemIdentifiers: self];
}
else
{
NSLog(@"Toolbar delegate does not respond to %@",
@selector(toolbarSelectableItemIdentifiers:));
return;
}
if (selectableIdentifiers == nil)
{
NSLog(@"Toolbar delegate returns no such selectable item identifiers");
return;
}
selectableIdentifiers = [self _selectableItemIdentifiers];
if (selectableIdentifiers == nil)
return;
itemsToSelect = [_items objectsWithValue: identifier
forKey: @"_itemIdentifier"];
e = [itemsToSelect objectEnumerator];
@ -888,6 +960,18 @@ static GSValidationCenter *vc = nil;
// Private methods
- (NSArray *) _defaultItemIdentifiers
{
if (_delegate != nil)
{
return [_delegate toolbarDefaultItemIdentifiers:self];
}
else
{
return _interfaceBuilderDefaultItemIdentifiers;
}
}
/*
* Toolbar build :
* will use the delegate when there is no toolbar model
@ -920,13 +1004,7 @@ static GSValidationCenter *vc = nil;
RELEASE(_items);
_items = [[NSMutableArray alloc] init];
if (_delegate == nil)
{
_build = NO;
return;
}
toolbarModel = [self _toolbarModel];
wantedItemIdentifiers = [self _itemsFromConfig];
@ -938,10 +1016,15 @@ static GSValidationCenter *vc = nil;
[[toolbarModel items] valueForKey: @"_itemIdentifier"];
}
else
{
wantedItemIdentifiers = [_delegate toolbarDefaultItemIdentifiers:self];
{
wantedItemIdentifiers = [self _defaultItemIdentifiers];
}
}
if (wantedItemIdentifiers == nil)
{
_build = NO;
return;
}
e = [wantedItemIdentifiers objectEnumerator];
while ((itemIdentifier = [e nextObject]) != nil)
@ -1104,7 +1187,7 @@ static GSValidationCenter *vc = nil;
return nil;
}
- (NSToolbarItem *) _toolbarItemForIdentifier: (NSString *)itemIdent
- (NSToolbarItem *) _toolbarItemForIdentifier: (NSString *)itemIdent willBeInsertedIntoToolbar: (BOOL)insert
{
NSToolbarItem *item = nil;
@ -1116,10 +1199,21 @@ static GSValidationCenter *vc = nil;
[itemIdent isEqual: NSToolbarCustomizeToolbarItemIdentifier] ||
[itemIdent isEqual: NSToolbarPrintItemIdentifier])
{
item = [[NSToolbarItem alloc] initWithItemIdentifier: itemIdent];
item = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdent] autorelease];
}
return AUTORELEASE(item);
if (item == nil && _delegate != nil)
{
item = [_delegate toolbar: self itemForItemIdentifier: itemIdent
willBeInsertedIntoToolbar: insert];
}
if (item == nil && _interfaceBuilderItemsByIdentifier)
{
item = [_interfaceBuilderItemsByIdentifier objectForKey: itemIdent];
}
return item;
}
@ -1141,40 +1235,35 @@ static GSValidationCenter *vc = nil;
[toolbar signature]; \
} \
- (NSArray *) _allowedItemIdentifiers
{
if (_delegate)
{
return [_delegate toolbarAllowedItemIdentifiers: self];
}
else
{
return _interfaceBuilderAllowedItemIdentifiers;
}
}
- (void) _insertItemWithItemIdentifier: (NSString *)itemIdentifier
atIndex: (int)index
broadcast: (BOOL)broadcast
{
NSToolbarItem *item = nil;
NSArray *allowedItems;
if (_delegate == nil)
return;
allowedItems = [_delegate toolbarAllowedItemIdentifiers: self];
NSArray *allowedItems = [self _allowedItemIdentifiers];
if ([allowedItems containsObject: itemIdentifier])
{
item = [self _toolbarItemForIdentifier: itemIdentifier];
if (item == nil)
{
item =
[_delegate toolbar: self itemForItemIdentifier: itemIdentifier
willBeInsertedIntoToolbar: YES];
}
item = [self _toolbarItemForIdentifier: itemIdentifier willBeInsertedIntoToolbar: YES];
if (item != nil)
{
NSArray *selectableItems;
NSArray *selectableItems = [self _selectableItemIdentifiers];
if ([_delegate respondsToSelector:
@selector(toolbarSelectableItemIdentifiers:)])
{
selectableItems =
[_delegate toolbarSelectableItemIdentifiers: self];
if ([selectableItems containsObject: itemIdentifier])
[item _setSelectable: YES];
}
if ([selectableItems containsObject: itemIdentifier])
[item _setSelectable: YES];
[nc postNotificationName: NSToolbarWillAddItemNotification
object: self
@ -1451,4 +1540,6 @@ static GSValidationCenter *vc = nil;
[self validateVisibleItems];
}
@end

View file

@ -94,7 +94,6 @@
toIndex: (int)newIndex
broadcast: (BOOL)broacast;
- (void) _performRemoveItem: (NSToolbarItem *)item; // Used by drag setup
- (NSToolbarItem *) _toolbarItemForIdentifier: (NSString *)itemIdent;
- (NSToolbar *) _toolbarModel;
- (void) _validate: (NSWindow *)observedWindow;
- (void) _toolbarViewWillMoveToSuperview: (NSView *)newSuperview;
@ -111,6 +110,13 @@
// Deprecated
- (void) setUsesStandardBackgroundColor: (BOOL)standard;
- (BOOL) usesStandardBackgroundColor;
// Delegate wrappers
- (NSArray *) _allowedItemIdentifiers;
- (NSArray *) _defaultItemIdentifiers;
- (NSArray *) _selectableItemIdentifiers;
- (NSToolbarItem *) _toolbarItemForIdentifier: (NSString *)itemIdent willBeInsertedIntoToolbar: (BOOL)insert;
@end
@interface GSWindowDecorationView (ToolbarPrivate)

View file

@ -929,12 +929,12 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
*/
// ---- NSToolbarSeparatorItemIdentifier
@interface GSToolbarSeparatorItem : NSToolbarItem
@interface NSToolbarSeparatorItem : NSToolbarItem
{
}
@end
@implementation GSToolbarSeparatorItem
@implementation NSToolbarSeparatorItem
- (id) initWithItemIdentifier: (NSString *)itemIdentifier
{
self = [super initWithItemIdentifier: itemIdentifier];
@ -977,12 +977,12 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
@end
// ---- NSToolbarSpaceItemIdentifier
@interface GSToolbarSpaceItem : NSToolbarItem
@interface NSToolbarSpaceItem : NSToolbarItem
{
}
@end
@implementation GSToolbarSpaceItem
@implementation NSToolbarSpaceItem
- (id) initWithItemIdentifier: (NSString *)itemIdentifier
{
self = [super initWithItemIdentifier: itemIdentifier];
@ -1007,12 +1007,12 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
@end
// ---- NSToolbarFlexibleSpaceItemIdentifier
@interface GSToolbarFlexibleSpaceItem : NSToolbarItem
@interface NSToolbarFlexibleSpaceItem : NSToolbarItem
{
}
@end
@implementation GSToolbarFlexibleSpaceItem
@implementation NSToolbarFlexibleSpaceItem
- (id) initWithItemIdentifier: (NSString *)itemIdentifier
{
self = [super initWithItemIdentifier: itemIdentifier];
@ -1167,25 +1167,25 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
{
// GNUstep predefined toolbar items
if ([itemIdentifier isEqualToString: NSToolbarSeparatorItemIdentifier]
&& [self isKindOfClass: [GSToolbarSeparatorItem class]] == NO)
&& [self isKindOfClass: [NSToolbarSeparatorItem class]] == NO)
{
RELEASE(self);
return [[GSToolbarSeparatorItem alloc]
return [[NSToolbarSeparatorItem alloc]
initWithItemIdentifier: itemIdentifier];
}
else if ([itemIdentifier isEqualToString: NSToolbarSpaceItemIdentifier]
&& [self isKindOfClass: [GSToolbarSpaceItem class]] == NO)
&& [self isKindOfClass: [NSToolbarSpaceItem class]] == NO)
{
RELEASE(self);
return [[GSToolbarSpaceItem alloc]
return [[NSToolbarSpaceItem alloc]
initWithItemIdentifier: itemIdentifier];
}
else if ([itemIdentifier
isEqualToString: NSToolbarFlexibleSpaceItemIdentifier]
&& [self isKindOfClass: [GSToolbarFlexibleSpaceItem class]] == NO)
&& [self isKindOfClass: [NSToolbarFlexibleSpaceItem class]] == NO)
{
RELEASE(self);
return [[GSToolbarFlexibleSpaceItem alloc]
return [[NSToolbarFlexibleSpaceItem alloc]
initWithItemIdentifier: itemIdentifier];
}
else if ([itemIdentifier
@ -1645,4 +1645,39 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
{
return [NSString stringWithFormat: @"<%@ - <%@>>",[super description],[self itemIdentifier]];
}
- (id) initWithCoder: (NSCoder *)aCoder
{
self = [self initWithItemIdentifier: [aCoder decodeObjectForKey:@"NSToolbarItemIdentifier"]];
if ([aCoder containsValueForKey: @"NSToolbarItemTarget"])
[self setTarget: [aCoder decodeObjectForKey:@"NSToolbarItemTarget"]];
if ([aCoder containsValueForKey: @"NSToolbarItemAction"])
[self setAction: NSSelectorFromString([aCoder decodeObjectForKey:@"NSToolbarItemAction"])];
if ([aCoder containsValueForKey: @"NSToolbarItemToolTip"])
[self setToolTip: [aCoder decodeObjectForKey:@"NSToolbarItemToolTip"]];
if ([aCoder containsValueForKey: @"NSToolbarItemTag"])
[self setTag: [aCoder decodeIntForKey:@"NSToolbarItemTag"]];
if ([aCoder containsValueForKey: @"NSToolbarItemImage"])
[self setImage: [aCoder decodeObjectForKey:@"NSToolbarItemImage"]];
if ([aCoder containsValueForKey: @"NSToolbarItemEnabled"])
[self setEnabled: [aCoder decodeBoolForKey:@"NSToolbarItemEnabled"]];
if ([aCoder containsValueForKey: @"NSToolbarItemPaletteLabel"])
[self setPaletteLabel: [aCoder decodeObjectForKey:@"NSToolbarItemPaletteLabel"]];
if ([aCoder containsValueForKey: @"NSToolbarItemLabel"])
[self setLabel: [aCoder decodeObjectForKey:@"NSToolbarItemLabel"]];
if ([aCoder containsValueForKey: @"NSToolbarItemMinSize"])
[self setMinSize: NSSizeFromString([aCoder decodeObjectForKey:@"NSToolbarItemMinSize"])];
if ([aCoder containsValueForKey: @"NSToolbarItemMaxSize"])
[self setMaxSize: NSSizeFromString([aCoder decodeObjectForKey:@"NSToolbarItemMaxSize"])];
if ([aCoder containsValueForKey: @"NSToolbarItemAutovalidates"])
[self setAutovalidates: [aCoder decodeBoolForKey:@"NSToolbarItemAutovalidates"]];
if ([aCoder containsValueForKey: @"NSToolbarItemVisibilityPriority"])
[self setVisibilityPriority: [aCoder decodeIntForKey:@"NSToolbarItemVisibilityPriority"]];
if ([aCoder containsValueForKey: @"NSToolbarItemView"])
[self setView: [aCoder decodeObjectForKey: @"NSToolbarItemView"]];
return self;
}
@end