Skip to content

Commit d669050

Browse files
heipeiPieter de Bie
authored andcommitted
Add PBCollapsibleSplitView as subclass of PBNiceSplitView
This adds a subclass to PBNiceSplitView which has collapsible subviews as well as an uncollapse-method. The initWithTopMin method is used to set the minimum sizes for the subviews. Signed-off-by: Johannes Gilger <[email protected]>
1 parent f146e9a commit d669050

File tree

6 files changed

+113
-4
lines changed

6 files changed

+113
-4
lines changed

GitX.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
93CB42C20EAB7B2200530609 /* PBGitDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = 93CB42C10EAB7B2200530609 /* PBGitDefaults.m */; };
4545
93F7857F0EA3ABF100C1F443 /* PBCommitMessageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 93F7857E0EA3ABF100C1F443 /* PBCommitMessageView.m */; };
4646
D26DC6450E782C9000C777B2 /* gitx.icns in Resources */ = {isa = PBXBuildFile; fileRef = D26DC6440E782C9000C777B2 /* gitx.icns */; };
47+
EB2A734A0FEE3F09006601CF /* PBCollapsibleSplitView.m in Sources */ = {isa = PBXBuildFile; fileRef = EB2A73490FEE3F09006601CF /* PBCollapsibleSplitView.m */; };
4748
F50A411F0EBB874C00208746 /* mainSplitterBar.tiff in Resources */ = {isa = PBXBuildFile; fileRef = F50A411D0EBB874C00208746 /* mainSplitterBar.tiff */; };
4849
F50A41200EBB874C00208746 /* mainSplitterDimple.tiff in Resources */ = {isa = PBXBuildFile; fileRef = F50A411E0EBB874C00208746 /* mainSplitterDimple.tiff */; };
4950
F50A41230EBB875D00208746 /* PBNiceSplitView.m in Sources */ = {isa = PBXBuildFile; fileRef = F50A41220EBB875D00208746 /* PBNiceSplitView.m */; };
@@ -190,6 +191,8 @@
190191
93F7857E0EA3ABF100C1F443 /* PBCommitMessageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBCommitMessageView.m; sourceTree = "<group>"; };
191192
93FCCBA80EA8AF450061B02B /* PBGitConfig.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitConfig.m; sourceTree = "<group>"; };
192193
D26DC6440E782C9000C777B2 /* gitx.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = gitx.icns; sourceTree = "<group>"; };
194+
EB2A73480FEE3F09006601CF /* PBCollapsibleSplitView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBCollapsibleSplitView.h; sourceTree = "<group>"; };
195+
EB2A73490FEE3F09006601CF /* PBCollapsibleSplitView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBCollapsibleSplitView.m; sourceTree = "<group>"; };
193196
F50A411D0EBB874C00208746 /* mainSplitterBar.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; name = mainSplitterBar.tiff; path = Images/mainSplitterBar.tiff; sourceTree = "<group>"; };
194197
F50A411E0EBB874C00208746 /* mainSplitterDimple.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; name = mainSplitterDimple.tiff; path = Images/mainSplitterDimple.tiff; sourceTree = "<group>"; };
195198
F50A41210EBB875D00208746 /* PBNiceSplitView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBNiceSplitView.h; sourceTree = "<group>"; };
@@ -530,6 +533,8 @@
530533
F56244080E9684B0002B6C44 /* PBUnsortableTableHeader.m */,
531534
F50A41210EBB875D00208746 /* PBNiceSplitView.h */,
532535
F50A41220EBB875D00208746 /* PBNiceSplitView.m */,
536+
EB2A73480FEE3F09006601CF /* PBCollapsibleSplitView.h */,
537+
EB2A73490FEE3F09006601CF /* PBCollapsibleSplitView.m */,
533538
F5FC41F20EBCBD4300191D80 /* PBGitXProtocol.h */,
534539
F5FC41F30EBCBD4300191D80 /* PBGitXProtocol.m */,
535540
);
@@ -848,6 +853,7 @@
848853
47DBDB670E94EE8B00671A1E /* PBPrefsWindowController.m in Sources */,
849854
47DBDBCA0E95016F00671A1E /* PBNSURLPathUserDefaultsTransfomer.m in Sources */,
850855
F562C8870FE1766C000EC528 /* NSString_RegEx.m in Sources */,
856+
EB2A734A0FEE3F09006601CF /* PBCollapsibleSplitView.m in Sources */,
851857
);
852858
runOnlyForDeploymentPostprocessing = 0;
853859
};

PBCollapsibleSplitView.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// PBCollapsibleSplitView.h
3+
// GitX
4+
//
5+
// Created by Johannes Gilger on 6/21/09.
6+
// Copyright 2009 Johannes Gilger. All rights reserved.
7+
//
8+
9+
#import <Cocoa/Cocoa.h>
10+
#import "PBNiceSplitView.h"
11+
12+
@interface PBCollapsibleSplitView : PBNiceSplitView {
13+
CGFloat topViewMin;
14+
CGFloat bottomViewMin;
15+
}
16+
17+
@property (readonly) CGFloat topViewMin;
18+
@property (readonly) CGFloat bottomViewMin;
19+
20+
- (void)setTopMin:(CGFloat)topMin andBottomMin:(CGFloat)bottomMin;
21+
- (void)uncollapse;
22+
23+
@end

PBCollapsibleSplitView.m

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// PBCollapsibleSplitView.m
3+
// GitX
4+
//
5+
// Created by Johannes Gilger on 6/21/09.
6+
// Copyright 2009 Johannes Gilger. All rights reserved.
7+
//
8+
9+
#import "PBCollapsibleSplitView.h"
10+
11+
@implementation PBCollapsibleSplitView
12+
@synthesize topViewMin, bottomViewMin;
13+
14+
- (void)setTopMin:(CGFloat)topMin andBottomMin:(CGFloat)bottomMin {
15+
topViewMin = topMin;
16+
bottomViewMin = bottomMin;
17+
}
18+
19+
- (void)uncollapse {
20+
for (NSView *subview in [self subviews]) {
21+
if([self isSubviewCollapsed:subview]) {
22+
[self setPosition:[self frame].size.height / 3 ofDividerAtIndex:0];
23+
[self adjustSubviews];
24+
}
25+
}
26+
}
27+
28+
@end

PBGitHistoryController.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
#import "PBGitCommit.h"
1111
#import "PBGitTree.h"
1212
#import "PBViewController.h"
13+
#import "PBCollapsibleSplitView.h"
1314

1415
@interface PBGitHistoryController : PBViewController {
1516
IBOutlet NSSearchField *searchField;
1617
IBOutlet NSArrayController* commitController;
1718
IBOutlet NSTreeController* treeController;
1819
IBOutlet NSOutlineView* fileBrowser;
1920
IBOutlet NSTableView* commitList;
21+
IBOutlet PBCollapsibleSplitView *historySplitView;
2022

2123
IBOutlet id webView;
2224
int selectedTab;
@@ -54,4 +56,10 @@
5456
- (BOOL) hasNonlinearPath;
5557

5658
- (NSMenu *)tableColumnMenu;
59+
60+
- (BOOL)splitView:(NSSplitView *)sender canCollapseSubview:(NSView *)subview;
61+
- (BOOL)splitView:(NSSplitView *)splitView shouldCollapseSubview:(NSView *)subview forDoubleClickOnDividerAtIndex:(NSInteger)dividerIndex;
62+
- (CGFloat)splitView:(NSSplitView *)sender constrainMinCoordinate:(CGFloat)proposedMin ofSubviewAt:(NSInteger)offset;
63+
- (CGFloat)splitView:(NSSplitView *)sender constrainMaxCoordinate:(CGFloat)proposedMax ofSubviewAt:(NSInteger)offset;
64+
5765
@end

PBGitHistoryController.m

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ - (void)awakeFromNib
4141
[[commitList tableColumnWithIdentifier:@"subject"] setSortDescriptorPrototype:[[NSSortDescriptor alloc] initWithKey:@"subject" ascending:YES]];
4242
// Add a menu that allows a user to select which columns to view
4343
[[commitList headerView] setMenu:[self tableColumnMenu]];
44+
[historySplitView setTopMin:33.0 andBottomMin:100.0];
45+
[historySplitView uncollapse];
4446
[super awakeFromNib];
4547
}
4648

@@ -296,4 +298,28 @@ - (NSArray *)menuItemsForPaths:(NSArray *)paths
296298
return menuItems;
297299
}
298300

301+
- (BOOL)splitView:(NSSplitView *)sender canCollapseSubview:(NSView *)subview {
302+
return TRUE;
303+
}
304+
305+
- (BOOL)splitView:(NSSplitView *)splitView shouldCollapseSubview:(NSView *)subview forDoubleClickOnDividerAtIndex:(NSInteger)dividerIndex {
306+
int index = [[splitView subviews] indexOfObject:subview];
307+
// this method (and canCollapse) are called by the splitView to decide how to collapse on double-click
308+
// we compare our two subviews, so that always the smaller one is collapsed.
309+
if([[[splitView subviews] objectAtIndex:index] frame].size.height < [[[splitView subviews] objectAtIndex:((index+1)%2)] frame].size.height) {
310+
return TRUE;
311+
}
312+
return FALSE;
313+
}
314+
315+
- (CGFloat)splitView:(NSSplitView *)sender constrainMinCoordinate:(CGFloat)proposedMin ofSubviewAt:(NSInteger)offset {
316+
return proposedMin + historySplitView.topViewMin;
317+
}
318+
319+
- (CGFloat)splitView:(NSSplitView *)sender constrainMaxCoordinate:(CGFloat)proposedMax ofSubviewAt:(NSInteger)offset {
320+
if(offset = 1)
321+
return proposedMax - historySplitView.bottomViewMin;
322+
return [sender frame].size.height;
323+
}
324+
299325
@end

PBGitHistoryView.xib

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<string key="IBDocument.HIToolboxVersion">353.00</string>
99
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
1010
<bool key="EncodedWithXMLCoder">YES</bool>
11+
<integer value="46"/>
1112
<integer value="237"/>
12-
<integer value="2"/>
1313
</object>
1414
<object class="NSArray" key="IBDocument.PluginDependencies">
1515
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -420,7 +420,7 @@
420420
<object class="NSTextView" id="239018083">
421421
<reference key="NSNextResponder" ref="948090592"/>
422422
<int key="NSvFlags">2322</int>
423-
<string key="NSFrameSize">{835, 70}</string>
423+
<string key="NSFrameSize">{835, 0}</string>
424424
<reference key="NSSuperview" ref="948090592"/>
425425
<object class="NSTextContainer" key="NSTextContainer" id="53511606">
426426
<object class="NSLayoutManager" key="NSLayoutManager">
@@ -784,7 +784,7 @@
784784
<object class="NSTextView" id="75600241">
785785
<reference key="NSNextResponder" ref="321980917"/>
786786
<int key="NSvFlags">2322</int>
787-
<string key="NSFrameSize">{543, 112}</string>
787+
<string key="NSFrameSize">{543, 0}</string>
788788
<reference key="NSSuperview" ref="321980917"/>
789789
<object class="NSTextContainer" key="NSTextContainer" id="480935218">
790790
<object class="NSLayoutManager" key="NSLayoutManager">
@@ -2093,6 +2093,14 @@
20932093
</object>
20942094
<int key="connectionID">274</int>
20952095
</object>
2096+
<object class="IBConnectionRecord">
2097+
<object class="IBOutletConnection" key="connection">
2098+
<string key="label">historySplitView</string>
2099+
<reference key="source" ref="1001"/>
2100+
<reference key="destination" ref="202620420"/>
2101+
</object>
2102+
<int key="connectionID">275</int>
2103+
</object>
20962104
</object>
20972105
<object class="IBMutableOrderedSet" key="objectRecords">
20982106
<object class="NSArray" key="orderedObjects">
@@ -2859,7 +2867,7 @@
28592867
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
28602868
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
28612869
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
2862-
<string>PBNiceSplitView</string>
2870+
<string>PBCollapsibleSplitView</string>
28632871
<string>{{312, 577}, {852, 384}}</string>
28642872
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
28652873
<reference ref="9"/>
@@ -2993,6 +3001,14 @@
29933001
<object class="IBClassDescriber" key="IBDocument.Classes">
29943002
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
29953003
<bool key="EncodedWithXMLCoder">YES</bool>
3004+
<object class="IBPartialClassDescription">
3005+
<string key="className">PBCollapsibleSplitView</string>
3006+
<string key="superclassName">PBNiceSplitView</string>
3007+
<object class="IBClassDescriptionSource" key="sourceIdentifier">
3008+
<string key="majorKey">IBProjectSource</string>
3009+
<string key="minorKey">PBCollapsibleSplitView.h</string>
3010+
</object>
3011+
</object>
29963012
<object class="IBPartialClassDescription">
29973013
<string key="className">PBCommitList</string>
29983014
<string key="superclassName">NSTableView</string>
@@ -3051,6 +3067,7 @@
30513067
<string>commitController</string>
30523068
<string>commitList</string>
30533069
<string>fileBrowser</string>
3070+
<string>historySplitView</string>
30543071
<string>searchField</string>
30553072
<string>treeContextMenu</string>
30563073
<string>treeController</string>
@@ -3061,6 +3078,7 @@
30613078
<string>NSArrayController</string>
30623079
<string>NSTableView</string>
30633080
<string>NSOutlineView</string>
3081+
<string>PBCollapsibleSplitView</string>
30643082
<string>NSSearchField</string>
30653083
<string>NSMenu</string>
30663084
<string>NSTreeController</string>

0 commit comments

Comments
 (0)