Fix the File/Tree view's vertical split view

It will now remember it's position and the divider will not move when the window resizes.
This commit is contained in:
Nathan Kinsinger
2010-11-17 15:36:14 -07:00
parent c545832108
commit b41da9e23e
3 changed files with 106 additions and 5 deletions
+1
View File
@@ -21,6 +21,7 @@
NSMutableArray *groups;
NSString *logFormat;
IBOutlet NSView *accessoryView;
IBOutlet NSSplitView *fileListSplitView;
}
- (void)showFile;
+77
View File
@@ -16,6 +16,14 @@
#define ITEM_IDENTIFIER @"Identifier" // string
#define ITEM_NAME @"Name" // string
@interface GLFileView ()
- (void)saveSplitViewPosition;
@end
@implementation GLFileView
- (void) awakeFromNib
@@ -52,6 +60,9 @@
items, GROUP_ITEMS,
nil]];
[typeBar reloadData];
[fileListSplitView setHidden:YES];
[self performSelector:@selector(restoreSplitViewPositiion) withObject:nil afterDelay:0];
}
- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
@@ -154,6 +165,7 @@
- (void)closeView
{
[historyController.treeController removeObserver:self forKeyPath:@"selection"];
[self saveSplitViewPosition];
[super closeView];
}
@@ -241,6 +253,71 @@
return (NSString *)res;
}
#pragma mark NSSplitView delegate methods
#define kFileListSplitViewLeftMin 120
#define kFileListSplitViewRightMin 180
#define kHFileListSplitViewPositionDefault @"File List SplitView Position"
- (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMin ofSubviewAt:(NSInteger)dividerIndex
{
return kFileListSplitViewLeftMin;
}
- (CGFloat)splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMax ofSubviewAt:(NSInteger)dividerIndex
{
return [splitView frame].size.width - [splitView dividerThickness] - kFileListSplitViewRightMin;
}
// while the user resizes the window keep the left (file list) view constant and just resize the right view
// unless the right view gets too small
- (void)splitView:(NSSplitView *)splitView resizeSubviewsWithOldSize:(NSSize)oldSize
{
NSRect newFrame = [splitView frame];
float dividerThickness = [splitView dividerThickness];
NSView *leftView = [[splitView subviews] objectAtIndex:0];
NSRect leftFrame = [leftView frame];
leftFrame.size.height = newFrame.size.height;
if ((newFrame.size.width - leftFrame.size.width - dividerThickness) < kFileListSplitViewRightMin) {
leftFrame.size.width = newFrame.size.width - kFileListSplitViewRightMin - dividerThickness;
}
NSView *rightView = [[splitView subviews] objectAtIndex:1];
NSRect rightFrame = [rightView frame];
rightFrame.origin.x = leftFrame.size.width + dividerThickness;
rightFrame.size.width = newFrame.size.width - rightFrame.origin.x;
rightFrame.size.height = newFrame.size.height;
[leftView setFrame:leftFrame];
[rightView setFrame:rightFrame];
}
// NSSplitView does not save and restore the position of the SplitView correctly so do it manually
- (void)saveSplitViewPosition
{
float position = [[[fileListSplitView subviews] objectAtIndex:0] frame].size.width;
[[NSUserDefaults standardUserDefaults] setFloat:position forKey:kHFileListSplitViewPositionDefault];
[[NSUserDefaults standardUserDefaults] synchronize];
}
// make sure this happens after awakeFromNib
- (void)restoreSplitViewPositiion
{
float position = [[NSUserDefaults standardUserDefaults] floatForKey:kHFileListSplitViewPositionDefault];
if (position < 1.0)
position = 200;
[fileListSplitView setPosition:position ofDividerAtIndex:0];
[fileListSplitView setHidden:NO];
}
@synthesize groups;
@synthesize logFormat;
+28 -5
View File
@@ -21,7 +21,7 @@
</object>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
<integer value="486"/>
<integer value="475"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -1074,7 +1074,7 @@
</object>
<object class="NSCustomView" id="891500945">
<reference key="NSNextResponder" ref="626906425"/>
<int key="NSvFlags">268</int>
<int key="NSvFlags">274</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSCustomView" id="375746871">
@@ -1084,7 +1084,7 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSCustomView" id="951933530">
<reference key="NSNextResponder" ref="375746871"/>
<int key="NSvFlags">268</int>
<int key="NSvFlags">265</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSButton" id="16222431">
@@ -1984,6 +1984,22 @@
</object>
<int key="connectionID">488</int>
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">fileListSplitView</string>
<reference key="source" ref="932676109"/>
<reference key="destination" ref="626906425"/>
</object>
<int key="connectionID">489</int>
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">delegate</string>
<reference key="source" ref="626906425"/>
<reference key="destination" ref="932676109"/>
</object>
<int key="connectionID">490</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -2894,7 +2910,7 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.WebKitIBPlugin</string>
<string>{{1559, 241}, {955, 434}}</string>
<string>{{1084, 241}, {955, 434}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -2932,7 +2948,7 @@
</object>
</object>
<nil key="sourceID"/>
<int key="maxID">488</int>
<int key="maxID">490</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -2945,12 +2961,14 @@
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>accessoryView</string>
<string>fileListSplitView</string>
<string>historyController</string>
<string>typeBar</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>NSView</string>
<string>NSSplitView</string>
<string>PBGitHistoryController</string>
<string>MGScopeBar</string>
</object>
@@ -2960,6 +2978,7 @@
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>accessoryView</string>
<string>fileListSplitView</string>
<string>historyController</string>
<string>typeBar</string>
</object>
@@ -2969,6 +2988,10 @@
<string key="name">accessoryView</string>
<string key="candidateClassName">NSView</string>
</object>
<object class="IBToOneOutletInfo">
<string key="name">fileListSplitView</string>
<string key="candidateClassName">NSSplitView</string>
</object>
<object class="IBToOneOutletInfo">
<string key="name">historyController</string>
<string key="candidateClassName">PBGitHistoryController</string>