Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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 <heipei@hackvalue.de>
  • Loading branch information...
commit 193b834a5c50a06812fb21a274d7dd823c641146 1 parent d669050
@heipei heipei authored Pieter de Bie committed
View
6 PBCollapsibleSplitView.h
@@ -2,6 +2,10 @@
// PBCollapsibleSplitView.h
// GitX
//
+// This is a limited subclass of a SplitView. It adds methods to aid in
+// collapsing/uncollapsing subviews using the mouse or programmatically.
+// Right now it only works for vertical layouts and with two subviews.
+//
// Created by Johannes Gilger on 6/21/09.
// Copyright 2009 Johannes Gilger. All rights reserved.
//
@@ -12,6 +16,7 @@
@interface PBCollapsibleSplitView : PBNiceSplitView {
CGFloat topViewMin;
CGFloat bottomViewMin;
+ CGFloat splitterPosition;
}
@property (readonly) CGFloat topViewMin;
@@ -19,5 +24,6 @@
- (void)setTopMin:(CGFloat)topMin andBottomMin:(CGFloat)bottomMin;
- (void)uncollapse;
+- (void)keyDown:(NSEvent *)event;
@end
View
29 PBCollapsibleSplitView.m
@@ -25,4 +25,33 @@ - (void)uncollapse {
}
}
+- (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
View
8 PBCommitList.m
@@ -18,10 +18,16 @@ - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL) local
return NSDragOperationCopy;
}
-- (void) keyDown: (id) event
+- (void)keyDown:(NSEvent *)event
{
NSString* character = [event charactersIgnoringModifiers];
+ // Pass on command-shift up/down to the responder. We want the splitview to capture this.
+ if ([event modifierFlags] & NSShiftKeyMask && [event modifierFlags] & NSCommandKeyMask && ([event keyCode] == 0x7E || [event keyCode] == 0x7D)) {
+ [self.nextResponder keyDown:event];
+ return;
+ }
+
if ([character isEqualToString:@" "])
{
if ([event modifierFlags] & NSShiftKeyMask)
Please sign in to comment.
Something went wrong with that request. Please try again.