From 2dbae24c7735ead0524bd9847af6ea99d8654ec6 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Sat, 14 May 2011 17:26:18 +0000 Subject: Bring outline view branch up to date with trunk (r3279:r3306). --- Source/SPWindowController.m | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) (limited to 'Source/SPWindowController.m') diff --git a/Source/SPWindowController.m b/Source/SPWindowController.m index e9b73491..ed18335d 100644 --- a/Source/SPWindowController.m +++ b/Source/SPWindowController.m @@ -42,7 +42,7 @@ /** * awakeFromNib */ -- (void) awakeFromNib +- (void)awakeFromNib { selectedTableDocument = nil; @@ -67,9 +67,13 @@ [tabBar setTearOffStyle:PSMTabBarTearOffAlphaWindow]; [tabBar setUsesSafariStyleDragging:YES]; - // hook up add tab button + // Hook up add tab button [tabBar setCreateNewTabTarget:self]; [tabBar setCreateNewTabAction:@selector(addNewConnection:)]; + + // Set the double click target and action + [tabBar setDoubleClickTarget:self]; + [tabBar setDoubleClickAction:@selector(openDatabaseInNewTab)]; // Retrieve references to the 'Close Window' and 'Close Tab' menus. These are updated as window focus changes. closeWindowMenuItem = [[[[NSApp mainMenu] itemWithTag:SPMainMenuFile] submenu] itemWithTag:1003]; @@ -100,7 +104,6 @@ */ - (IBAction) addNewConnection:(id)sender { - // Create a new database connection view SPDatabaseDocument *newTableDocument = [[SPDatabaseDocument alloc] init]; [newTableDocument setParentWindowController:self]; @@ -160,14 +163,14 @@ */ - (IBAction) closeTab:(id)sender { - // Return if the selected tab shouldn't be closed if (![selectedTableDocument parentTabShouldClose]) return; // If there are multiple tabs, close the front tab. if ([tabView numberOfTabViewItems] > 1) { [tabView removeTabViewItem:[tabView selectedTabViewItem]]; - } else { + } + else { [[self window] performClose:self]; } } @@ -326,11 +329,22 @@ } } + - (void)setHideForSingleTab:(BOOL)hide { [tabBar setHideForSingleTab:hide]; } +/** + * Opens the current connection in a new tab, but only if it's already connected. + */ +- (void)openDatabaseInNewTab +{ + if ([selectedTableDocument database]) { + [selectedTableDocument openDatabaseInNewTab:self]; + } +} + #pragma mark - #pragma mark Tab view delegate methods @@ -571,6 +585,20 @@ return [viewImage autorelease]; } +/** + * Displays the current tab's context menu. + */ +- (NSMenu *)tabView:(NSTabView *)aTabView menuForTabViewItem:(NSTabViewItem *)tabViewItem +{ + NSMenu *menu = [[NSMenu alloc] init]; + + [menu addItemWithTitle:NSLocalizedString(@"Close Tab", @"close tab context menu item") action:@selector(closeTab:) keyEquivalent:@""]; + [menu insertItem:[NSMenuItem separatorItem] atIndex:1]; + [menu addItemWithTitle:NSLocalizedString(@"Open in New Tab", @"open connection in new tab context menu item") action:@selector(openDatabaseInNewTab:) keyEquivalent:@""]; + + return [menu autorelease]; +} + /** * When tab drags start, show all the tab bars. This allows adding tabs to windows * containing only one tab - where the bar is normally hidden. -- cgit v1.2.3