Permalink
Browse files

Fix the Stage view's horizontal split view

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...
1 parent b11d4f7 commit c545832108c2a95f97ac8173f7fd9894b45a20d8 @brotherbard committed Nov 15, 2010
Showing with 400 additions and 9 deletions.
  1. +2 −0 PBGitCommitController.h
  2. +83 −0 PBGitCommitController.m
  3. +315 −9 PBGitCommitView.xib
@@ -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
@@ -23,6 +24,7 @@
IBOutlet PBGitIndexController *indexController;
IBOutlet PBWebChangesController *webController;
+ IBOutlet PBNiceSplitView *commitSplitView;
}
@property(readonly) PBGitIndex *index;
@@ -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;
@@ -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
@@ -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];
}
@@ -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
Oops, something went wrong.

0 comments on commit c545832

Please sign in to comment.