From 31e0c9633c2bc06591da14a4eada0bffcfd4390d Mon Sep 17 00:00:00 2001 From: gcasa Date: Mon, 16 Mar 2009 07:33:31 +0000 Subject: [PATCH] * Source/GSToolbarView.m: Added code to save the configuration when deleting an item as well as saving an item. * Source/NSToolbarFrameworkPrivate.h: removed old _loadConfig method added new methods to track changes to toolbars. * Source/NSToolbar.m: Added check for items already in the toolbar, removed calls to _loadConfig which were commented out, implemented setConfigurationFromDictionary: as described in the documentation, changed _build to get dictionary from defaults if it's there. Implemented new method _containsItemWithIdentifier: and _itemsFromConfig. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@28084 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 13 ++++ Source/GSToolbarView.m | 14 +++- Source/NSToolbar.m | 115 +++++++++++++++++++++++++---- Source/NSToolbarFrameworkPrivate.h | 5 +- 4 files changed, 126 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 848e9752c..f26ab1c43 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2009-03-16 03:29-EDT Gregory John Casamento + + * Source/GSToolbarView.m: Added code to save the configuration when + deleting an item as well as saving an item. + * Source/NSToolbarFrameworkPrivate.h: removed old _loadConfig method + added new methods to track changes to toolbars. + * Source/NSToolbar.m: Added check for items already in the toolbar, + removed calls to _loadConfig which were commented out, implemented + setConfigurationFromDictionary: as described in the documentation, + changed _build to get dictionary from defaults if it's there. + Implemented new method _containsItemWithIdentifier: and + _itemsFromConfig. + 2009-03-16 01:22-EDT Gregory John Casamento * Source/GSToolbarView.m: Call the _insertItemWithItemIdentifier:.. diff --git a/Source/GSToolbarView.m b/Source/GSToolbarView.m index 16dcb7dfb..442435643 100644 --- a/Source/GSToolbarView.m +++ b/Source/GSToolbarView.m @@ -397,13 +397,16 @@ static void initSystemExtensionsColors(void) NSToolbar *toolbar = [self toolbar]; NSToolbarItem *item = [[info draggingSource] toolbarItem]; int newIndex = [self _insertionIndexAtPoint: [info draggingLocation]]; - // Calculate the index if(index == -1) { - [toolbar _insertItemWithItemIdentifier: [item itemIdentifier] - atIndex: newIndex - broadcast: YES]; + NSString *identifier = [item itemIdentifier]; + if([_toolbar _containsItemWithIdentifier: identifier] == NO) + { + [toolbar _insertItemWithItemIdentifier: identifier + atIndex: newIndex + broadcast: YES]; + } RELEASE(item); } else @@ -412,6 +415,9 @@ static void initSystemExtensionsColors(void) RELEASE(item); [toolbar _moveItemFromIndex: index toIndex: newIndex broadcast: YES]; } + + // save the configuration... + [toolbar _saveConfig]; return YES; } diff --git a/Source/NSToolbar.m b/Source/NSToolbar.m index 5e37ffcfc..936b8ad47 100644 --- a/Source/NSToolbar.m +++ b/Source/NSToolbar.m @@ -41,6 +41,7 @@ #include #include #include +#include #include "AppKit/NSApplication.h" #include "AppKit/NSEvent.h" #include "AppKit/NSMenu.h" @@ -520,8 +521,6 @@ static GSValidationCenter *vc = nil; _displayMode = [toolbarModel displayMode]; _sizeMode = [toolbarModel sizeMode]; _visible = [toolbarModel isVisible]; - - // [self _loadConfig]; } else { @@ -532,8 +531,6 @@ static GSValidationCenter *vc = nil; _displayMode = NSToolbarDisplayModeIconAndLabel; _sizeMode = NSToolbarSizeModeRegular; _visible = YES; - - // [self _loadConfig]; } _delegate = nil; @@ -707,7 +704,33 @@ static GSValidationCenter *vc = nil; - (void) setConfigurationFromDictionary: (NSDictionary *)configDict { + int i = 0; + id item = nil; + NSArray *items = nil; + NSEnumerator *en = nil; + ASSIGN(_configurationDictionary, configDict); + + // set + _visible = [[_configurationDictionary objectForKey: @"isVisible"] boolValue]; + _displayMode = [[_configurationDictionary objectForKey: @"displayMode"] intValue]; + + // remove all items... + for(i = 0; i < [_items count]; i++) + { + [self _removeItemAtIndex: 0 broadcast: YES]; + } + + // add all of the items... + i = 0; + items = [_configurationDictionary objectForKey: @"items"]; + en = [items objectEnumerator]; + while((item = [en nextObject]) != nil) + { + [self _insertItemWithItemIdentifier: item + atIndex: i++ + broadcast: YES]; + } } /** @@ -885,15 +908,19 @@ static GSValidationCenter *vc = nil; } toolbarModel = [self _toolbarModel]; - - if (toolbarModel != nil) + + wantedItemIdentifiers = [self _itemsFromConfig]; + if(wantedItemIdentifiers == nil) { - wantedItemIdentifiers = - [[toolbarModel items] valueForKey: @"_itemIdentifier"]; - } - else - { - wantedItemIdentifiers = [_delegate toolbarDefaultItemIdentifiers:self]; + if (toolbarModel != nil) + { + wantedItemIdentifiers = + [[toolbarModel items] valueForKey: @"_itemIdentifier"]; + } + else + { + wantedItemIdentifiers = [_delegate toolbarDefaultItemIdentifiers:self]; + } } e = [wantedItemIdentifiers objectEnumerator]; @@ -947,8 +974,64 @@ static GSValidationCenter *vc = nil; } } -- (void) _loadConfig +- (void) _saveConfig { + if (_identifier != nil) + { + NSUserDefaults *defaults; + NSString *tableKey; + id config; + NSMutableArray *items = [NSMutableArray array]; + id item; + NSEnumerator *en = [_items objectEnumerator]; + + defaults = [NSUserDefaults standardUserDefaults]; + tableKey = + [NSString stringWithFormat: @"NSToolbar Config %@",_identifier]; + + config = [defaults objectForKey: tableKey]; + + if (config == nil) + { + config = [NSMutableDictionary dictionary]; + } + else + { + config = [config mutableCopy]; + } + + [config setObject: [NSNumber numberWithBool: _visible] forKey: @"isVisible"]; + [config setObject: [NSNumber numberWithInt: _displayMode] forKey: @"displayMode"]; + while((item = [en nextObject]) != nil) + { + [items addObject: [item itemIdentifier]]; + } + [config setObject: items forKey: @"items"]; + + // write to defaults + [defaults setObject: config forKey: tableKey]; + ASSIGN(_configurationDictionary, config); + } +} + +- (BOOL) _containsItemWithIdentifier: (NSString *)identifier +{ + NSEnumerator *en = [_items objectEnumerator]; + id item = nil; + + while((item = [en nextObject]) != nil) + { + if([identifier isEqual: [item itemIdentifier]]) + { + return YES; + } + } + return NO; +} + +- (NSArray *) _itemsFromConfig +{ + NSArray *items = nil; if (_identifier != nil) { NSUserDefaults *defaults; @@ -958,14 +1041,15 @@ static GSValidationCenter *vc = nil; defaults = [NSUserDefaults standardUserDefaults]; tableKey = [NSString stringWithFormat: @"NSToolbar Config %@",_identifier]; - + config = [defaults objectForKey: tableKey]; if (config != nil) { - [self setConfigurationFromDictionary: config]; + items = [config objectForKey: @"items"]; } } + return items; } - (NSToolbar *) _toolbarModel @@ -1098,6 +1182,7 @@ static GSValidationCenter *vc = nil; { [_items removeObject: item]; [_toolbarView _reload]; + [self _saveConfig]; } - (void) _concludeRemoveItem: (NSToolbarItem *)item atIndex: (int)index broadcast: (BOOL)broadcast diff --git a/Source/NSToolbarFrameworkPrivate.h b/Source/NSToolbarFrameworkPrivate.h index 805fb4274..a9d1bcb24 100644 --- a/Source/NSToolbarFrameworkPrivate.h +++ b/Source/NSToolbarFrameworkPrivate.h @@ -86,7 +86,6 @@ // Few other private methods - (void) _build; - - (int) _indexOfItem: (NSToolbarItem *)item; - (void) _concludeRemoveItem: (NSToolbarItem *)item atIndex: (int)index @@ -96,11 +95,13 @@ toIndex: (int)newIndex broadcast: (BOOL)broacast; - (void) _performRemoveItem: (NSToolbarItem *)item; // Used by drag setup -- (void) _loadConfig; - (NSToolbarItem *) _toolbarItemForIdentifier: (NSString *)itemIdent; - (NSToolbar *) _toolbarModel; - (void) _validate: (NSWindow *)observedWindow; - (void) _toolbarViewWillMoveToSuperview: (NSView *)newSuperview; +- (void) _saveConfig; +- (NSArray *) _itemsFromConfig; +- (BOOL) _containsItemWithIdentifier: (NSString *) identifier; // Accessors - (void) _setCustomizationPaletteIsRunning: (BOOL)isRunning;