From c51b7b4e4b73613411d9f5000e1dce61281384bf Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Sun, 27 Apr 2008 23:34:38 +0000 Subject: [PATCH] * 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 --- ChangeLog | 9 + .../GormPalettePanel.gorm/data.classes | 27 +++ English.lproj/GormPalettePanel.gorm/data.info | Bin 0 -> 184 bytes .../GormPalettePanel.gorm/objects.gorm | Bin 0 -> 1299 bytes GNUmakefile | 1 + GormCore/GormDocument.m | 1 + GormCore/GormPalettesManager.h | 6 +- GormCore/GormPalettesManager.m | 213 +++++++++++------- 8 files changed, 170 insertions(+), 87 deletions(-) create mode 100644 English.lproj/GormPalettePanel.gorm/data.classes create mode 100644 English.lproj/GormPalettePanel.gorm/data.info create mode 100644 English.lproj/GormPalettePanel.gorm/objects.gorm diff --git a/ChangeLog b/ChangeLog index b5429faa..353ea409 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-04-27 19:32-EDT Gregory John Casamento + + * 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 * English.lproj/GormDocument.gorm: Corrected possition. diff --git a/English.lproj/GormPalettePanel.gorm/data.classes b/English.lproj/GormPalettePanel.gorm/data.classes new file mode 100644 index 00000000..c1b72522 --- /dev/null +++ b/English.lproj/GormPalettePanel.gorm/data.classes @@ -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; + }; +} \ No newline at end of file diff --git a/English.lproj/GormPalettePanel.gorm/data.info b/English.lproj/GormPalettePanel.gorm/data.info new file mode 100644 index 0000000000000000000000000000000000000000..b48c50a5a060bffea38d60c8ffa4e63a46400366 GIT binary patch literal 184 zcmZ?w3oR~5El@}-O3uhEOEmxjqvX^yD-Z(+j4>DnRtAiQj0_^~`9-;InK`KeMX71U zzKMB>>8V8wKw!wkz~L9{pOlrFTms@Vs4_4zu^KQLGK0i}ONuh{(t)Ck3~E4%leh&6lmiG3NV7d~=mpwDM3typVSdgVX9_VPgtF_M_rC}~m3sg*Spl|t-q|$e{gLp5I%XTN?cO}I zz;eB%0X&hu1{PQm>OJpc5Duc*J28$&JQbv2C5qk|@yW!S@iag#!g{0D-{VaqO2@0QPYm zz_B~uufXoS0Tsqp7LMKh`3mfAU#4TRZ790lhd|7v?|&d9GDT3!HDnXyXP5?6WM@9d zBC9|(FWzyI@Jn)IRU)+7YTgD>Hn7BM)Pl}*l1AfIF02lls(+`c7?T-bc~PbywY*w2 zvlk`f3qBHQD#-Chia%twEAr2AlQk%XPBe;W77Bn{8nBTAHe~r-J{ALIjaPEcog_N4WjVWkHWcXpll-57S=1+ zrTE=na#9+LiqhlGN@%hsH1j@p1D^nSqMO~K`?G$g@HeofQ(7PS^O?M#*w(6MUX14T z{!Y$#D5)jr{Htd2$~?tqSpj#owvvNX%)f(0CMDdvodOLHDJ{IC`KjAz;a%3IVb;$` zC?5?qIsloIwdQzl(a!cVXO8<)*v*(X1jQBo8KVeLrM`JEt;wge*mSa^F;sv literal 0 HcmV?d00001 diff --git a/GNUmakefile b/GNUmakefile index ab9c1f83..e9f1725c 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -149,6 +149,7 @@ Gorm_LOCALIZED_RESOURCE_FILES = \ GormInspectorPanel.gorm \ GormObjectInspector.gorm \ GormNSSplitViewInspector.gorm \ + GormPalettePanel.gorm \ GormPrefColors.gorm \ GormPreferences.gorm \ GormPrefGeneral.gorm \ diff --git a/GormCore/GormDocument.m b/GormCore/GormDocument.m index c44ba7d3..5fa1901e 100644 --- a/GormCore/GormDocument.m +++ b/GormCore/GormDocument.m @@ -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); diff --git a/GormCore/GormPalettesManager.h b/GormCore/GormPalettesManager.h index 4a168c21..5ebc8415 100644 --- a/GormCore/GormPalettesManager.h +++ b/GormCore/GormPalettesManager.h @@ -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; diff --git a/GormCore/GormPalettesManager.m b/GormCore/GormPalettesManager.m index 89eb6366..27bdbc93 100644 --- a/GormCore/GormPalettesManager.m +++ b/GormCore/GormPalettesManager.m @@ -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,100 +287,88 @@ 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]; - - // allocate arrays and dictionaries. - bundles = [[NSMutableArray alloc] init]; + self = [super init]; + if(self != nil) + { + if([NSBundle loadNibNamed: @"GormPalettePanel" owner: self] == NO) + { + return nil; + } + } + else + { + return nil; + } + + // + // 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; - + array = [array sortedArrayUsingSelector: @selector(compare:)]; - + for (index = 0; index < [array count]; index++) { [self loadPalette: [array objectAtIndex: index]]; } } - - // 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