* English.lproj/GormPalettePanel.gorm: Moved palette window to

gorm file.
	* GNUmakefile: Added new gorm here.
	* GormCore/GormDocument.m: Made toolbar items smaller
	* GormCore/GormPalettesManager.[hm]: Added toolbar implementation
	to this class to allow the user to switch palettes using the toolbar.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@26477 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Gregory John Casamento 2008-04-27 23:34:38 +00:00
parent 0a0af253db
commit c51b7b4e4b
8 changed files with 170 additions and 87 deletions

View file

@ -1,3 +1,12 @@
2008-04-27 19:32-EDT Gregory John Casamento <greg_casamento@yahoo.com>
* English.lproj/GormPalettePanel.gorm: Moved palette window to
gorm file.
* GNUmakefile: Added new gorm here.
* GormCore/GormDocument.m: Made toolbar items smaller
* GormCore/GormPalettesManager.[hm]: Added toolbar implementation
to this class to allow the user to switch palettes using the toolbar.
2008-04-25 17:41-EDT Gregory John Casamento <greg_casamento@yahoo.com>
* English.lproj/GormDocument.gorm: Corrected possition.

View file

@ -0,0 +1,27 @@
{
"## Comment" = "Do NOT change this file, Gorm maintains it";
GormPalettePanel = {
Actions = (
);
Outlets = (
);
Super = NSPanel;
};
GormPaletteView = {
Actions = (
);
Outlets = (
);
Super = NSView;
};
GormPalettesManager = {
Actions = (
);
Outlets = (
panel,
dragView,
selectionView
);
Super = NSObject;
};
}

Binary file not shown.

Binary file not shown.

View file

@ -149,6 +149,7 @@ Gorm_LOCALIZED_RESOURCE_FILES = \
GormInspectorPanel.gorm \
GormObjectInspector.gorm \
GormNSSplitViewInspector.gorm \
GormPalettePanel.gorm \
GormPrefColors.gorm \
GormPreferences.gorm \
GormPrefGeneral.gorm \

View file

@ -341,6 +341,7 @@ static NSImage *fileImage = nil;
// set up the toolbar...
toolbar = [(NSToolbar *)[NSToolbar alloc] initWithIdentifier: @"GormToolbar"];
[toolbar setAllowsUserCustomization: NO];
[toolbar setSizeMode: NSToolbarSizeModeSmall];
[toolbar setDelegate: self];
[window setToolbar: toolbar];
RELEASE(toolbar);

View file

@ -37,13 +37,16 @@
NSMatrix *selectionView;
NSView *dragView;
NSMutableArray *bundles;
NSMutableArray *palettes;
NSMutableDictionary *palettesDict;
NSMutableArray *palettes;
NSMutableArray *paletteNames;
int current;
BOOL hiddenDuringTest;
NSMutableDictionary *importedClasses;
NSMutableArray *importedImages;
NSMutableArray *importedSounds;
NSMutableDictionary *substituteClasses;
NSToolbar *toolbar;
}
// methods for loading and display the palette panels
@ -51,6 +54,7 @@
- (id) openPalette: (id) sender;
- (NSPanel*) panel;
- (void) setCurrentPalette: (id)anObject;
- (void) setCurrentPaletteWithTag: (int)tag;
// methods for importing stuff from palettes
- (void) importClasses: (NSArray *)classes withDictionary: (NSDictionary *)dict;

View file

@ -150,7 +150,6 @@ static NSImage *dragImage = nil;
return YES;
}
/*
* Intercepting events in the view and handling them
*/
@ -255,6 +254,7 @@ static NSImage *dragImage = nil;
RELEASE(panel);
RELEASE(bundles);
RELEASE(palettes);
RELEASE(palettesDict);
RELEASE(importedClasses);
RELEASE(importedImages);
RELEASE(importedSounds);
@ -287,63 +287,52 @@ static NSImage *dragImage = nil;
- (id) init
{
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
NSScrollView *scrollView;
NSArray *array;
NSRect contentRect = {{0, 0}, {272, 266}};
NSRect selectionRect = {{0, 0}, {52, 52}};
NSRect scrollRect = {{0, 192}, {272, 74}};
NSRect dragRect = {{0, 0}, {272, 192}};
unsigned int style = NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSArray *userPalettes = [defaults arrayForKey: USER_PALETTES];
panel = [[GormPalettePanel alloc] initWithContentRect: contentRect
styleMask: style
backing: NSBackingStoreRetained
defer: NO];
[panel setTitle: _(@"Palettes")];
[panel setMinSize: [panel frame].size];
self = [super init];
if(self != nil)
{
if([NSBundle loadNibNamed: @"GormPalettePanel" owner: self] == NO)
{
return nil;
}
}
else
{
return nil;
}
// allocate arrays and dictionaries.
bundles = [[NSMutableArray alloc] init];
//
// Initialize dictionary
//
palettesDict = [[NSMutableDictionary alloc] init];
palettes = [[NSMutableArray alloc] init];
importedClasses = [[NSMutableDictionary alloc] init];
importedImages = [[NSMutableArray alloc] init];
importedSounds = [[NSMutableArray alloc] init];
paletteNames = [[NSMutableArray alloc] init];
substituteClasses = [[NSMutableDictionary alloc] init];
scrollView = [[NSScrollView alloc] initWithFrame: scrollRect];
[scrollView setHasHorizontalScroller: YES];
[scrollView setHasVerticalScroller: NO];
[scrollView setAutoresizingMask: NSViewMinYMargin | NSViewWidthSizable];
[scrollView setBorderType: NSBezelBorder];
selectionView = [[NSMatrix alloc] initWithFrame: selectionRect
mode: NSRadioModeMatrix
cellClass: [NSImageCell class]
numberOfRows: 1
numberOfColumns: 0];
[selectionView setTarget: self];
[selectionView setAction: @selector(setCurrentPalette:)];
[selectionView setCellSize: NSMakeSize(52,52)];
[selectionView setIntercellSpacing: NSMakeSize(0,0)];
[scrollView setDocumentView: selectionView];
RELEASE(selectionView);
[[panel contentView] addSubview: scrollView];
RELEASE(scrollView);
dragView = [[GormPaletteView alloc] initWithFrame: dragRect];
[dragView setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];
[[panel contentView] addSubview: dragView];
RELEASE(dragView);
//
// Set frame name
//
[panel setFrameUsingName: @"Palettes"];
[panel setFrameAutosaveName: @"Palettes"];
current = -1;
//
// Set up the toolbar.
//
toolbar = [(NSToolbar *)[NSToolbar alloc] initWithIdentifier: @"GormPalettesToolbar"];
[toolbar setDisplayMode: NSToolbarDisplayModeIconOnly];
[toolbar setSizeMode: NSToolbarSizeModeSmall];
[toolbar setAllowsUserCustomization: NO];
[toolbar setDelegate: self];
[panel setToolbar: toolbar];
RELEASE(toolbar);
array = [[NSBundle mainBundle] pathsForResourcesOfType: @"palette"
inDirectory: nil];
if ([array count] > 0)
inDirectory: nil];
if ([array count] > 0)
{
unsigned index;
@ -355,31 +344,30 @@ static NSImage *dragImage = nil;
}
}
// if we have any user palettes load them as well.
if(userPalettes != nil)
{
NSEnumerator *en = [userPalettes objectEnumerator];
id paletteName = nil;
while((paletteName = [en nextObject]) != nil)
{
[self loadPalette: paletteName];
}
}
// if we have any user palettes load them as well.
if(userPalettes != nil)
{
NSEnumerator *en = [userPalettes objectEnumerator];
id paletteName = nil;
while((paletteName = [en nextObject]) != nil)
{
[self loadPalette: paletteName];
}
}
/*
* Select initial palette - this should be the standard controls palette.
*/
[selectionView selectCellAtRow: 0 column: 2];
[self setCurrentPalette: selectionView];
[self setCurrentPaletteWithTag: 2];
[nc addObserver: self
selector: @selector(handleNotification:)
name: IBWillBeginTestingInterfaceNotification
object: nil];
selector: @selector(handleNotification:)
name: IBWillBeginTestingInterfaceNotification
object: nil];
[nc addObserver: self
selector: @selector(handleNotification:)
name: IBWillEndTestingInterfaceNotification
object: nil];
selector: @selector(handleNotification:)
name: IBWillEndTestingInterfaceNotification
object: nil];
return self;
}
@ -411,8 +399,6 @@ static NSImage *dragImage = nil;
NSArray *exportImages;
NSDictionary *subClasses;
IBPalette *palette;
NSImageCell *cell;
int col;
if([self bundlePathIsLoaded: path])
{
@ -535,16 +521,14 @@ static NSImage *dragImage = nil;
[window setFrame: NSMakeRect(0,0,272,192) display: NO];
}
// manage palette data.
[palettesDict setObject: palette forKey: className];
[palettes addObject: palette];
[paletteNames addObject: className];
[selectionView addColumn];
[[palette paletteIcon] setBackgroundColor: [selectionView backgroundColor]];
col = [selectionView numberOfColumns] - 1;
cell = [selectionView cellAtRow: 0 column: col];
[cell setImageFrameStyle: NSImageFrameButton];
[cell setImage: [palette paletteIcon]];
[selectionView sizeToCells];
[selectionView selectCellAtRow: 0 column: col];
[self setCurrentPalette: selectionView];
[toolbar insertItemWithItemIdentifier: className atIndex: ([palettes count] - 1)];
[self setCurrentPalette: 0];
RELEASE(palette);
return YES;
@ -610,7 +594,12 @@ static NSImage *dragImage = nil;
return panel;
}
- (void) setCurrentPalette: (id)anObj
- (void) setCurrentPalette: (id)anObject
{
[self setCurrentPaletteWithTag: [anObject tag]];
}
- (void) setCurrentPaletteWithTag: (int)tag
{
NSView *wv;
NSView *sv;
@ -633,7 +622,7 @@ static NSImage *dragImage = nil;
}
}
current = [anObj selectedColumn];
current = tag;
if (current >= 0 && current < [palettes count])
{
id palette = [palettes objectAtIndex: current];
@ -649,8 +638,12 @@ static NSImage *dragImage = nil;
* Resize our drag view to the right size fitrst.
*/
wv = [[palette originalWindow] contentView];
if (wv)
[dragView setFrameSize: [wv frame].size];
if(wv)
{
[dragView setFrameSize: [wv frame].size];
}
// iterate over the subviews and add them to the dragview.
enumerator = [[wv subviews] objectEnumerator];
while ((sv = [enumerator nextObject]) != nil)
{
@ -662,7 +655,7 @@ static NSImage *dragImage = nil;
}
else
{
NSLog(@"Bad palette selection - %d", [anObj selectedColumn]);
NSLog(@"Bad palette selection - %d", tag);
current = -1;
}
[dragView setNeedsDisplay: YES];
@ -821,3 +814,51 @@ static NSImage *dragImage = nil;
return substituteClasses;
}
@end
@implementation GormPalettesManager (NSToolbarDelegate)
- (NSToolbarItem*)toolbar: (NSToolbar*)toolbar
itemForItemIdentifier: (NSString*)itemIdentifier
willBeInsertedIntoToolbar: (BOOL)flag
{
NSToolbarItem *toolbarItem = AUTORELEASE([[NSToolbarItem alloc]
initWithItemIdentifier: itemIdentifier]);
id palette = [palettesDict objectForKey: itemIdentifier];
NSImage *image = [palette paletteIcon];
int tag = [palettes indexOfObject: palette];
NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle: itemIdentifier
action: @selector(setCurrentPalette:)
keyEquivalent: @""];
// set up the toolbar...
[toolbarItem setLabel: itemIdentifier];
[toolbarItem setToolTip: itemIdentifier];
[toolbarItem setImage: image];
[toolbarItem setTarget: self];
[toolbarItem setAction: @selector(setCurrentPalette:)];
[toolbarItem setTag: tag];
[toolbarItem setMenuFormRepresentation: menuItem];
// complete setup of menu item.
[menuItem setTarget: self];
[menuItem setTag: tag];
RELEASE(menuItem);
return toolbarItem;
}
- (NSArray*) toolbarAllowedItemIdentifiers: (NSToolbar*)toolbar
{
return paletteNames;
}
- (NSArray*) toolbarDefaultItemIdentifiers: (NSToolbar*)toolbar
{
return [NSArray array];
}
- (NSArray*) toolbarSelectableItemIdentifiers: (NSToolbar*)toolbar
{
return paletteNames;
}
@end