Commits

Anonymous committed 08efeb2

Anchored button bar - Fixed issue where inspector wasn't updating properly

Comments (0)

Files changed (2)

BWAnchoredButtonBarInspector.h

 	IBOutlet NSMatrix *matrix;
 	IBOutlet NSImageView *selectionView;
 	IBOutlet NSView *contentView;
+	
+	BOOL isAnimating;
 }
 
 - (IBAction)selectMode1:(id)sender;
 - (IBAction)selectMode2:(id)sender;
 - (IBAction)selectMode3:(id)sender;
+- (void)selectMode:(int)modeIndex withAnimation:(BOOL)shouldAnimate;
 
 @end

BWAnchoredButtonBarInspector.m

 //
 
 #import "BWAnchoredButtonBarInspector.h"
+#import "BWAnchoredButtonBar.h"
 
 @implementation BWAnchoredButtonBarInspector
 
 - (void)refresh 
 {
 	[super refresh];
+	
+	if ([[self inspectedObjects] count] > 0 && !isAnimating)
+	{
+		BWAnchoredButtonBar *inspectedButtonBar = [[self inspectedObjects] lastObject];
+		
+		if ([inspectedButtonBar selectedIndex] == 0)
+			[self selectMode:1 withAnimation:NO];
+		else if ([inspectedButtonBar selectedIndex] == 1)
+			[self selectMode:2 withAnimation:NO];
+		else
+			[self selectMode:3 withAnimation:NO];
+	}
 }
 
 - (IBAction)selectMode1:(id)sender
 {
-	float xOrigin = matrix.frame.origin.x-1;
-	float deltaX = fabsf(xOrigin - selectionView.frame.origin.x);
-	float doubleSpaceMultiplier = 1;
-	
-	if (deltaX > 65)
-		doubleSpaceMultiplier = 1.5;
-	
-	float duration = 0.1*doubleSpaceMultiplier;
-	
-	[NSAnimationContext beginGrouping];
-	[[NSAnimationContext currentContext] setDuration:(duration)];
-	[[selectionView animator] setFrameOrigin:NSMakePoint(xOrigin,selectionView.frame.origin.y)];
-	[NSAnimationContext endGrouping];
+	[self selectMode:1 withAnimation:YES];
 }
 
 - (IBAction)selectMode2:(id)sender
 {
-	float xOrigin = matrix.frame.origin.x + NSWidth(matrix.frame) / matrix.numberOfColumns;
-	float deltaX = fabsf(xOrigin - selectionView.frame.origin.x);
-	float doubleSpaceMultiplier = 1;
-	
-	if (deltaX > 65)
-		doubleSpaceMultiplier = 1.5;
-	
-	float duration = 0.1*doubleSpaceMultiplier;
-	
-	[NSAnimationContext beginGrouping];
-	[[NSAnimationContext currentContext] setDuration:(duration)];
-	[[selectionView animator] setFrameOrigin:NSMakePoint(xOrigin,selectionView.frame.origin.y)];
-	[NSAnimationContext endGrouping];
+	[self selectMode:2 withAnimation:YES];
 }
 
 - (IBAction)selectMode3:(id)sender
 {
-	float xOrigin = NSMaxX(matrix.frame) - NSWidth(matrix.frame) / matrix.numberOfColumns + matrix.numberOfColumns - 1;
-	float deltaX = fabsf(xOrigin - selectionView.frame.origin.x);
-	float doubleSpaceMultiplier = 1;
+	[self selectMode:3 withAnimation:YES];
+}
+
+- (void)selectMode:(int)modeIndex withAnimation:(BOOL)shouldAnimate
+{
+	float xOrigin;
 	
-	if (deltaX > 65)
-		doubleSpaceMultiplier = 1.5;
+	if (modeIndex == 1)
+		xOrigin = roundf(matrix.frame.origin.x-1);
+	else if (modeIndex == 2)
+		xOrigin = roundf(matrix.frame.origin.x + NSWidth(matrix.frame) / matrix.numberOfColumns);
+	else
+		xOrigin = roundf(NSMaxX(matrix.frame) - NSWidth(matrix.frame) / matrix.numberOfColumns + matrix.numberOfColumns - 1);
 	
-	float duration = 0.1*doubleSpaceMultiplier;
-	
-	[NSAnimationContext beginGrouping];
-	[[NSAnimationContext currentContext] setDuration:(duration)];
-	[[selectionView animator] setFrameOrigin:NSMakePoint(xOrigin,selectionView.frame.origin.y)];
-	[NSAnimationContext endGrouping];
+	if (shouldAnimate)
+	{
+		float deltaX = fabsf(xOrigin - selectionView.frame.origin.x);
+		float doubleSpaceMultiplier = 1;
+		
+		if (deltaX > 65)
+			doubleSpaceMultiplier = 1.5;
+		
+		float duration = 0.1*doubleSpaceMultiplier;
+		
+		isAnimating = YES;
+		
+		[NSAnimationContext beginGrouping];
+		[[NSAnimationContext currentContext] setDuration:(duration)];
+		[[selectionView animator] setFrameOrigin:NSMakePoint(xOrigin,selectionView.frame.origin.y)];
+		[NSAnimationContext endGrouping];
+		
+		[self performSelector:@selector(selectionAnimationDidEnd) withObject:nil afterDelay:duration];
+	}
+	else
+	{
+		[selectionView setFrameOrigin:NSMakePoint(xOrigin,selectionView.frame.origin.y)];
+	}
+}
+
+- (void)selectionAnimationDidEnd
+{
+	isAnimating = NO;
 }
 
 @end
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.