File tree Expand file tree Collapse file tree 3 files changed +42
-1
lines changed Expand file tree Collapse file tree 3 files changed +42
-1
lines changed Original file line number Diff line number Diff line change 2
2
// PBCollapsibleSplitView.h
3
3
// GitX
4
4
//
5
+ // This is a limited subclass of a SplitView. It adds methods to aid in
6
+ // collapsing/uncollapsing subviews using the mouse or programmatically.
7
+ // Right now it only works for vertical layouts and with two subviews.
8
+ //
5
9
// Created by Johannes Gilger on 6/21/09.
6
10
// Copyright 2009 Johannes Gilger. All rights reserved.
7
11
//
12
16
@interface PBCollapsibleSplitView : PBNiceSplitView {
13
17
CGFloat topViewMin;
14
18
CGFloat bottomViewMin;
19
+ CGFloat splitterPosition;
15
20
}
16
21
17
22
@property (readonly ) CGFloat topViewMin;
18
23
@property (readonly ) CGFloat bottomViewMin;
19
24
20
25
- (void )setTopMin : (CGFloat)topMin andBottomMin : (CGFloat)bottomMin ;
21
26
- (void )uncollapse ;
27
+ - (void )keyDown : (NSEvent *)event ;
22
28
23
29
@end
Original file line number Diff line number Diff line change @@ -25,4 +25,33 @@ - (void)uncollapse {
25
25
}
26
26
}
27
27
28
+ - (void )collapseSubview : (NSInteger )index {
29
+ // Already collapsed, just uncollapse
30
+ if ([self isSubviewCollapsed: [[self subviews ] objectAtIndex: index]]) {
31
+ [self setPosition: splitterPosition ofDividerAtIndex: 0 ];
32
+ return ;
33
+ }
34
+
35
+ // Store splitterposition if the other view isn't collapsed
36
+ if (![self isSubviewCollapsed: [[self subviews ] objectAtIndex: (index + 1 ) % 2 ]])
37
+ splitterPosition = [[[self subviews ] objectAtIndex: 0 ] frame ].size .height ;
38
+
39
+ if (index == 0 ) // Top view
40
+ [self setPosition: 0.0 ofDividerAtIndex: 0 ];
41
+ else // Bottom view
42
+ [self setPosition: [self frame ].size.height ofDividerAtIndex: 0 ];
43
+ }
44
+
45
+ - (void )keyDown : (NSEvent *)event {
46
+ if (!([event modifierFlags ] & NSShiftKeyMask && [event modifierFlags ] & NSCommandKeyMask ))
47
+ return [super keyDown: event];
48
+
49
+ if ([event keyCode ] == 0x07E ) { // Up-Key
50
+ [self collapseSubview: 0 ];
51
+ [[self window ] makeFirstResponder: [[self subviews ] objectAtIndex: 1 ]];
52
+ } else if ([event keyCode ] == 0x07D ) { // Down-Key
53
+ [self collapseSubview: 1 ];
54
+ [[self window ] makeFirstResponder: [[self subviews ] objectAtIndex: 0 ]];
55
+ }
56
+ }
28
57
@end
Original file line number Diff line number Diff line change @@ -18,10 +18,16 @@ - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL) local
18
18
return NSDragOperationCopy;
19
19
}
20
20
21
- - (void ) keyDown : ( id ) event
21
+ - (void )keyDown : ( NSEvent *) event
22
22
{
23
23
NSString * character = [event charactersIgnoringModifiers ];
24
24
25
+ // Pass on command-shift up/down to the responder. We want the splitview to capture this.
26
+ if ([event modifierFlags ] & NSShiftKeyMask && [event modifierFlags ] & NSCommandKeyMask && ([event keyCode ] == 0x7E || [event keyCode ] == 0x7D )) {
27
+ [self .nextResponder keyDown: event];
28
+ return ;
29
+ }
30
+
25
31
if ([character isEqualToString: @" " ])
26
32
{
27
33
if ([event modifierFlags ] & NSShiftKeyMask )
You can’t perform that action at this time.
0 commit comments