Anonymous avatar Anonymous committed 0eddbd9

Anchored button bar - resize handle now moves to the left when the bar is in the right-most pane

Comments (0)

Files changed (2)

BWAnchoredButtonBar.h

 
 @interface BWAnchoredButtonBar : NSView 
 {
-	BOOL isResizable;
-	BOOL isAtBottom;
+	BOOL isResizable, isAtBottom, handleIsRightAligned;
 	int selectedIndex;
 	id splitViewDelegate;
 }
 
-@property BOOL isResizable;
-@property BOOL isAtBottom;
+@property BOOL isResizable, isAtBottom, handleIsRightAligned;
 @property int selectedIndex;
 
 // The mode of this bar with a resize handle makes use of some NSSplitView delegate methods. Use the splitViewDelegate for any custom delegate implementations

BWAnchoredButtonBar.m

 @interface BWAnchoredButtonBar (BWABBPrivate)
 - (void)drawResizeHandleInRect:(NSRect)handleRect withColor:(NSColor *)color;
 - (void)drawLastButtonInsetInRect:(NSRect)rect;
+- (BOOL)isInLastSubview;
+- (NSSplitView *)splitView;
 @end
 
 @implementation BWAnchoredButtonBar
 
-@synthesize selectedIndex, isAtBottom, isResizable, splitViewDelegate;
+@synthesize selectedIndex, isAtBottom, isResizable, handleIsRightAligned, splitViewDelegate;
 
 + (void)initialize;
 {
 	{
 		[self setIsResizable:[decoder decodeBoolForKey:@"BWABBIsResizable"]];
 		[self setIsAtBottom:[decoder decodeBoolForKey:@"BWABBIsAtBottom"]];
+		[self setHandleIsRightAligned:[decoder decodeBoolForKey:@"BWABBHandleIsRightAligned"]];
 		[self setSelectedIndex:[decoder decodeIntForKey:@"BWABBSelectedIndex"]];
 	}
 	return self;
 	
 	[coder encodeBool:[self isResizable] forKey:@"BWABBIsResizable"];
 	[coder encodeBool:[self isAtBottom] forKey:@"BWABBIsAtBottom"];
+	[coder encodeBool:[self handleIsRightAligned] forKey:@"BWABBHandleIsRightAligned"];
 	[coder encodeInt:[self selectedIndex] forKey:@"BWABBSelectedIndex"];
 }
 
 {
 	scaleFactor = [[NSScreen mainScreen] userSpaceScaleFactor];
 	
-	// Iterate through superviews, see if we're in a split view, and set its delegate
-	NSSplitView *splitView = nil;
-	id currentView = self;
-	
-	while (![currentView isKindOfClass:[NSSplitView class]] && currentView != nil)
-	{
-		currentView = [currentView superview];
-		if ([currentView isKindOfClass:[NSSplitView class]])
-			splitView = currentView;
-	}
+	// See if we're in a split view, and set its delegate
+	NSSplitView *splitView = [self splitView];
 	
 	if (splitView != nil && [splitView isVertical] && [self isResizable])
 		[splitView setDelegate:self];
 	if (isResizable)
 	{
 		NSRect handleRect = NSMakeRect(NSMaxX(rect)-11,6,6,10);
+		
+		if ([self handleIsRightAligned])
+			handleRect.origin.x = 4;
+		
 		[self drawResizeHandleInRect:handleRect withColor:resizeHandleColor];
 		
 		NSRect insetRect = NSOffsetRect(handleRect,1,-1);
 	}
 }
 
+- (void)viewDidMoveToSuperview
+{
+	if ([self splitView] != nil)
+		self.handleIsRightAligned = [self isInLastSubview];
+}
+
+- (BOOL)isInLastSubview
+{
+	// This method could be made more robust. Right now it assumes that the button bar's direct parent is the split view.
+	if ([self splitView] != nil && [self superview] == [[[self splitView] subviews] lastObject])
+		return YES;
+	
+	return NO;
+}
+
+- (NSSplitView *)splitView
+{
+	NSSplitView *splitView = nil;
+	id currentView = self;
+	
+	while (![currentView isKindOfClass:[NSSplitView class]] && currentView != nil)
+	{
+		currentView = [currentView superview];
+		if ([currentView isKindOfClass:[NSSplitView class]])
+			splitView = currentView;
+	}
+	
+	return splitView;
+}
+
 - (void)setIsAtBottom:(BOOL)flag
 {
 	isAtBottom = flag;
 	NSRect paddedHandleRect;
 	paddedHandleRect.origin.y = [aSplitView frame].size.height - [self frame].origin.y - [self bounds].size.height;
 	paddedHandleRect.origin.x = NSMaxX([self bounds]) - 15;
+	
+	if (self.handleIsRightAligned)
+		paddedHandleRect.origin.x = [aSplitView frame].size.width - [self bounds].size.width;
+	
 	paddedHandleRect.size.width = 15;
 	paddedHandleRect.size.height = [self bounds].size.height;
 	
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.