Anonymous avatar Anonymous committed 94fe672

Split view - Implemented design-time undo support and fixed document dirtying

Comments (0)

Files changed (5)

 	}
 }
 
-#pragma mark IB Inspector Support Notifications
-
-// This class doesn't have an appearance for wide vertical splitters, so we force all vertical splitters to thin.
-// We also post notifications that are used by the inspector to show & hide controls.
-
 - (void)setDividerStyle:(NSSplitViewDividerStyle)aStyle
 {
-	BOOL styleChanged = NO;
-	
-	if (aStyle != [self dividerStyle])
-		styleChanged = YES;
-	
 	[super setDividerStyle:aStyle];
 	
 	// There can be sizing issues during design-time if we don't call this
 	[self adjustSubviews];
-	
-	if (styleChanged)
-		[[NSNotificationCenter defaultCenter] postNotificationName:@"BWSplitViewDividerThicknessChanged" object:self];
-}
-
-- (void)setVertical:(BOOL)flag
-{
-	BOOL orientationChanged = NO;
-	
-	if (flag != [self isVertical])
-		orientationChanged = YES;
-		
-	[super setVertical:flag];
-	
-	if (orientationChanged)
-		[[NSNotificationCenter defaultCenter] postNotificationName:@"BWSplitViewOrientationChanged" object:self];		
 }
 
 #pragma mark IB Inspector Support Methods

BWSplitViewInspector.h

 	IBOutlet NSButton *dividerCheckbox;
 	IBOutlet BWSplitViewInspectorAutosizingView *autosizingView;
 	
-	int subviewPopupSelection, collapsiblePopupSelection, minUnitPopupSelection, maxUnitPopupSelection;
+	int subviewPopupSelection, minUnitPopupSelection, maxUnitPopupSelection;
 	NSMutableArray *subviewPopupContent, *collapsiblePopupContent;
 	
 	BWSplitView *splitView;
 	BOOL dividerCheckboxCollapsed;
 }
 
-@property int subviewPopupSelection, collapsiblePopupSelection, minUnitPopupSelection, maxUnitPopupSelection;
+@property int subviewPopupSelection, minUnitPopupSelection, maxUnitPopupSelection;
 @property (copy) NSMutableArray *subviewPopupContent, *collapsiblePopupContent;
 @property (retain) BWSplitView *splitView;
 @property BOOL dividerCheckboxCollapsed;

BWSplitViewInspector.m

 #import "NSView+BWAdditions.h"
 
 @interface BWSplitViewInspector (BWSVIPrivate)
-- (void)updateControls;
+- (void)updateSizeInputFields;
 - (BOOL)toggleDividerCheckboxVisibilityWithAnimation:(BOOL)shouldAnimate;
 - (void)updateSizeLabels;
+- (void)updateUnitPopupSelections;
 @end
 
 @implementation BWSplitViewInspector
 
-@synthesize subviewPopupSelection, subviewPopupContent, collapsiblePopupSelection, collapsiblePopupContent, minUnitPopupSelection, maxUnitPopupSelection, splitView, dividerCheckboxCollapsed;
+@synthesize subviewPopupSelection, subviewPopupContent, collapsiblePopupContent, minUnitPopupSelection, maxUnitPopupSelection, splitView, dividerCheckboxCollapsed;
 
 - (NSString *)viewNibName 
 {
 
 - (void)awakeFromNib
 {
-	[minField setDelegate:self];
-	[maxField setDelegate:self];
-	
-	[[NSNotificationCenter defaultCenter] addObserver:self 
-											 selector:@selector(dividerThicknessChanged:)
-												 name:@"BWSplitViewDividerThicknessChanged"
-											   object:splitView];
-	
-	[[NSNotificationCenter defaultCenter] addObserver:self 
-											 selector:@selector(orientationChanged:)
-												 name:@"BWSplitViewOrientationChanged"
-											   object:splitView];
-}
-
-- (void)dividerThicknessChanged:(NSNotification *)notification
-{
-	[self toggleDividerCheckboxVisibilityWithAnimation:YES];
+	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controlTextDidEndEditing:) name:NSControlTextDidEndEditingNotification object:minField];
+	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controlTextDidEndEditing:) name:NSControlTextDidEndEditingNotification object:maxField];
 }
 
 - (void)updateSizeLabels
-{
+{	
 	if ([splitView isVertical])
 	{
 		[maxLabel setStringValue:@"Max Width"];
 	}
 }
 
-- (void)orientationChanged:(NSNotification *)notification
-{
-	[self updateSizeLabels];
-	[self toggleDividerCheckboxVisibilityWithAnimation:YES];
-}
-
-- (void)setCollapsiblePopupSelection:(int)index
-{
-	collapsiblePopupSelection = index;
-	
-	[splitView setCollapsiblePopupSelection:index];
-	[self toggleDividerCheckboxVisibilityWithAnimation:YES];
-}
-
 - (void)setSplitView:(BWSplitView *)aSplitView
 {
     if (splitView != aSplitView) 
 		
 		[self toggleDividerCheckboxVisibilityWithAnimation:NO];
     }
+	else
+	{
+		[self toggleDividerCheckboxVisibilityWithAnimation:YES];
+	}
 }
 
 - (void)setDividerCheckboxWantsLayer:(NSString *)flag
 	[super refresh];
 
 	if ([[self inspectedObjects] count] > 0)
-	{
+	{	
+		[autosizingView setSplitView:[[self inspectedObjects] objectAtIndex:0]];
+		[autosizingView layoutButtons];
+
 		[self setSplitView:[[self inspectedObjects] objectAtIndex:0]];
 		
 		// Populate the subview popup button
 			[self setCollapsiblePopupContent:[NSMutableArray arrayWithObjects:@"None", @"Left Pane", @"Right Pane",nil]];
 		else
 			[self setCollapsiblePopupContent:[NSMutableArray arrayWithObjects:@"None", @"Top Pane", @"Bottom Pane",nil]];
+		
+		[self updateSizeLabels];
+		[self updateSizeInputFields];
+		[self updateUnitPopupSelections];
 	}
-	
-	// Refresh autosizing view
-	[autosizingView setSplitView:splitView];
-	[autosizingView layoutButtons];
-	
-	[self updateSizeLabels];
-	[self updateControls];
 }
 
 + (BOOL)supportsMultipleObjectInspection
 	[splitView setMaxUnits:tempMaxUnits];
 }
 
-- (void)controlTextDidChange:(NSNotification *)aNotification
+- (void)updateUnitPopupSelections
 {
-	if ([aNotification object] == minField)
-	{
+	minUnitPopupSelection = [[[splitView minUnits] objectForKey:[NSNumber numberWithInt:[self subviewPopupSelection]]] intValue];
+	maxUnitPopupSelection = [[[splitView maxUnits] objectForKey:[NSNumber numberWithInt:[self subviewPopupSelection]]] intValue];
+}
+
+- (void)controlTextDidEndEditing:(NSNotification *)aNotification
+{	
+	if ([aNotification object] == minField || aNotification == nil)
+	{	
 		if ([minField stringValue] != nil && [[minField stringValue] isEqualToString:@""] == NO && [[minField stringValue] isEqualToString:@" "] == NO)
 		{
 			NSNumber *minValue = [NSNumber numberWithInt:[minField intValue]];
 			[splitView setMinValues:tempMinValues];
 		}
 	}
-	else if ([aNotification object] == maxField)
-	{
+	
+	if ([aNotification object] == maxField || aNotification == nil)
+	{	
 		if ([maxField stringValue] != nil && [[maxField stringValue] isEqualToString:@""] == NO && [[maxField stringValue] isEqualToString:@" "] == NO)
 		{
 			NSNumber *maxValue = [NSNumber numberWithInt:[maxField intValue]];
 	}
 }
 
-- (int)collapsiblePopupSelection
-{
-	return [splitView collapsiblePopupSelection];
+- (void)setSubviewPopupSelection:(int)index
+{ 
+	// If someone types into the text field and chooses a different subview without hitting return or clicking out of the field,
+	// the controlTextDidEndEditing notification won't fire and the value won't be saved. So we fire it manually here. 
+	[self controlTextDidEndEditing:nil];
+	
+	subviewPopupSelection = index;
+	
+	// Update the input text fields with the values in the new subview
+	[self updateSizeInputFields];
 }
 
-- (void)setSubviewPopupSelection:(int)index
-{
-	subviewPopupSelection = index;
-	
-	[self updateControls];
-}
-
-- (void)updateControls
+- (void)updateSizeInputFields
 {
 	[minField setObjectValue:[[splitView minValues] objectForKey:[NSNumber numberWithInt:[self subviewPopupSelection]]]];
 	[maxField setObjectValue:[[splitView maxValues] objectForKey:[NSNumber numberWithInt:[self subviewPopupSelection]]]];

BWSplitViewInspector.xib

 <archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.10">
 	<data>
 		<int key="IBDocument.SystemTarget">1050</int>
-		<string key="IBDocument.SystemVersion">10A380</string>
-		<string key="IBDocument.InterfaceBuilderVersion">731</string>
-		<string key="IBDocument.AppKitVersion">1025.2</string>
-		<string key="IBDocument.HIToolboxVersion">427.00</string>
+		<string key="IBDocument.SystemVersion">10C540</string>
+		<string key="IBDocument.InterfaceBuilderVersion">740</string>
+		<string key="IBDocument.AppKitVersion">1038.25</string>
+		<string key="IBDocument.HIToolboxVersion">458.00</string>
 		<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
 			<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string>
-			<string key="NS.object.0">731</string>
+			<string key="NS.object.0">740</string>
 		</object>
 		<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
 			<bool key="EncodedWithXMLCoder">YES</bool>
 					<int key="connectionID">220</int>
 				</object>
 				<object class="IBConnectionRecord">
-					<object class="IBBindingConnection" key="connection">
-						<string key="label">selectedIndex: selection.collapsiblePopupSelection</string>
-						<reference key="source" ref="1021968833"/>
-						<reference key="destination" ref="764505916"/>
-						<object class="NSNibBindingConnector" key="connector">
-							<reference key="NSSource" ref="1021968833"/>
-							<reference key="NSDestination" ref="764505916"/>
-							<string key="NSLabel">selectedIndex: selection.collapsiblePopupSelection</string>
-							<string key="NSBinding">selectedIndex</string>
-							<string key="NSKeyPath">selection.collapsiblePopupSelection</string>
-							<reference key="NSPreviousConnector" ref="763085578"/>
-							<int key="NSNibBindingConnectorVersion">2</int>
-						</object>
-					</object>
-					<int key="connectionID">222</int>
-				</object>
-				<object class="IBConnectionRecord">
 					<object class="IBOutletConnection" key="connection">
 						<string key="label">maxField</string>
 						<reference key="source" ref="762632889"/>
 					</object>
 					<int key="connectionID">231</int>
 				</object>
+				<object class="IBConnectionRecord">
+					<object class="IBBindingConnection" key="connection">
+						<string key="label">selectedIndex: inspectedObjectsController.selection.collapsiblePopupSelection</string>
+						<reference key="source" ref="1021968833"/>
+						<reference key="destination" ref="762632889"/>
+						<object class="NSNibBindingConnector" key="connector">
+							<reference key="NSSource" ref="1021968833"/>
+							<reference key="NSDestination" ref="762632889"/>
+							<string key="NSLabel">selectedIndex: inspectedObjectsController.selection.collapsiblePopupSelection</string>
+							<string key="NSBinding">selectedIndex</string>
+							<string key="NSKeyPath">inspectedObjectsController.selection.collapsiblePopupSelection</string>
+							<reference key="NSPreviousConnector" ref="763085578"/>
+							<int key="NSNibBindingConnectorVersion">2</int>
+						</object>
+					</object>
+					<int key="connectionID">233</int>
+				</object>
 			</object>
 			<object class="IBMutableOrderedSet" key="objectRecords">
 				<object class="NSArray" key="orderedObjects">
 				</object>
 			</object>
 			<nil key="sourceID"/>
-			<int key="maxID">231</int>
+			<int key="maxID">233</int>
 		</object>
 		<object class="IBClassDescriber" key="IBDocument.Classes">
 			<object class="NSMutableArray" key="referencedPartialClassDescriptions">
 			<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.macosx</string>
 			<integer value="1050" key="NS.object.0"/>
 		</object>
-		<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencyDefaults">
-			<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.macosx</string>
-			<integer value="1050" key="NS.object.0"/>
-		</object>
 		<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies">
 			<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3</string>
 			<integer value="3000" key="NS.object.0"/>

BWSplitViewIntegration.m

 - (void)ibPopulateKeyPaths:(NSMutableDictionary *)keyPaths {
     [super ibPopulateKeyPaths:keyPaths];
 
-    [[keyPaths objectForKey:IBAttributeKeyPaths] addObjectsFromArray:[NSArray arrayWithObjects:@"color",@"colorIsEnabled",@"dividerCanCollapse",nil]];
+    [[keyPaths objectForKey:IBAttributeKeyPaths] addObjectsFromArray:[NSArray arrayWithObjects:@"color",@"colorIsEnabled",@"dividerCanCollapse",@"collapsiblePopupSelection",@"minValues",@"maxValues",@"minUnits",@"maxUnits",nil]];
 }
 
 - (void)ibPopulateAttributeInspectorClasses:(NSMutableArray *)classes {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.