diff --git a/GLFileView.h b/GLFileView.h index 79b3707..fa23859 100644 --- a/GLFileView.h +++ b/GLFileView.h @@ -21,6 +21,7 @@ NSMutableArray *groups; NSString *logFormat; IBOutlet NSView *accessoryView; + IBOutlet NSSplitView *fileListSplitView; } - (void)showFile; diff --git a/GLFileView.m b/GLFileView.m index b1d2da9..bec36c6 100644 --- a/GLFileView.m +++ b/GLFileView.m @@ -16,6 +16,14 @@ #define ITEM_IDENTIFIER @"Identifier" // string #define ITEM_NAME @"Name" // string + +@interface GLFileView () + +- (void)saveSplitViewPosition; + +@end + + @implementation GLFileView - (void) awakeFromNib @@ -52,6 +60,9 @@ items, GROUP_ITEMS, nil]]; [typeBar reloadData]; + + [fileListSplitView setHidden:YES]; + [self performSelector:@selector(restoreSplitViewPositiion) withObject:nil afterDelay:0]; } - (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context @@ -154,6 +165,7 @@ - (void)closeView { [historyController.treeController removeObserver:self forKeyPath:@"selection"]; + [self saveSplitViewPosition]; [super closeView]; } @@ -241,6 +253,71 @@ return (NSString *)res; } + + +#pragma mark NSSplitView delegate methods + +#define kFileListSplitViewLeftMin 120 +#define kFileListSplitViewRightMin 180 +#define kHFileListSplitViewPositionDefault @"File List SplitView Position" + +- (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMin ofSubviewAt:(NSInteger)dividerIndex +{ + return kFileListSplitViewLeftMin; +} + +- (CGFloat)splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMax ofSubviewAt:(NSInteger)dividerIndex +{ + return [splitView frame].size.width - [splitView dividerThickness] - kFileListSplitViewRightMin; +} + +// while the user resizes the window keep the left (file list) view constant and just resize the right view +// unless the right view gets too small +- (void)splitView:(NSSplitView *)splitView resizeSubviewsWithOldSize:(NSSize)oldSize +{ + NSRect newFrame = [splitView frame]; + + float dividerThickness = [splitView dividerThickness]; + + NSView *leftView = [[splitView subviews] objectAtIndex:0]; + NSRect leftFrame = [leftView frame]; + leftFrame.size.height = newFrame.size.height; + + if ((newFrame.size.width - leftFrame.size.width - dividerThickness) < kFileListSplitViewRightMin) { + leftFrame.size.width = newFrame.size.width - kFileListSplitViewRightMin - dividerThickness; + } + + NSView *rightView = [[splitView subviews] objectAtIndex:1]; + NSRect rightFrame = [rightView frame]; + rightFrame.origin.x = leftFrame.size.width + dividerThickness; + rightFrame.size.width = newFrame.size.width - rightFrame.origin.x; + rightFrame.size.height = newFrame.size.height; + + [leftView setFrame:leftFrame]; + [rightView setFrame:rightFrame]; +} + +// NSSplitView does not save and restore the position of the SplitView correctly so do it manually +- (void)saveSplitViewPosition +{ + float position = [[[fileListSplitView subviews] objectAtIndex:0] frame].size.width; + [[NSUserDefaults standardUserDefaults] setFloat:position forKey:kHFileListSplitViewPositionDefault]; + [[NSUserDefaults standardUserDefaults] synchronize]; +} + +// make sure this happens after awakeFromNib +- (void)restoreSplitViewPositiion +{ + float position = [[NSUserDefaults standardUserDefaults] floatForKey:kHFileListSplitViewPositionDefault]; + if (position < 1.0) + position = 200; + + [fileListSplitView setPosition:position ofDividerAtIndex:0]; + [fileListSplitView setHidden:NO]; +} + + + @synthesize groups; @synthesize logFormat; diff --git a/PBGitHistoryView.xib b/PBGitHistoryView.xib index aa1dd9b..ad42aa9 100644 --- a/PBGitHistoryView.xib +++ b/PBGitHistoryView.xib @@ -21,7 +21,7 @@ YES - + YES @@ -1074,7 +1074,7 @@ - 268 + 274 YES @@ -1084,7 +1084,7 @@ YES - 268 + 265 YES @@ -1984,6 +1984,22 @@ 488 + + + fileListSplitView + + + + 489 + + + + delegate + + + + 490 + @@ -2894,7 +2910,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.WebKitIBPlugin - {{1559, 241}, {955, 434}} + {{1084, 241}, {955, 434}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -2932,7 +2948,7 @@ - 488 + 490 @@ -2945,12 +2961,14 @@ YES accessoryView + fileListSplitView historyController typeBar YES NSView + NSSplitView PBGitHistoryController MGScopeBar @@ -2960,6 +2978,7 @@ YES accessoryView + fileListSplitView historyController typeBar @@ -2969,6 +2988,10 @@ accessoryView NSView + + fileListSplitView + NSSplitView + historyController PBGitHistoryController