Skip to content

Commit b41da9e

Browse files
committed
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.
1 parent c545832 commit b41da9e

File tree

3 files changed

+106
-5
lines changed

3 files changed

+106
-5
lines changed

GLFileView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
NSMutableArray *groups;
2222
NSString *logFormat;
2323
IBOutlet NSView *accessoryView;
24+
IBOutlet NSSplitView *fileListSplitView;
2425
}
2526

2627
- (void)showFile;

GLFileView.m

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
#define ITEM_IDENTIFIER @"Identifier" // string
1717
#define ITEM_NAME @"Name" // string
1818

19+
20+
@interface GLFileView ()
21+
22+
- (void)saveSplitViewPosition;
23+
24+
@end
25+
26+
1927
@implementation GLFileView
2028

2129
- (void) awakeFromNib
@@ -52,6 +60,9 @@ - (void) awakeFromNib
5260
items, GROUP_ITEMS,
5361
nil]];
5462
[typeBar reloadData];
63+
64+
[fileListSplitView setHidden:YES];
65+
[self performSelector:@selector(restoreSplitViewPositiion) withObject:nil afterDelay:0];
5566
}
5667

5768
- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
@@ -154,6 +165,7 @@ - (void) didLoad
154165
- (void)closeView
155166
{
156167
[historyController.treeController removeObserver:self forKeyPath:@"selection"];
168+
[self saveSplitViewPosition];
157169

158170
[super closeView];
159171
}
@@ -241,6 +253,71 @@ - (NSString *) parseBlame:(NSString *)txt
241253
return (NSString *)res;
242254
}
243255

256+
257+
258+
#pragma mark NSSplitView delegate methods
259+
260+
#define kFileListSplitViewLeftMin 120
261+
#define kFileListSplitViewRightMin 180
262+
#define kHFileListSplitViewPositionDefault @"File List SplitView Position"
263+
264+
- (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMin ofSubviewAt:(NSInteger)dividerIndex
265+
{
266+
return kFileListSplitViewLeftMin;
267+
}
268+
269+
- (CGFloat)splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMax ofSubviewAt:(NSInteger)dividerIndex
270+
{
271+
return [splitView frame].size.width - [splitView dividerThickness] - kFileListSplitViewRightMin;
272+
}
273+
274+
// while the user resizes the window keep the left (file list) view constant and just resize the right view
275+
// unless the right view gets too small
276+
- (void)splitView:(NSSplitView *)splitView resizeSubviewsWithOldSize:(NSSize)oldSize
277+
{
278+
NSRect newFrame = [splitView frame];
279+
280+
float dividerThickness = [splitView dividerThickness];
281+
282+
NSView *leftView = [[splitView subviews] objectAtIndex:0];
283+
NSRect leftFrame = [leftView frame];
284+
leftFrame.size.height = newFrame.size.height;
285+
286+
if ((newFrame.size.width - leftFrame.size.width - dividerThickness) < kFileListSplitViewRightMin) {
287+
leftFrame.size.width = newFrame.size.width - kFileListSplitViewRightMin - dividerThickness;
288+
}
289+
290+
NSView *rightView = [[splitView subviews] objectAtIndex:1];
291+
NSRect rightFrame = [rightView frame];
292+
rightFrame.origin.x = leftFrame.size.width + dividerThickness;
293+
rightFrame.size.width = newFrame.size.width - rightFrame.origin.x;
294+
rightFrame.size.height = newFrame.size.height;
295+
296+
[leftView setFrame:leftFrame];
297+
[rightView setFrame:rightFrame];
298+
}
299+
300+
// NSSplitView does not save and restore the position of the SplitView correctly so do it manually
301+
- (void)saveSplitViewPosition
302+
{
303+
float position = [[[fileListSplitView subviews] objectAtIndex:0] frame].size.width;
304+
[[NSUserDefaults standardUserDefaults] setFloat:position forKey:kHFileListSplitViewPositionDefault];
305+
[[NSUserDefaults standardUserDefaults] synchronize];
306+
}
307+
308+
// make sure this happens after awakeFromNib
309+
- (void)restoreSplitViewPositiion
310+
{
311+
float position = [[NSUserDefaults standardUserDefaults] floatForKey:kHFileListSplitViewPositionDefault];
312+
if (position < 1.0)
313+
position = 200;
314+
315+
[fileListSplitView setPosition:position ofDividerAtIndex:0];
316+
[fileListSplitView setHidden:NO];
317+
}
318+
319+
320+
244321
@synthesize groups;
245322
@synthesize logFormat;
246323

PBGitHistoryView.xib

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</object>
2222
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
2323
<bool key="EncodedWithXMLCoder">YES</bool>
24-
<integer value="486"/>
24+
<integer value="475"/>
2525
</object>
2626
<object class="NSArray" key="IBDocument.PluginDependencies">
2727
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -1074,7 +1074,7 @@
10741074
</object>
10751075
<object class="NSCustomView" id="891500945">
10761076
<reference key="NSNextResponder" ref="626906425"/>
1077-
<int key="NSvFlags">268</int>
1077+
<int key="NSvFlags">274</int>
10781078
<object class="NSMutableArray" key="NSSubviews">
10791079
<bool key="EncodedWithXMLCoder">YES</bool>
10801080
<object class="NSCustomView" id="375746871">
@@ -1084,7 +1084,7 @@
10841084
<bool key="EncodedWithXMLCoder">YES</bool>
10851085
<object class="NSCustomView" id="951933530">
10861086
<reference key="NSNextResponder" ref="375746871"/>
1087-
<int key="NSvFlags">268</int>
1087+
<int key="NSvFlags">265</int>
10881088
<object class="NSMutableArray" key="NSSubviews">
10891089
<bool key="EncodedWithXMLCoder">YES</bool>
10901090
<object class="NSButton" id="16222431">
@@ -1984,6 +1984,22 @@
19841984
</object>
19851985
<int key="connectionID">488</int>
19861986
</object>
1987+
<object class="IBConnectionRecord">
1988+
<object class="IBOutletConnection" key="connection">
1989+
<string key="label">fileListSplitView</string>
1990+
<reference key="source" ref="932676109"/>
1991+
<reference key="destination" ref="626906425"/>
1992+
</object>
1993+
<int key="connectionID">489</int>
1994+
</object>
1995+
<object class="IBConnectionRecord">
1996+
<object class="IBOutletConnection" key="connection">
1997+
<string key="label">delegate</string>
1998+
<reference key="source" ref="626906425"/>
1999+
<reference key="destination" ref="932676109"/>
2000+
</object>
2001+
<int key="connectionID">490</int>
2002+
</object>
19872003
</object>
19882004
<object class="IBMutableOrderedSet" key="objectRecords">
19892005
<object class="NSArray" key="orderedObjects">
@@ -2894,7 +2910,7 @@
28942910
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
28952911
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
28962912
<string>com.apple.WebKitIBPlugin</string>
2897-
<string>{{1559, 241}, {955, 434}}</string>
2913+
<string>{{1084, 241}, {955, 434}}</string>
28982914
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
28992915
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
29002916
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -2932,7 +2948,7 @@
29322948
</object>
29332949
</object>
29342950
<nil key="sourceID"/>
2935-
<int key="maxID">488</int>
2951+
<int key="maxID">490</int>
29362952
</object>
29372953
<object class="IBClassDescriber" key="IBDocument.Classes">
29382954
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -2945,12 +2961,14 @@
29452961
<object class="NSArray" key="dict.sortedKeys">
29462962
<bool key="EncodedWithXMLCoder">YES</bool>
29472963
<string>accessoryView</string>
2964+
<string>fileListSplitView</string>
29482965
<string>historyController</string>
29492966
<string>typeBar</string>
29502967
</object>
29512968
<object class="NSMutableArray" key="dict.values">
29522969
<bool key="EncodedWithXMLCoder">YES</bool>
29532970
<string>NSView</string>
2971+
<string>NSSplitView</string>
29542972
<string>PBGitHistoryController</string>
29552973
<string>MGScopeBar</string>
29562974
</object>
@@ -2960,6 +2978,7 @@
29602978
<object class="NSArray" key="dict.sortedKeys">
29612979
<bool key="EncodedWithXMLCoder">YES</bool>
29622980
<string>accessoryView</string>
2981+
<string>fileListSplitView</string>
29632982
<string>historyController</string>
29642983
<string>typeBar</string>
29652984
</object>
@@ -2969,6 +2988,10 @@
29692988
<string key="name">accessoryView</string>
29702989
<string key="candidateClassName">NSView</string>
29712990
</object>
2991+
<object class="IBToOneOutletInfo">
2992+
<string key="name">fileListSplitView</string>
2993+
<string key="candidateClassName">NSSplitView</string>
2994+
</object>
29722995
<object class="IBToOneOutletInfo">
29732996
<string key="name">historyController</string>
29742997
<string key="candidateClassName">PBGitHistoryController</string>

0 commit comments

Comments
 (0)