Steve Streeting avatar Steve Streeting committed 7dca27b

Support starting up the selectable toolbar with a non-default item

Comments (0)

Files changed (2)

BWSelectableToolbar.h

 	// For the IB inspector
 	int selectedIndex;
 	BOOL isPreferencesToolbar;
+	
+	// SJS 
+	NSString* itemToSelectOnLoad;
 }
 
 // Call one of these methods to set the active tab. 

BWSelectableToolbar.m

 	// When the window launches, we want to select the toolbar item that was previously selected.
 	// So we have to find the toolbar index for our saved selected identifier.
 	int toolbarIndex;
-	
-	if ([helper selectedIdentifier] != nil)
+
+	if (itemToSelectOnLoad)
+	{
+		// Necessary to allow starting up the window with a tab selected
+		toolbarIndex = [itemIdentifiers indexOfObject:itemToSelectOnLoad];
+		itemToSelectOnLoad = nil;
+	}
+	else if ([helper selectedIdentifier] != nil)
 		toolbarIndex = [itemIdentifiers indexOfObject:[helper selectedIdentifier]];
 	else
 		toolbarIndex = [self toolbarIndexFromSelectableIndex:0];
 		
 	}
 
-	
 	if ([helper selectedIdentifier] != nil && [helper contentViewsByIdentifier].count != 0)
 	{
 		// When the actual app is ran or an item is added or removed from the toolbar in IB, we need to select the previously stored identifier
 	
 	if (validIdentifier)
 		[self switchToItemAtIndex:[itemIdentifiers indexOfObject:itemIdentifier] animate:NO];
+	else if ([itemIdentifiers count] == 0)
+	{
+		// not initialised yet
+		itemToSelectOnLoad = itemIdentifier;
+	}
 }
 
 - (void)setEnabled:(BOOL)flag forIdentifier:(NSString *)itemIdentifier
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.