2 // PBCollapsibleSplitView.m
5 // Created by Johannes Gilger on 6/21/09.
6 // Copyright 2009 Johannes Gilger. All rights reserved.
9 #import "PBCollapsibleSplitView.h"
11 @implementation PBCollapsibleSplitView
12 @synthesize topViewMin, bottomViewMin;
14 - (void)setTopMin:(CGFloat)topMin andBottomMin:(CGFloat)bottomMin {
16 bottomViewMin = bottomMin;
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];
28 - (void)collapseSubview:(NSInteger)index {
29 // Already collapsed, just uncollapse
30 if ([self isSubviewCollapsed:[[self subviews] objectAtIndex:index]]) {
31 [self setPosition:splitterPosition ofDividerAtIndex:0];
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;
39 if (index == 0) // Top view
40 [self setPosition:0.0 ofDividerAtIndex:0];
42 [self setPosition:[self frame].size.height ofDividerAtIndex:0];
45 - (void)keyDown:(NSEvent *)event {
46 if (!([event modifierFlags] & NSShiftKeyMask && [event modifierFlags] & NSCommandKeyMask))
47 return [super keyDown:event];
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]];