Testing: add missing file
[GitX.git] / PBCollapsibleSplitView.m
blob9665cac120f30fdda09fbc014029bf969a74d59a
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 //
9 #import "PBCollapsibleSplitView.h"
11 @implementation PBCollapsibleSplitView
12 @synthesize topViewMin, bottomViewMin;
14 - (void)setTopMin:(CGFloat)topMin andBottomMin:(CGFloat)bottomMin {
15         topViewMin = topMin;
16         bottomViewMin = bottomMin;
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         }
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         }
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];
41         else // Bottom view
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]];
55         }
57 @end