Skip to content

Commit b11d4f7

Browse files
committed
Fix the history view's horizontal split view
Save the position correctly (it wasn't saving before). Restore the position sometime after awakeFromNib otherwise the superview's size will not have been set yet. Also constrain the divider from moving unless the lower view is too small.
1 parent 621b4e6 commit b11d4f7

File tree

2 files changed

+66
-22
lines changed

2 files changed

+66
-22
lines changed

PBGitHistoryController.m

+66-21
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@
3030
#define kHistoryDetailViewIndex 0
3131
#define kHistoryTreeViewIndex 1
3232

33+
#define kHistorySplitViewPositionDefault @"History SplitView Position"
34+
3335
@interface PBGitHistoryController ()
3436

3537
- (void) updateBranchFilterMatrix;
3638
- (void) restoreFileBrowserSelection;
3739
- (void) saveFileBrowserSelection;
40+
- (void)saveSplitViewPosition;
3841

3942
@end
4043

@@ -77,13 +80,14 @@ - (void)awakeFromNib
7780
[[commitList tableColumnWithIdentifier:@"SubjectColumn"] setSortDescriptorPrototype:[[NSSortDescriptor alloc] initWithKey:@"subject" ascending:YES]];
7881
// Add a menu that allows a user to select which columns to view
7982
[[commitList headerView] setMenu:[self tableColumnMenu]];
83+
8084
[historySplitView setTopMin:58.0 andBottomMin:100.0];
81-
[historySplitView uncollapse];
85+
[historySplitView setHidden:YES];
86+
[self performSelector:@selector(restoreSplitViewPositiion) withObject:nil afterDelay:0];
8287

8388
[upperToolbarView setTopShade:237/255.0 bottomShade:216/255.0];
8489
[scopeBarView setTopColor:[NSColor colorWithCalibratedHue:0.579 saturation:0.068 brightness:0.898 alpha:1.000]
8590
bottomColor:[NSColor colorWithCalibratedHue:0.579 saturation:0.119 brightness:0.765 alpha:1.000]];
86-
//[scopeBarView setTopShade:207/255.0 bottomShade:180/255.0];
8791
[self updateBranchFilterMatrix];
8892

8993
[super awakeFromNib];
@@ -419,13 +423,6 @@ - (void) updateView
419423
[self updateKeys];
420424
}
421425

422-
- (void)viewLoaded
423-
{
424-
float position = [[NSUserDefaults standardUserDefaults] floatForKey:@"PBGitSplitViewPosition"];
425-
if (position)
426-
[historySplitView setPosition:position ofDividerAtIndex:0];
427-
}
428-
429426
- (NSResponder *)firstResponder;
430427
{
431428
return commitList;
@@ -488,9 +485,7 @@ - (BOOL) hasNonlinearPath
488485

489486
- (void)closeView
490487
{
491-
float position = [[[historySplitView subviews] objectAtIndex:0] frame].size.height;
492-
[[NSUserDefaults standardUserDefaults] setFloat:position forKey:@"PBGitSplitViewPosition"];
493-
[[NSUserDefaults standardUserDefaults] synchronize];
488+
[self saveSplitViewPosition];
494489

495490
if (commitController) {
496491
[commitController removeObserver:self forKeyPath:@"selection"];
@@ -620,12 +615,17 @@ - (NSArray *)menuItemsForPaths:(NSArray *)paths
620615
return menuItems;
621616
}
622617

623-
- (BOOL)splitView:(NSSplitView *)sender canCollapseSubview:(NSView *)subview {
618+
619+
#pragma mark NSSplitView delegate methods
620+
621+
- (BOOL)splitView:(NSSplitView *)splitView canCollapseSubview:(NSView *)subview
622+
{
624623
return TRUE;
625624
}
626625

627-
- (BOOL)splitView:(NSSplitView *)splitView shouldCollapseSubview:(NSView *)subview forDoubleClickOnDividerAtIndex:(NSInteger)dividerIndex {
628-
int index = [[splitView subviews] indexOfObject:subview];
626+
- (BOOL)splitView:(NSSplitView *)splitView shouldCollapseSubview:(NSView *)subview forDoubleClickOnDividerAtIndex:(NSInteger)dividerIndex
627+
{
628+
NSUInteger index = [[splitView subviews] indexOfObject:subview];
629629
// this method (and canCollapse) are called by the splitView to decide how to collapse on double-click
630630
// we compare our two subviews, so that always the smaller one is collapsed.
631631
if([[[splitView subviews] objectAtIndex:index] frame].size.height < [[[splitView subviews] objectAtIndex:((index+1)%2)] frame].size.height) {
@@ -634,14 +634,59 @@ - (BOOL)splitView:(NSSplitView *)splitView shouldCollapseSubview:(NSView *)subvi
634634
return FALSE;
635635
}
636636

637-
- (CGFloat)splitView:(NSSplitView *)sender constrainMinCoordinate:(CGFloat)proposedMin ofSubviewAt:(NSInteger)offset {
638-
return proposedMin + historySplitView.topViewMin;
637+
- (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMin ofSubviewAt:(NSInteger)dividerIndex
638+
{
639+
return historySplitView.topViewMin;
640+
}
641+
642+
- (CGFloat)splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMax ofSubviewAt:(NSInteger)dividerIndex
643+
{
644+
return [splitView frame].size.height - [splitView dividerThickness] - historySplitView.bottomViewMin;
639645
}
640646

641-
- (CGFloat)splitView:(NSSplitView *)sender constrainMaxCoordinate:(CGFloat)proposedMax ofSubviewAt:(NSInteger)offset {
642-
if(offset == 1)
643-
return proposedMax - historySplitView.bottomViewMin;
644-
return [sender frame].size.height;
647+
// while the user resizes the window keep the upper (history) view constant and just resize the lower view
648+
// unless the lower view gets too small
649+
- (void)splitView:(NSSplitView *)splitView resizeSubviewsWithOldSize:(NSSize)oldSize
650+
{
651+
NSRect newFrame = [splitView frame];
652+
653+
float dividerThickness = [splitView dividerThickness];
654+
655+
NSView *upperView = [[splitView subviews] objectAtIndex:0];
656+
NSRect upperFrame = [upperView frame];
657+
upperFrame.size.width = newFrame.size.width;
658+
659+
if ((newFrame.size.height - upperFrame.size.height - dividerThickness) < historySplitView.bottomViewMin) {
660+
upperFrame.size.height = newFrame.size.height - historySplitView.bottomViewMin - dividerThickness;
661+
}
662+
663+
NSView *lowerView = [[splitView subviews] objectAtIndex:1];
664+
NSRect lowerFrame = [lowerView frame];
665+
lowerFrame.origin.y = upperFrame.size.height + dividerThickness;
666+
lowerFrame.size.height = newFrame.size.height - lowerFrame.origin.y;
667+
lowerFrame.size.width = newFrame.size.width;
668+
669+
[upperView setFrame:upperFrame];
670+
[lowerView setFrame:lowerFrame];
671+
}
672+
673+
// NSSplitView does not save and restore the position of the SplitView correctly so do it manually
674+
- (void)saveSplitViewPosition
675+
{
676+
float position = [[[historySplitView subviews] objectAtIndex:0] frame].size.height;
677+
[[NSUserDefaults standardUserDefaults] setFloat:position forKey:kHistorySplitViewPositionDefault];
678+
[[NSUserDefaults standardUserDefaults] synchronize];
679+
}
680+
681+
// make sure this happens after awakeFromNib
682+
- (void)restoreSplitViewPositiion
683+
{
684+
float position = [[NSUserDefaults standardUserDefaults] floatForKey:kHistorySplitViewPositionDefault];
685+
if (position < 1.0)
686+
position = 175;
687+
688+
[historySplitView setPosition:position ofDividerAtIndex:0];
689+
[historySplitView setHidden:NO];
645690
}
646691

647692

PBGitHistoryView.xib

-1
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,6 @@
11971197
<string key="NSFrameSize">{955, 405}</string>
11981198
<reference key="NSSuperview" ref="319362431"/>
11991199
<int key="NSDividerStyle">2</int>
1200-
<string key="NSAutosaveName">HistoryViewSplitView</string>
12011200
</object>
12021201
</object>
12031202
<string key="NSFrameSize">{955, 434}</string>

0 commit comments

Comments
 (0)