forked from brotherbard/gitx
-
Notifications
You must be signed in to change notification settings - Fork 2
/
PBCollapsibleSplitView.m
57 lines (48 loc) · 1.63 KB
/
PBCollapsibleSplitView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// PBCollapsibleSplitView.m
// GitX
//
// Created by Johannes Gilger on 6/21/09.
// Copyright 2009 Johannes Gilger. All rights reserved.
//
#import "PBCollapsibleSplitView.h"
@implementation PBCollapsibleSplitView
@synthesize topViewMin, bottomViewMin;
- (void)setTopMin:(CGFloat)topMin andBottomMin:(CGFloat)bottomMin {
topViewMin = topMin;
bottomViewMin = bottomMin;
}
- (void)uncollapse {
for (NSView *subview in [self subviews]) {
if([self isSubviewCollapsed:subview]) {
[self setPosition:[self frame].size.height / 3 ofDividerAtIndex:0];
[self adjustSubviews];
}
}
}
- (void)collapseSubview:(NSInteger)index {
// Already collapsed, just uncollapse
if ([self isSubviewCollapsed:[[self subviews] objectAtIndex:index]]) {
[self setPosition:splitterPosition ofDividerAtIndex:0];
return;
}
// Store splitterposition if the other view isn't collapsed
if (![self isSubviewCollapsed:[[self subviews] objectAtIndex:(index + 1) % 2]])
splitterPosition = [[[self subviews] objectAtIndex:0] frame].size.height;
if (index == 0) // Top view
[self setPosition:0.0 ofDividerAtIndex:0];
else // Bottom view
[self setPosition:[self frame].size.height ofDividerAtIndex:0];
}
- (void)keyDown:(NSEvent *)event {
if (!([event modifierFlags] & NSShiftKeyMask && [event modifierFlags] & NSCommandKeyMask))
return [super keyDown:event];
if ([event keyCode] == 0x07E) { // Up-Key
[self collapseSubview:0];
[[self window] makeFirstResponder:[[self subviews] objectAtIndex:1]];
} else if ([event keyCode] == 0x07D) { // Down-Key
[self collapseSubview:1];
[[self window] makeFirstResponder:[[self subviews] objectAtIndex:0]];
}
}
@end