Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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.
  • Loading branch information...
commit b11d4f748538d68acaf4270ca69710386a64b50a 1 parent 621b4e6
Nathan Kinsinger brotherbard authored

Showing 2 changed files with 66 additions and 22 deletions. Show diff stats Hide diff stats

  1. +66 21 PBGitHistoryController.m
  2. +0 1  PBGitHistoryView.xib
87 PBGitHistoryController.m
@@ -30,11 +30,14 @@
30 30 #define kHistoryDetailViewIndex 0
31 31 #define kHistoryTreeViewIndex 1
32 32
  33 +#define kHistorySplitViewPositionDefault @"History SplitView Position"
  34 +
33 35 @interface PBGitHistoryController ()
34 36
35 37 - (void) updateBranchFilterMatrix;
36 38 - (void) restoreFileBrowserSelection;
37 39 - (void) saveFileBrowserSelection;
  40 +- (void)saveSplitViewPosition;
38 41
39 42 @end
40 43
@@ -77,13 +80,14 @@ - (void)awakeFromNib
77 80 [[commitList tableColumnWithIdentifier:@"SubjectColumn"] setSortDescriptorPrototype:[[NSSortDescriptor alloc] initWithKey:@"subject" ascending:YES]];
78 81 // Add a menu that allows a user to select which columns to view
79 82 [[commitList headerView] setMenu:[self tableColumnMenu]];
  83 +
80 84 [historySplitView setTopMin:58.0 andBottomMin:100.0];
81   - [historySplitView uncollapse];
  85 + [historySplitView setHidden:YES];
  86 + [self performSelector:@selector(restoreSplitViewPositiion) withObject:nil afterDelay:0];
82 87
83 88 [upperToolbarView setTopShade:237/255.0 bottomShade:216/255.0];
84 89 [scopeBarView setTopColor:[NSColor colorWithCalibratedHue:0.579 saturation:0.068 brightness:0.898 alpha:1.000]
85 90 bottomColor:[NSColor colorWithCalibratedHue:0.579 saturation:0.119 brightness:0.765 alpha:1.000]];
86   - //[scopeBarView setTopShade:207/255.0 bottomShade:180/255.0];
87 91 [self updateBranchFilterMatrix];
88 92
89 93 [super awakeFromNib];
@@ -419,13 +423,6 @@ - (void) updateView
419 423 [self updateKeys];
420 424 }
421 425
422   -- (void)viewLoaded
423   -{
424   - float position = [[NSUserDefaults standardUserDefaults] floatForKey:@"PBGitSplitViewPosition"];
425   - if (position)
426   - [historySplitView setPosition:position ofDividerAtIndex:0];
427   -}
428   -
429 426 - (NSResponder *)firstResponder;
430 427 {
431 428 return commitList;
@@ -488,9 +485,7 @@ - (BOOL) hasNonlinearPath
488 485
489 486 - (void)closeView
490 487 {
491   - float position = [[[historySplitView subviews] objectAtIndex:0] frame].size.height;
492   - [[NSUserDefaults standardUserDefaults] setFloat:position forKey:@"PBGitSplitViewPosition"];
493   - [[NSUserDefaults standardUserDefaults] synchronize];
  488 + [self saveSplitViewPosition];
494 489
495 490 if (commitController) {
496 491 [commitController removeObserver:self forKeyPath:@"selection"];
@@ -620,12 +615,17 @@ - (NSArray *)menuItemsForPaths:(NSArray *)paths
620 615 return menuItems;
621 616 }
622 617
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 +{
624 623 return TRUE;
625 624 }
626 625
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];
629 629 // this method (and canCollapse) are called by the splitView to decide how to collapse on double-click
630 630 // we compare our two subviews, so that always the smaller one is collapsed.
631 631 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
634 634 return FALSE;
635 635 }
636 636
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;
639 645 }
640 646
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];
645 690 }
646 691
647 692
1  PBGitHistoryView.xib
@@ -1197,7 +1197,6 @@
1197 1197 <string key="NSFrameSize">{955, 405}</string>
1198 1198 <reference key="NSSuperview" ref="319362431"/>
1199 1199 <int key="NSDividerStyle">2</int>
1200   - <string key="NSAutosaveName">HistoryViewSplitView</string>
1201 1200 </object>
1202 1201 </object>
1203 1202 <string key="NSFrameSize">{955, 434}</string>

0 comments on commit b11d4f7

Please sign in to comment.
Something went wrong with that request. Please try again.