Skip to content

Commit 193b834

Browse files
heipeiPieter de Bie
authored andcommitted
PBCollapsibleSplitView: Enable collapse/uncollapse using keys
This adds a method to programmatically collapse/uncollapse the two subviews of our custom SplitView-class. It also implements a keyDown-method so that the collapsing can be used with Command-Shift-{Up,Down}. Signed-off-by: Johannes Gilger <[email protected]>
1 parent d669050 commit 193b834

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

PBCollapsibleSplitView.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// PBCollapsibleSplitView.h
33
// GitX
44
//
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+
//
59
// Created by Johannes Gilger on 6/21/09.
610
// Copyright 2009 Johannes Gilger. All rights reserved.
711
//
@@ -12,12 +16,14 @@
1216
@interface PBCollapsibleSplitView : PBNiceSplitView {
1317
CGFloat topViewMin;
1418
CGFloat bottomViewMin;
19+
CGFloat splitterPosition;
1520
}
1621

1722
@property (readonly) CGFloat topViewMin;
1823
@property (readonly) CGFloat bottomViewMin;
1924

2025
- (void)setTopMin:(CGFloat)topMin andBottomMin:(CGFloat)bottomMin;
2126
- (void)uncollapse;
27+
- (void)keyDown:(NSEvent *)event;
2228

2329
@end

PBCollapsibleSplitView.m

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,33 @@ - (void)uncollapse {
2525
}
2626
}
2727

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+
}
2857
@end

PBCommitList.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,16 @@ - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL) local
1818
return NSDragOperationCopy;
1919
}
2020

21-
- (void) keyDown: (id) event
21+
- (void)keyDown:(NSEvent *)event
2222
{
2323
NSString* character = [event charactersIgnoringModifiers];
2424

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+
2531
if ([character isEqualToString:@" "])
2632
{
2733
if ([event modifierFlags] & NSShiftKeyMask)

0 commit comments

Comments
 (0)