Skip to content

Commit 899ca98

Browse files
authored
Merge pull request #88 from ksuther/split-view
Split view modernization, better window frame restoration and other fixes
2 parents e55b4a4 + 3d969fe commit 899ca98

15 files changed

+460
-711
lines changed

Classes/Controllers/PBGitCommitController.m

Lines changed: 4 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@
1111
#import "PBChangedFile.h"
1212
#import "PBWebChangesController.h"
1313
#import "PBGitIndex.h"
14-
#import "PBNiceSplitView.h"
1514
#import "PBGitRepositoryWatcher.h"
1615
#import "PBCommitMessageView.h"
16+
#import "NSSplitView+GitX.h"
1717

1818
#import <ObjectiveGit/GTRepository.h>
1919
#import <ObjectiveGit/GTConfiguration.h>
2020

21-
#define kCommitSplitViewPositionDefault @"Commit SplitView Position"
2221
#define kMinimalCommitMessageLength 3
2322
#define kNotificationDictionaryDescriptionKey @"description"
2423
#define kNotificationDictionaryMessageKey @"message"
@@ -36,7 +35,7 @@ @interface PBGitCommitController () <NSTextViewDelegate, NSMenuDelegate> {
3635
IBOutlet NSButton *commitButton;
3736

3837
IBOutlet PBWebChangesController *webController;
39-
IBOutlet PBNiceSplitView *commitSplitView;
38+
IBOutlet NSSplitView *commitSplitView;
4039
}
4140

4241
@property (weak) IBOutlet NSTableView *unstagedTable;
@@ -70,6 +69,8 @@ - (id)initWithRepository:(PBGitRepository *)theRepository superController:(PBGit
7069

7170
- (void)awakeFromNib
7271
{
72+
[commitSplitView pb_restoreAutosavedPositions];
73+
7374
[super awakeFromNib];
7475

7576
commitMessageView.repository = self.repository;
@@ -93,9 +94,6 @@ - (void)awakeFromNib
9394
[stagedFilesController setAutomaticallyRearrangesObjects:NO];
9495
[unstagedFilesController setAutomaticallyRearrangesObjects:NO];
9596

96-
[commitSplitView setHidden:YES];
97-
[self performSelector:@selector(restoreCommitSplitViewPositiion) withObject:nil afterDelay:0];
98-
9997
[unstagedTable setDoubleAction:@selector(didDoubleClickOnTable:)];
10098
[stagedTable setDoubleAction:@selector(didDoubleClickOnTable:)];
10199

@@ -125,7 +123,6 @@ - (void) updateView
125123

126124
- (void)closeView
127125
{
128-
[self saveCommitSplitViewPosition];
129126
[[NSNotificationCenter defaultCenter] removeObserver:self];
130127
[webController closeView];
131128
}
@@ -460,81 +457,6 @@ - (void)indexOperationFailed:(NSNotification *)notification
460457
infoText:notification.userInfo[kNotificationDictionaryDescriptionKey]];
461458
}
462459

463-
464-
#pragma mark NSSplitView delegate methods
465-
466-
#define kCommitSplitViewTopViewMin 150
467-
#define kCommitSplitViewBottomViewMin 100
468-
469-
- (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMin ofSubviewAt:(NSInteger)dividerIndex
470-
{
471-
if (splitView == commitSplitView)
472-
return kCommitSplitViewTopViewMin;
473-
474-
return proposedMin;
475-
}
476-
477-
- (CGFloat)splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMax ofSubviewAt:(NSInteger)dividerIndex
478-
{
479-
if (splitView == commitSplitView)
480-
return splitView.frame.size.height - splitView.dividerThickness - kCommitSplitViewBottomViewMin;
481-
482-
return proposedMax;
483-
}
484-
485-
// while the user resizes the window keep the lower (changes/message) view constant and just resize the upper view
486-
// unless the upper view gets too small
487-
- (void)resizeCommitSplitView
488-
{
489-
NSRect newFrame = [commitSplitView frame];
490-
491-
CGFloat dividerThickness = commitSplitView.dividerThickness;
492-
493-
NSView *upperView = [[commitSplitView subviews] objectAtIndex:0];
494-
NSRect upperFrame = [upperView frame];
495-
upperFrame.size.width = newFrame.size.width;
496-
497-
NSView *lowerView = [[commitSplitView subviews] objectAtIndex:1];
498-
NSRect lowerFrame = [lowerView frame];
499-
lowerFrame.size.width = newFrame.size.width;
500-
501-
upperFrame.size.height = newFrame.size.height - lowerFrame.size.height - dividerThickness;
502-
if (upperFrame.size.height < kCommitSplitViewTopViewMin)
503-
upperFrame.size.height = kCommitSplitViewTopViewMin;
504-
505-
lowerFrame.size.height = newFrame.size.height - upperFrame.size.height - dividerThickness;
506-
lowerFrame.origin.y = newFrame.size.height - lowerFrame.size.height;
507-
508-
[upperView setFrame:upperFrame];
509-
[lowerView setFrame:lowerFrame];
510-
}
511-
512-
- (void)splitView:(NSSplitView *)splitView resizeSubviewsWithOldSize:(NSSize)oldSize
513-
{
514-
if (splitView == commitSplitView)
515-
[self resizeCommitSplitView];
516-
}
517-
518-
// NSSplitView does not save and restore the position of the splitView correctly so do it manually
519-
- (void)saveCommitSplitViewPosition
520-
{
521-
CGFloat position = [[[commitSplitView subviews] objectAtIndex:0] frame].size.height;
522-
[[NSUserDefaults standardUserDefaults] setDouble:position forKey:kCommitSplitViewPositionDefault];
523-
[[NSUserDefaults standardUserDefaults] synchronize];
524-
}
525-
526-
// make sure this happens after awakeFromNib
527-
- (void)restoreCommitSplitViewPositiion
528-
{
529-
CGFloat position = [[NSUserDefaults standardUserDefaults] doubleForKey:kCommitSplitViewPositionDefault];
530-
if (position < 1.0)
531-
position = commitSplitView.frame.size.height - 225;
532-
533-
[commitSplitView setPosition:position ofDividerAtIndex:0];
534-
[commitSplitView setHidden:NO];
535-
}
536-
537-
538460
#pragma mark NSTextView delegate methods
539461

540462
- (void)focusTable:(NSTableView *)table

Classes/Controllers/PBGitHistoryController.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
@class PBGitCommit;
1313
@class PBGitTree;
14-
@class PBCollapsibleSplitView;
1514

1615
@class PBGitSidebarController;
1716
@class PBWebHistoryController;
@@ -33,7 +32,7 @@
3332
__weak IBOutlet NSSearchField *searchField;
3433
__weak IBOutlet NSOutlineView *fileBrowser;
3534
__weak IBOutlet PBCommitList *commitList;
36-
__weak IBOutlet PBCollapsibleSplitView *historySplitView;
35+
__weak IBOutlet NSSplitView *historySplitView;
3736
__weak IBOutlet PBGitGradientBarView *upperToolbarView;
3837
__weak IBOutlet PBGitGradientBarView *scopeBarView;
3938
__weak IBOutlet NSButton *allBranchesFilterItem;
@@ -94,9 +93,4 @@
9493

9594
- (NSMenu *)tableColumnMenu;
9695

97-
- (BOOL)splitView:(NSSplitView *)sender canCollapseSubview:(NSView *)subview;
98-
- (BOOL)splitView:(NSSplitView *)splitView shouldCollapseSubview:(NSView *)subview forDoubleClickOnDividerAtIndex:(NSInteger)dividerIndex;
99-
- (CGFloat)splitView:(NSSplitView *)sender constrainMinCoordinate:(CGFloat)proposedMin ofSubviewAt:(NSInteger)offset;
100-
- (CGFloat)splitView:(NSSplitView *)sender constrainMaxCoordinate:(CGFloat)proposedMax ofSubviewAt:(NSInteger)offset;
101-
10296
@end

Classes/Controllers/PBGitHistoryController.m

Lines changed: 4 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#import "PBGitRef.h"
1212
#import "PBGitHistoryList.h"
1313
#import "PBGitRevSpecifier.h"
14-
#import "PBCollapsibleSplitView.h"
1514
#import "PBGitHistoryController.h"
1615
#import "PBWebHistoryController.h"
1716
#import "PBGitGrapher.h"
@@ -30,21 +29,19 @@
3029
#import "PBQLTextView.h"
3130
#import "GLFileView.h"
3231
#import "GitXCommitCopier.h"
32+
#import "NSSplitView+GitX.h"
3333
#import <Quartz/Quartz.h>
3434

3535

3636
#define kHistorySelectedDetailIndexKey @"PBHistorySelectedDetailIndex"
3737
#define kHistoryDetailViewIndex 0
3838
#define kHistoryTreeViewIndex 1
3939

40-
#define kHistorySplitViewPositionDefault @"History SplitView Position"
41-
4240
@interface PBGitHistoryController ()
4341

4442
- (void) updateBranchFilterMatrix;
4543
- (void) restoreFileBrowserSelection;
4644
- (void) saveFileBrowserSelection;
47-
- (void)saveSplitViewPosition;
4845

4946
@end
5047

@@ -58,6 +55,8 @@ @implementation PBGitHistoryController
5855

5956
- (void)awakeFromNib
6057
{
58+
[historySplitView pb_restoreAutosavedPositions];
59+
6160
self.selectedCommitDetailsIndex = [[NSUserDefaults standardUserDefaults] integerForKey:kHistorySelectedDetailIndexKey];
6261

6362
[commitController addObserver:self forKeyPath:@"selection" options:0 context:@"commitChange"];
@@ -95,10 +94,6 @@ - (void)awakeFromNib
9594
// Add a menu that allows a user to select which columns to view
9695
[[commitList headerView] setMenu:[self tableColumnMenu]];
9796

98-
[historySplitView setTopMin:58.0 andBottomMin:100.0];
99-
[historySplitView setHidden:YES];
100-
[self performSelector:@selector(restoreSplitViewPositiion) withObject:nil afterDelay:0];
101-
10297
[upperToolbarView setTopShade:237/255.0f bottomShade:216/255.0f];
10398
[scopeBarView setTopColor:[NSColor colorWithCalibratedHue:0.579 saturation:0.068 brightness:0.898 alpha:1.000]
10499
bottomColor:[NSColor colorWithCalibratedHue:0.579 saturation:0.119 brightness:0.765 alpha:1.000]];
@@ -438,7 +433,7 @@ - (IBAction) toggleQLPreviewPanel:(id)sender
438433

439434
- (void) updateQuicklookForce:(BOOL)force
440435
{
441-
if (!force && ![[QLPreviewPanel sharedPreviewPanel] isVisible])
436+
if (!force && (![QLPreviewPanel sharedPreviewPanelExists] || ![[QLPreviewPanel sharedPreviewPanel] isVisible]))
442437
return;
443438

444439
[[QLPreviewPanel sharedPreviewPanel] reloadData];
@@ -517,8 +512,6 @@ - (BOOL) hasNonlinearPath
517512

518513
- (void)closeView
519514
{
520-
[self saveSplitViewPosition];
521-
522515
if (commitController) {
523516
[[NSNotificationCenter defaultCenter] removeObserver:self];
524517
[commitController removeObserver:self forKeyPath:@"selection"];
@@ -637,55 +630,6 @@ - (NSArray *)menuItemsForPaths:(NSArray *)paths
637630
return menuItems;
638631
}
639632

640-
641-
#pragma mark NSSplitView delegate methods
642-
643-
- (BOOL)splitView:(NSSplitView *)splitView canCollapseSubview:(NSView *)subview
644-
{
645-
return TRUE;
646-
}
647-
648-
- (BOOL)splitView:(NSSplitView *)splitView shouldCollapseSubview:(NSView *)subview forDoubleClickOnDividerAtIndex:(NSInteger)dividerIndex
649-
{
650-
NSUInteger index = [[splitView subviews] indexOfObject:subview];
651-
// this method (and canCollapse) are called by the splitView to decide how to collapse on double-click
652-
// we compare our two subviews, so that always the smaller one is collapsed.
653-
if([[[splitView subviews] objectAtIndex:index] frame].size.height < [[[splitView subviews] objectAtIndex:((index+1)%2)] frame].size.height) {
654-
return TRUE;
655-
}
656-
return FALSE;
657-
}
658-
659-
- (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMin ofSubviewAt:(NSInteger)dividerIndex
660-
{
661-
return historySplitView.topViewMin;
662-
}
663-
664-
- (CGFloat)splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMax ofSubviewAt:(NSInteger)dividerIndex
665-
{
666-
return [splitView frame].size.height - [splitView dividerThickness] - historySplitView.bottomViewMin;
667-
}
668-
669-
// NSSplitView does not save and restore the position of the SplitView correctly so do it manually
670-
- (void)saveSplitViewPosition
671-
{
672-
CGFloat position = [[historySplitView subviews] objectAtIndex:0].frame.size.height;
673-
[[NSUserDefaults standardUserDefaults] setDouble:position forKey:kHistorySplitViewPositionDefault];
674-
[[NSUserDefaults standardUserDefaults] synchronize];
675-
}
676-
677-
// make sure this happens after awakeFromNib
678-
- (void)restoreSplitViewPositiion
679-
{
680-
CGFloat position = [[NSUserDefaults standardUserDefaults] doubleForKey:kHistorySplitViewPositionDefault];
681-
if (position < 1.0)
682-
position = 175;
683-
684-
[historySplitView setPosition:position ofDividerAtIndex:0];
685-
[historySplitView setHidden:NO];
686-
}
687-
688-
689633
#pragma mark Repository Methods
690634

691635
- (IBAction) createBranch:(id)sender

Classes/Controllers/PBGitWindowController.m

Lines changed: 11 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ - (void)synchronizeWindowTitleWithDocumentName
4646
{
4747
[super synchronizeWindowTitleWithDocumentName];
4848

49-
// Point window proxy icon at project directory, not internal .git dir
50-
[[self window] setRepresentedURL:self.repository.workingDirectoryURL];
49+
if ([self isWindowLoaded]) {
50+
// Point window proxy icon at project directory, not internal .git dir
51+
[[self window] setRepresentedURL:self.repository.workingDirectoryURL];
52+
}
5153
}
5254

5355
- (void)windowWillClose:(NSNotification *)notification
@@ -99,11 +101,14 @@ - (BOOL) validateMenuItem:(NSMenuItem *)menuItem remoteTitle:(NSString *)localis
99101
}
100102

101103

102-
- (void) awakeFromNib
104+
- (void) windowDidLoad
103105
{
104-
[[self window] setDelegate:self];
105-
[[self window] setAutorecalculatesContentBorderThickness:NO forEdge:NSMinYEdge];
106-
[[self window] setContentBorderThickness:31.0f forEdge:NSMinYEdge];
106+
[super windowDidLoad];
107+
108+
// Explicitly set the frame using the autosave name
109+
// Opening the first and second documents works fine, but the third and subsequent windows aren't positioned correctly
110+
[[self window] setFrameUsingName:@"GitX"];
111+
[[self window] setRepresentedURL:self.repository.workingDirectoryURL];
107112

108113
sidebarController = [[PBGitSidebarController alloc] initWithRepository:repository superController:self];
109114
[[sidebarController view] setFrame:[sourceSplitView bounds]];
@@ -112,8 +117,6 @@ - (void) awakeFromNib
112117

113118
[[statusField cell] setBackgroundStyle:NSBackgroundStyleRaised];
114119
[progressIndicator setUsesThreadedAnimation:YES];
115-
116-
[self showWindow:nil];
117120
}
118121

119122
- (void) removeAllContentSubViews
@@ -398,50 +401,4 @@ - (IBAction) refresh:(id)sender
398401
[contentController refresh:self];
399402
}
400403

401-
#pragma mark -
402-
#pragma mark SplitView Delegates
403-
404-
#define kGitSplitViewMinWidth 150.0f
405-
#define kGitSplitViewMaxWidth 300.0f
406-
407-
#pragma mark min/max widths while moving the divider
408-
409-
- (CGFloat)splitView:(NSSplitView *)view constrainMinCoordinate:(CGFloat)proposedMin ofSubviewAt:(NSInteger)dividerIndex
410-
{
411-
if (proposedMin < kGitSplitViewMinWidth)
412-
return kGitSplitViewMinWidth;
413-
414-
return proposedMin;
415-
}
416-
417-
- (CGFloat)splitView:(NSSplitView *)view constrainMaxCoordinate:(CGFloat)proposedMax ofSubviewAt:(NSInteger)dividerIndex
418-
{
419-
if (dividerIndex == 0)
420-
return kGitSplitViewMaxWidth;
421-
422-
return proposedMax;
423-
}
424-
425-
#pragma mark constrain sidebar width while resizing the window
426-
427-
- (void)splitView:(NSSplitView *)sender resizeSubviewsWithOldSize:(NSSize)oldSize
428-
{
429-
NSRect newFrame = [sender frame];
430-
431-
CGFloat dividerThickness = [sender dividerThickness];
432-
433-
NSView *sourceView = [[sender subviews] objectAtIndex:0];
434-
NSRect sourceFrame = [sourceView frame];
435-
sourceFrame.size.height = newFrame.size.height;
436-
437-
NSView *mainView = [[sender subviews] objectAtIndex:1];
438-
NSRect mainFrame = [mainView frame];
439-
mainFrame.origin.x = sourceFrame.size.width + dividerThickness;
440-
mainFrame.size.width = newFrame.size.width - mainFrame.origin.x;
441-
mainFrame.size.height = newFrame.size.height;
442-
443-
[sourceView setFrame:sourceFrame];
444-
[mainView setFrame:mainFrame];
445-
}
446-
447404
@end

Classes/NSSplitView+GitX.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// NSSplitView+GitX.h
3+
// GitX
4+
//
5+
// Created by Kent Sutherland on 4/25/17.
6+
//
7+
//
8+
9+
#import <Cocoa/Cocoa.h>
10+
11+
@interface NSSplitView (GitX)
12+
13+
- (void)pb_restoreAutosavedPositions;
14+
15+
@end

0 commit comments

Comments
 (0)