Skip to content

Commit

Permalink
Split view - Implemented design-time undo support and fixed document …
Browse files Browse the repository at this point in the history
…dirtying
  • Loading branch information
Brandon Walkin committed Dec 21, 2009
1 parent 0911f64 commit a481440
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 111 deletions.
26 changes: 0 additions & 26 deletions BWSplitView.m
Expand Up @@ -1340,38 +1340,12 @@ - (void)splitView:(NSSplitView *)sender resizeSubviewsWithOldSize:(NSSize)oldSiz
}
}

#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
Expand Down
4 changes: 2 additions & 2 deletions BWSplitViewInspector.h
Expand Up @@ -16,14 +16,14 @@
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;
Expand Down
93 changes: 38 additions & 55 deletions BWSplitViewInspector.m
Expand Up @@ -10,14 +10,15 @@
#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
{
Expand All @@ -26,27 +27,12 @@ - (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"];
Expand All @@ -59,20 +45,6 @@ - (void)updateSizeLabels
}
}

- (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)
Expand All @@ -82,6 +54,10 @@ - (void)setSplitView:(BWSplitView *)aSplitView

[self toggleDividerCheckboxVisibilityWithAnimation:NO];
}
else
{
[self toggleDividerCheckboxVisibilityWithAnimation:YES];
}
}

- (void)setDividerCheckboxWantsLayer:(NSString *)flag
Expand Down Expand Up @@ -148,7 +124,10 @@ - (void)refresh
[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
Expand All @@ -172,14 +151,11 @@ - (void)refresh
[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
Expand Down Expand Up @@ -209,10 +185,16 @@ - (void)setMaxUnitPopupSelection:(int)index
[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]];
Expand All @@ -227,8 +209,9 @@ - (void)controlTextDidChange:(NSNotification *)aNotification
[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]];
Expand All @@ -245,19 +228,19 @@ - (void)controlTextDidChange:(NSNotification *)aNotification
}
}

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

[self updateControls];
// Update the input text fields with the values in the new subview
[self updateSizeInputFields];
}

- (void)updateControls
- (void)updateSizeInputFields
{
[minField setObjectValue:[[splitView minValues] objectForKey:[NSNumber numberWithInt:[self subviewPopupSelection]]]];
[maxField setObjectValue:[[splitView maxValues] objectForKey:[NSNumber numberWithInt:[self subviewPopupSelection]]]];
Expand Down
50 changes: 23 additions & 27 deletions BWSplitViewInspector.xib
Expand Up @@ -2,13 +2,13 @@
<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>
Expand Down Expand Up @@ -780,23 +780,6 @@
</object>
<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>
Expand Down Expand Up @@ -877,6 +860,23 @@
</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">
Expand Down Expand Up @@ -1480,7 +1480,7 @@
</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">
Expand Down Expand Up @@ -2065,10 +2065,6 @@
<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"/>
Expand Down
2 changes: 1 addition & 1 deletion BWSplitViewIntegration.m
Expand Up @@ -15,7 +15,7 @@ @implementation BWSplitView ( BWSplitViewIntegration )
- (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 {
Expand Down

0 comments on commit a481440

Please sign in to comment.