Skip to content

Commit

Permalink
Fix the Stage view's horizontal split view
Browse files Browse the repository at this point in the history
It will now remember it's position and the divider will keep its position relative to the bottom when the window resizes.
  • Loading branch information
brotherbard committed Nov 18, 2010
1 parent b11d4f7 commit c545832
Show file tree
Hide file tree
Showing 3 changed files with 400 additions and 9 deletions.
2 changes: 2 additions & 0 deletions PBGitCommitController.h
Expand Up @@ -10,6 +10,7 @@
#import "PBViewController.h"

@class PBGitIndexController, PBIconAndTextCell, PBWebChangesController, PBGitIndex;
@class PBNiceSplitView;

@interface PBGitCommitController : PBViewController {
// This might have to transfer over to the PBGitRepository
Expand All @@ -23,6 +24,7 @@

IBOutlet PBGitIndexController *indexController;
IBOutlet PBWebChangesController *webController;
IBOutlet PBNiceSplitView *commitSplitView;
}

@property(readonly) PBGitIndex *index;
Expand Down
83 changes: 83 additions & 0 deletions PBGitCommitController.m
Expand Up @@ -11,6 +11,10 @@
#import "PBChangedFile.h"
#import "PBWebChangesController.h"
#import "PBGitIndex.h"
#import "PBNiceSplitView.h"


#define kCommitSplitViewPositionDefault @"Commit SplitView Position"

@interface PBGitCommitController ()
- (void)refreshFinished:(NSNotification *)notification;
Expand All @@ -22,6 +26,7 @@ - (void)commitHookFailed:(NSNotification *)notification;
- (void)amendCommit:(NSNotification *)notification;
- (void)indexChanged:(NSNotification *)notification;
- (void)indexOperationFailed:(NSNotification *)notification;
- (void)saveCommitSplitViewPosition;
@end

@implementation PBGitCommitController
Expand Down Expand Up @@ -65,10 +70,14 @@ - (void)awakeFromNib

[cachedFilesController setAutomaticallyRearrangesObjects:NO];
[unstagedFilesController setAutomaticallyRearrangesObjects:NO];

[commitSplitView setHidden:YES];
[self performSelector:@selector(restoreCommitSplitViewPositiion) withObject:nil afterDelay:0];
}

- (void)closeView
{
[self saveCommitSplitViewPosition];
[webController closeView];
}

Expand Down Expand Up @@ -211,4 +220,78 @@ - (void)indexOperationFailed:(NSNotification *)notification
[[repository windowController] showMessageSheet:@"Index operation failed" infoText:[[notification userInfo] objectForKey:@"description"]];
}


#pragma mark NSSplitView delegate methods

#define kCommitSplitViewTopViewMin 150
#define kCommitSplitViewBottomViewMin 100

- (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMin ofSubviewAt:(NSInteger)dividerIndex
{
if (splitView == commitSplitView)
return kCommitSplitViewTopViewMin;

return proposedMin;
}

- (CGFloat)splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMax ofSubviewAt:(NSInteger)dividerIndex
{
if (splitView == commitSplitView)
return [splitView frame].size.height - [splitView dividerThickness] - kCommitSplitViewBottomViewMin;

return proposedMax;
}

// while the user resizes the window keep the lower (changes/message) view constant and just resize the upper view
// unless the upper view gets too small
- (void)resizeCommitSplitView
{
NSRect newFrame = [commitSplitView frame];

float dividerThickness = [commitSplitView dividerThickness];

NSView *upperView = [[commitSplitView subviews] objectAtIndex:0];
NSRect upperFrame = [upperView frame];
upperFrame.size.width = newFrame.size.width;

NSView *lowerView = [[commitSplitView subviews] objectAtIndex:1];
NSRect lowerFrame = [lowerView frame];
lowerFrame.size.width = newFrame.size.width;

upperFrame.size.height = newFrame.size.height - lowerFrame.size.height - dividerThickness;
if (upperFrame.size.height < kCommitSplitViewTopViewMin)
upperFrame.size.height = kCommitSplitViewTopViewMin;

lowerFrame.size.height = newFrame.size.height - upperFrame.size.height - dividerThickness;
lowerFrame.origin.y = newFrame.size.height - lowerFrame.size.height;

[upperView setFrame:upperFrame];
[lowerView setFrame:lowerFrame];
}

- (void)splitView:(NSSplitView *)splitView resizeSubviewsWithOldSize:(NSSize)oldSize
{
if (splitView == commitSplitView)
[self resizeCommitSplitView];
}

// NSSplitView does not save and restore the position of the splitView correctly so do it manually
- (void)saveCommitSplitViewPosition
{
float position = [[[commitSplitView subviews] objectAtIndex:0] frame].size.height;
[[NSUserDefaults standardUserDefaults] setFloat:position forKey:kCommitSplitViewPositionDefault];
[[NSUserDefaults standardUserDefaults] synchronize];
}

// make sure this happens after awakeFromNib
- (void)restoreCommitSplitViewPositiion
{
float position = [[NSUserDefaults standardUserDefaults] floatForKey:kCommitSplitViewPositionDefault];
if (position < 1.0)
position = [commitSplitView frame].size.height - 225;

[commitSplitView setPosition:position ofDividerAtIndex:0];
[commitSplitView setHidden:NO];
}

@end

0 comments on commit c545832

Please sign in to comment.