Commit [r657] Maximize Restore History

Converted LDrawColorPanel to an NSWindowController

lightbulbs 2014-04-10

changed /trunk/Bricksmith/Source/Widgets/LDrawColorBar.m
changed /trunk/Bricksmith/Source/Application/General/PartBrowserDataSource.m
changed /trunk/Bricksmith/Bricksmith.xcodeproj/project.pbxproj
changed /trunk/Bricksmith/Source/Application/Document/LDrawDocument.m
changed /trunk/Bricksmith/Source/Application/Document/SearchPanelController.m
changed /trunk/Bricksmith/Resources/Interface/English.lproj/ColorPanel.xib
changed /trunk/Bricksmith/Source/Application/General/ToolPalette.m
changed /trunk/Bricksmith/Source/Application/General/LDrawApplication.m
changed /trunk/Bricksmith/Source/Widgets/LDrawColorBar.h
changed /trunk/Bricksmith/Source/Application/Document/PieceCountPanel.m
changed /trunk/Bricksmith/Source/Widgets/LDrawColorWell.m
copied /trunk/Bricksmith/Source/Application/General/LDrawColorPanel.h -> /trunk/Bricksmith/Source/Application/General/LDrawColorPanelController.h
copied /trunk/Bricksmith/Source/Application/General/LDrawColorPanel.m -> /trunk/Bricksmith/Source/Application/General/LDrawColorPanelController.m
/trunk/Bricksmith/Source/Widgets/LDrawColorBar.m Diff Switch to side-by-side view
Loading...
/trunk/Bricksmith/Source/Application/General/PartBrowserDataSource.m Diff Switch to side-by-side view
Loading...
/trunk/Bricksmith/Bricksmith.xcodeproj/project.pbxproj Diff Switch to side-by-side view
Loading...
/trunk/Bricksmith/Source/Application/Document/LDrawDocument.m Diff Switch to side-by-side view
Loading...
/trunk/Bricksmith/Source/Application/Document/SearchPanelController.m Diff Switch to side-by-side view
Loading...
/trunk/Bricksmith/Resources/Interface/English.lproj/ColorPanel.xib Diff Switch to side-by-side view
Loading...
/trunk/Bricksmith/Source/Application/General/ToolPalette.m Diff Switch to side-by-side view
Loading...
/trunk/Bricksmith/Source/Application/General/LDrawApplication.m Diff Switch to side-by-side view
Loading...
/trunk/Bricksmith/Source/Widgets/LDrawColorBar.h Diff Switch to side-by-side view
Loading...
/trunk/Bricksmith/Source/Application/Document/PieceCountPanel.m Diff Switch to side-by-side view
Loading...
/trunk/Bricksmith/Source/Widgets/LDrawColorWell.m Diff Switch to side-by-side view
Loading...
/trunk/Bricksmith/Source/Application/General/LDrawColorPanel.h to /trunk/Bricksmith/Source/Application/General/LDrawColorPanelController.h
--- a/trunk/Bricksmith/Source/Application/General/LDrawColorPanel.h
+++ b/trunk/Bricksmith/Source/Application/General/LDrawColorPanelController.h
@@ -1,6 +1,6 @@
 //==============================================================================
 //
-// File:		LDrawColorPanel.h
+// File:		LDrawColorPanelController.h
 //
 // Purpose:		Color-picker for Bricksmith.
 //
@@ -15,12 +15,11 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 //
-// Class:		LDrawColorPanel
+// Class:		LDrawColorPanelController
 //
 ////////////////////////////////////////////////////////////////////////////////
-@interface LDrawColorPanel : NSPanel <LDrawColorable, NSWindowDelegate>
+@interface LDrawColorPanelController : NSWindowController <LDrawColorable>
 {
-	IBOutlet	LDrawColorPanel		*colorPanel;
 	IBOutlet	LDrawColorBar		*colorBar;
 	IBOutlet	NSPopUpButton		*materialPopUpButton;
 	IBOutlet	NSTableView			*colorTable;
@@ -34,7 +33,7 @@
 }
 
 //Initialization
-+ (LDrawColorPanel *) sharedColorPanel;
++ (LDrawColorPanelController *) sharedColorPanel;
 
 //Actions
 - (void) focusSearchField:(id)sender;
/trunk/Bricksmith/Source/Application/General/LDrawColorPanel.m to /trunk/Bricksmith/Source/Application/General/LDrawColorPanelController.m
--- a/trunk/Bricksmith/Source/Application/General/LDrawColorPanel.m
+++ b/trunk/Bricksmith/Source/Application/General/LDrawColorPanelController.m
@@ -1,6 +1,6 @@
 //==============================================================================
 //
-// File:		LDrawColorPanel.m
+// File:		LDrawColorPanelController.m
 //
 // Purpose:		Color-picker for Bricksmith. The color panel is used to browse, 
 //				select, and apply LDraw colors. The colors are presented by 
@@ -9,7 +9,7 @@
 //  Created by Allen Smith on 2/26/05.
 //  Copyright 2005. All rights reserved.
 //==============================================================================
-#import "LDrawColorPanel.h"
+#import "LDrawColorPanelController.h"
 
 #import "ColorLibrary.h"
 #import "LDrawColor.h"
@@ -34,13 +34,13 @@
 
 #define COLOR_SORT_DESCRIPTORS_KEY @"ColorTable Sort Ordering"
 
-@implementation LDrawColorPanel
+@implementation LDrawColorPanelController
 
 //There is supposed to be only one of these.
-LDrawColorPanel *sharedColorPanel = nil;
-
-
-//========== awakeFromNib ======================================================
+LDrawColorPanelController *sharedColorPanel = nil;
+
+
+//========== windowDidLoad =====================================================
 //
 // Purpose:		Brings the LDraw color panel to life.
 //
@@ -49,7 +49,7 @@
 //				table's data is even loaded, so you can't sort the data here.
 //
 //==============================================================================
-- (void) awakeFromNib
+- (void) windowDidLoad
 {
 	LDrawColorCell	*colorCell		= [[[LDrawColorCell alloc] init] autorelease];
 	NSTableColumn	*colorColumn	= [colorTable tableColumnWithIdentifier:@"colorCode"];
@@ -58,8 +58,9 @@
 	
 	[materialPopUpButton selectItemWithTag:MaterialTypeAll];
 	
-	//Remember, this method is called twice for an LDrawColorPanel; the first time 
-	// is for the File's Owner, which is promptly overwritten.
+	[(NSPanel*)[self window] setWorksWhenModal:YES];
+	[(NSPanel*)[self window] setLevel:NSStatusWindowLevel];
+	[(NSPanel*)[self window] setBecomesKeyOnlyIfNeeded:YES];
 	
 }//end awakeFromNib
 
@@ -73,10 +74,10 @@
 // Purpose:		Returns the global instance of the color panel.
 //
 //------------------------------------------------------------------------------
-+ (LDrawColorPanel *) sharedColorPanel
++ (LDrawColorPanelController *) sharedColorPanel
 {
 	if(sharedColorPanel == nil)
-		sharedColorPanel = [[LDrawColorPanel alloc] init];
+		sharedColorPanel = [[LDrawColorPanelController alloc] init];
 	
 	return sharedColorPanel;
 	
@@ -90,22 +91,22 @@
 //==============================================================================
 - (id) init
 {
-	id              oldself         = [super init];
-	ColorLibrary    *colorLibrary   = [ColorLibrary sharedColorLibrary];
-	NSArray         *colorList      = [colorLibrary colors];
-
-	[NSBundle loadNibNamed:@"ColorPanel" owner:self];
-	
-	self = colorPanel; //this don't look good, but it works.
-						//this takes the place of calling [super init]
-						// Note that connections in the Nib file must be made 
-						// to the colorPanel, not to the File's Owner!
-						
-	//While the data is being loaded in the table, a color will automatically 
-	// be selected. We do not want this color-selection to generate a 
-	// changeColor: message, so we turn on this flag.
-	updatingToReflectFile = YES;
-	
+	self = [super initWithWindowNibName:@"ColorPanel"];
+	if(self)
+	{
+		ColorLibrary    *colorLibrary   = [ColorLibrary sharedColorLibrary];
+		NSArray         *colorList      = [colorLibrary colors];
+		
+		//While the data is being loaded in the table, a color will automatically
+		// be selected. We do not want this color-selection to generate a
+		// changeColor: message, so we turn on this flag.
+		updatingToReflectFile = YES;
+		
+		// The application's selected color state is stored in an 
+		// NSArrayController that is instantiated by the nib. So no lazy loading 
+		// for us. Force nib to load now.
+		[self window];
+		
 		// Set the list of colors to display.
 		[self->colorListController setContent:colorList];
 		[self->colorListController addObserver:self forKeyPath:@"selectedObjects" options:kNilOptions context:NULL];
@@ -114,17 +115,8 @@
 		[self loadInitialSortDescriptors];
 		
 		[self setLDrawColor:[colorLibrary colorForCode:LDrawRed]];
-	updatingToReflectFile = NO;
-	
-	[self setDelegate:self];
-	[self setWorksWhenModal:YES];
-	[self setLevel:NSStatusWindowLevel];
-	[self setBecomesKeyOnlyIfNeeded:YES];
-	
-	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:NSApp];
-	
-	[oldself release];
-	
+		updatingToReflectFile = NO;
+	}
 	return self;
 	
 }//end init
@@ -204,7 +196,7 @@
 //==============================================================================
 - (void) focusSearchField:(id)sender
 {
-	[self makeFirstResponder:self->searchField];
+	[[self window] makeFirstResponder:self->searchField];
 	
 }//end focusSearchField:
 
@@ -218,23 +210,6 @@
 {
 	[self updateColorFilter];
 }
-
-//========== orderOut: =========================================================
-//
-// Purpose:		The color panel is being closed. If there is an active color 
-//				well, it needs to deactivate.
-//
-//==============================================================================
-- (void) orderOut:(id)sender
-{
-	//deactivate active color well.
-	if([LDrawColorWell activeColorWell] != nil)
-		[LDrawColorWell setActiveColorWell:nil];
-	
-	[super orderOut:sender];
-	
-}//end orderOut:
-
 
 //========== sendAction ========================================================
 //
@@ -609,8 +584,23 @@
 	
 }//end observeValueForKeyPath:ofObject:change:context:
 
-
-//**** NSWindow ****
+#pragma mark - NSWindow -
+
+//========== windowWillClose: ==================================================
+//
+// Purpose:		The color panel is being closed. If there is an active color
+//				well, it needs to deactivate.
+//
+//==============================================================================
+- (void) windowWillClose:(NSNotification *)notification
+{
+	//deactivate active color well.
+	if([LDrawColorWell activeColorWell] != nil)
+		[LDrawColorWell setActiveColorWell:nil];
+	
+}//end orderOut:
+
+
 //========== windowWillReturnUndoManager: ======================================
 //
 // Purpose:		Allows Undo to keep working transparently through this window by 
@@ -626,18 +616,6 @@
 }//end windowWillReturnUndoManager:
 
 
-//========== applicationWillTerminate: =========================================
-//
-// Purpose:		It seems we have some memory to mange. 
-//
-//==============================================================================
-- (void) applicationWillTerminate:(NSNotification *)notification
-{
-	[self release];
-	
-}//end applicationWillTerminate:
-
-
 #pragma mark -
 #pragma mark DESTRUCTOR
 #pragma mark -