diff options
author | Bibiko <bibiko@eva.mpg.de> | 2010-06-16 12:39:48 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2010-06-16 12:39:48 +0000 |
commit | 630002af8fffbce120392df5eba3cd57e1c67040 (patch) | |
tree | 8b561c1d85f6a045f35bc0810b9653e2cff912cc /Source | |
parent | 63f30386aa21d2bb74233698c0b8a3d72333858d (diff) | |
download | sequelpro-630002af8fffbce120392df5eba3cd57e1c67040.tar.gz sequelpro-630002af8fffbce120392df5eba3cd57e1c67040.tar.bz2 sequelpro-630002af8fffbce120392df5eba3cd57e1c67040.zip |
• added Window menu item "Move Tab to New Window"
- it moves the SPDatabaseDocument of the currently selected tab to a new window
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPWindowController.h | 2 | ||||
-rw-r--r-- | Source/SPWindowController.m | 95 |
2 files changed, 83 insertions, 14 deletions
diff --git a/Source/SPWindowController.h b/Source/SPWindowController.h index 28186901..88b3e3a2 100644 --- a/Source/SPWindowController.h +++ b/Source/SPWindowController.h @@ -39,7 +39,7 @@ // Database connection management - (IBAction) addNewConnection:(id)sender; -- (IBAction) openSelectedTabInNewWindow:(id)sender; +- (IBAction) moveSelectedTabInNewWindow:(id)sender; - (SPDatabaseDocument *) selectedTableDocument; - (void) updateSelectedTableDocument; - (void) updateAllTabTitles:(id)sender; diff --git a/Source/SPWindowController.m b/Source/SPWindowController.m index eaa98997..e5e2ca13 100644 --- a/Source/SPWindowController.m +++ b/Source/SPWindowController.m @@ -153,7 +153,7 @@ /** * Close the current tab, or if it's the last in the window, the window. */ -- (IBAction)closeTab:(id)sender +- (IBAction) closeTab:(id)sender { // Return if the selected tab shouldn't be closed @@ -170,7 +170,7 @@ /** * Select next tab; if last select first one. */ -- (IBAction)selectNextDocumentTab:(id)sender +- (IBAction) selectNextDocumentTab:(id)sender { if([tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == [tabView numberOfTabViewItems] - 1) [tabView selectFirstTabViewItem:nil]; @@ -181,7 +181,7 @@ /** * Select previous tab; if first select last one. */ -- (IBAction)selectPreviousDocumentTab:(id)sender +- (IBAction) selectPreviousDocumentTab:(id)sender { if([tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 0) [tabView selectLastTabViewItem:nil]; @@ -190,18 +190,92 @@ } /** - * Menu validation + * Move the currently selected tab to a new window. */ -- (BOOL)validateMenuItem:(NSMenuItem *)menuItem +- (IBAction) moveSelectedTabInNewWindow:(id)sender { - // Select Next/Previous Tab - if ([menuItem action] == @selector(selectPreviousDocumentTab:) || [menuItem action] == @selector(selectNextDocumentTab:)) { - return ([tabView numberOfTabViewItems] != 1); + + static NSPoint cascadeLocation = {.x = 0, .y = 0}; + + SPDatabaseDocument *selectedDocument = [[tabView selectedTabViewItem] identifier]; + NSTabViewItem *selectedTabViewItem = [tabView selectedTabViewItem]; + PSMTabBarCell *selectedCell = [[tabBar cells] objectAtIndex:[tabView indexOfTabViewItem:selectedTabViewItem]]; + + SPWindowController *newWindowController = [[SPWindowController alloc] initWithWindowNibName:@"MainWindow"]; + NSWindow *newWindow = [newWindowController window]; + + CGFloat toolbarHeight = 0; + if ([[[self window] toolbar] isVisible]) { + NSRect innerFrame = [NSWindow contentRectForFrameRect:[[self window] frame] styleMask:[[self window] styleMask]]; + toolbarHeight = innerFrame.size.height - [[[self window] contentView] frame].size.height; } + // Set the new window position and size + NSRect targetWindowFrame = [[self window] frame]; + targetWindowFrame.size.height -= toolbarHeight; + [newWindow setFrame:targetWindowFrame display:NO]; + + // Cascade according to the statically stored cascade location. + cascadeLocation = [newWindow cascadeTopLeftFromPoint:cascadeLocation]; + + // Set the window controller as the window's delegate + [newWindow setDelegate:newWindowController]; + + // Set window title + [newWindow setTitle:[[[[tabView selectedTabViewItem] identifier] parentWindow] title]]; + + // New window's tabBar control + PSMTabBarControl *control = [newWindowController valueForKey:@"tabBar"]; + + // Add the selected tab to the new window + [[control cells] insertObject:selectedCell atIndex:0]; + + // Remove 'isProcessing' observer from old windowController + [selectedDocument removeObserver:self forKeyPath:@"isProcessing"]; + + // Update new 'isProcessing' observer and bind the new tab bar's progress display to the document + [self _updateProgressIndicatorForItem:selectedTabViewItem]; + + //remove the tracking rects and bindings registered on the old tab + [tabBar removeTrackingRect:[selectedCell closeButtonTrackingTag]]; + [tabBar removeTrackingRect:[selectedCell cellTrackingTag]]; + [tabBar removeTabForCell:selectedCell]; + + //rebind the selected cell to the new control + [control bindPropertiesForCell:selectedCell andTabViewItem:selectedTabViewItem]; + + [selectedCell setControlView:control]; + + [[tabBar tabView] removeTabViewItem:[selectedCell representedObject]]; + + [[control tabView] addTabViewItem:selectedTabViewItem]; + + [control update:NO]; //make sure the new tab is set in the correct position + + // Update tabBar of the new window + [newWindowController tabView:[tabBar tabView] didDropTabViewItem:[selectedCell representedObject] inTabBar:control]; + + [newWindow makeKeyAndOrderFront:nil]; + +} + +/** + * Menu validation + */ +- (BOOL) validateMenuItem:(NSMenuItem *)menuItem +{ + // See if the front document blocks validation of this item if (![selectedTableDocument validateMenuItem:menuItem]) return NO; + // Select Next/Previous/Move Tab + if ( [menuItem action] == @selector(selectPreviousDocumentTab:) + || [menuItem action] == @selector(selectNextDocumentTab:) + || [menuItem action] == @selector(moveSelectedTabInNewWindow:)) + { + return ([tabView numberOfTabViewItems] != 1); + } + return YES; } @@ -475,11 +549,6 @@ [tabBar setHideForSingleTab:YES]; } -- (IBAction) openSelectedTabInNewWindow:(id)sender -{ - // not yet implemented -} - #pragma mark - #pragma mark Window delegate methods |