* 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
This commit is contained in:
Gregory John Casamento 2009-03-16 07:33:31 +00:00
parent 6f3f7be33c
commit a74a5f8ffd
4 changed files with 126 additions and 21 deletions

View file

@ -1,3 +1,16 @@
2009-03-16 03:29-EDT Gregory John Casamento <greg_casamento@yahoo.com>
* 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 <greg_casamento@yahoo.com>
* Source/GSToolbarView.m: Call the _insertItemWithItemIdentifier:..

View file

@ -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;
}

View file

@ -41,6 +41,7 @@
#include <Foundation/NSString.h>
#include <Foundation/NSTimer.h>
#include <Foundation/NSUserDefaults.h>
#include <Foundation/NSDecimalNumber.h>
#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

View file

@ -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;