aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/SPAppController.h22
-rw-r--r--Source/SPAppController.m240
-rw-r--r--Source/SPAppleScriptSupport.h41
-rw-r--r--Source/SPAppleScriptSupport.m128
-rw-r--r--Source/SPContentFilterManager.m1
-rw-r--r--Source/SPDatabaseDocument.m1
-rw-r--r--Source/SPNavigatorController.m1
-rw-r--r--Source/SPQueryDocumentsController.m1
-rw-r--r--Source/SPQueryFavoriteManager.m1
-rw-r--r--Source/SPTablesList.m1
-rw-r--r--Source/SPTextViewAdditions.m1
-rw-r--r--Source/SPWindowManagement.h55
-rw-r--r--Source/SPWindowManagement.m182
-rw-r--r--sequel-pro.xcodeproj/project.pbxproj12
14 files changed, 261 insertions, 426 deletions
diff --git a/Source/SPAppController.h b/Source/SPAppController.h
index 4dd93839..818a781c 100644
--- a/Source/SPAppController.h
+++ b/Source/SPAppController.h
@@ -37,6 +37,7 @@
@class SPAboutController;
@class SPDatabaseDocument;
@class SPBundleEditorController;
+@class SPWindowController;
@interface SPAppController : NSObject <FRFeedbackReporterDelegate, NSApplicationDelegate, NSOpenSavePanelDelegate, NSFileManagerDelegate>
{
@@ -116,4 +117,25 @@
- (void)addHTMLOutputController:(id)controller;
- (void)removeHTMLOutputController:(id)controller;
+#pragma mark - SPAppleScriptSupport
+
+- (NSArray *)orderedDocuments;
+- (void)insertInOrderedDocuments:(SPDatabaseDocument *)doc;
+- (NSArray *)orderedWindows;
+- (id)handleQuitScriptCommand:(NSScriptCommand *)command;
+- (id)handleOpenScriptCommand:(NSScriptCommand *)command;
+
+#pragma mark - SPWindowManagement
+
+- (IBAction)newWindow:(id)sender;
+- (IBAction)newTab:(id)sender;
+- (IBAction)duplicateTab:(id)sender;
+
+- (SPWindowController *)newWindow;
+- (SPDatabaseDocument *)makeNewConnectionTabOrWindow;
+- (SPWindowController *)frontController;
+
+- (NSWindow *)frontDocumentWindow;
+- (void)tabDragStarted:(id)sender;
+
@end
diff --git a/Source/SPAppController.m b/Source/SPAppController.m
index afdfd16f..58080265 100644
--- a/Source/SPAppController.m
+++ b/Source/SPAppController.m
@@ -47,10 +47,10 @@
#import "SPFavoritesController.h"
#import "SPEditorTokens.h"
#import "SPBundleCommandRunner.h"
-#import "SPWindowManagement.h"
#import "SPCopyTable.h"
#import "SPSyntaxParser.h"
#import "SPOSInfo.h"
+#import "SPPrintController.h"
#import <PSMTabBar/PSMTabBarControl.h>
#import <Sparkle/Sparkle.h>
@@ -2329,6 +2329,244 @@
}
}
+#pragma mark - SPAppleScriptSupport
+
+/**
+ * Is needed to interact with AppleScript for set/get internal SP variables
+ */
+- (BOOL)application:(NSApplication *)sender delegateHandlesKey:(NSString *)key
+{
+ NSLog(@"Not yet implemented.");
+
+ return NO;
+}
+
+/**
+ * AppleScript call to get the available documents.
+ */
+- (NSArray *)orderedDocuments
+{
+ NSMutableArray *orderedDocuments = [NSMutableArray array];
+
+ for (NSWindow *aWindow in [self orderedWindows])
+ {
+ if ([[aWindow windowController] isMemberOfClass:[SPWindowController class]]) {
+ [orderedDocuments addObjectsFromArray:[[aWindow windowController] documents]];
+ }
+ }
+
+ return orderedDocuments;
+}
+
+/**
+ * AppleScript support for 'make new document'.
+ *
+ * TODO: following tab support this has been disabled - need to discuss reimplmenting vs syntax.
+ */
+- (void)insertInOrderedDocuments:(SPDatabaseDocument *)doc
+{
+ [self newWindow:self];
+
+ // Set autoconnection if appropriate
+ if ([[NSUserDefaults standardUserDefaults] boolForKey:SPAutoConnectToDefault]) {
+ [[self frontDocument] connect];
+ }
+}
+
+/**
+ * AppleScript call to get the available windows.
+ */
+- (NSArray *)orderedWindows
+{
+ return [NSApp orderedWindows];
+}
+
+/**
+ * AppleScript handler to quit Sequel Pro
+ *
+ * This handler is required to allow termination via the Dock or AppleScript event after activating it using AppleScript
+ */
+- (id)handleQuitScriptCommand:(NSScriptCommand *)command
+{
+ [NSApp terminate:self];
+
+ return nil;
+}
+
+/**
+ * AppleScript open handler
+ *
+ * This handler is required to catch the 'open' command if no argument was passed which would cause a crash.
+ */
+- (id)handleOpenScriptCommand:(NSScriptCommand *)command
+{
+ return nil;
+}
+
+/**
+ * AppleScript print handler
+ *
+ * This handler prints the active view.
+ */
+- (id)handlePrintScriptCommand:(NSScriptCommand *)command
+{
+ SPDatabaseDocument *frontDoc = [self frontDocument];
+
+ if (frontDoc && ![frontDoc isWorking] && ![[frontDoc connectionID] isEqualToString:@"_"]) {
+ [frontDoc startPrintDocumentOperation];
+ }
+
+ return nil;
+}
+
+#pragma mark - SPWindowManagement
+
+- (IBAction)newWindow:(id)sender
+{
+ [self newWindow];
+}
+
+/**
+ * Create a new window, containing a single tab.
+ */
+- (SPWindowController *)newWindow
+{
+ static NSPoint cascadeLocation = {.x = 0, .y = 0};
+
+ // Create a new window controller, and set up a new connection view within it.
+ SPWindowController *newWindowController = [[SPWindowController alloc] initWithWindowNibName:@"MainWindow"];
+ NSWindow *newWindow = [newWindowController window];
+
+ // Cascading defaults to on - retrieve the window origin automatically assigned by cascading,
+ // and convert to a top left point.
+ NSPoint topLeftPoint = [newWindow frame].origin;
+ topLeftPoint.y += [newWindow frame].size.height;
+
+ // The first window should use autosaving; subsequent windows should cascade.
+ // So attempt to set the frame autosave name; this will succeed for the very
+ // first window, and fail for others.
+ BOOL usedAutosave = [newWindow setFrameAutosaveName:@"DBView"];
+
+ if (!usedAutosave) {
+ [newWindow setFrameUsingName:@"DBView"];
+ }
+
+ // Add the connection view
+ [newWindowController addNewConnection];
+
+ // Cascade according to the statically stored cascade location.
+ cascadeLocation = [newWindow cascadeTopLeftFromPoint:cascadeLocation];
+
+ // Set the window controller as the window's delegate
+ [newWindow setDelegate:newWindowController];
+
+ // Show the window, and perform frontmost tasks again once the window has drawn
+ [newWindowController showWindow:self];
+ [[newWindowController selectedTableDocument] didBecomeActiveTabInWindow];
+
+ return newWindowController;
+}
+
+/**
+ * Create a new tab in the frontmost window.
+ */
+- (IBAction)newTab:(id)sender
+{
+ SPWindowController *frontController = [self frontController];
+
+ // If no window was found, create a new one
+ if (!frontController) {
+ [self newWindow:self];
+ }
+ else {
+ if ([[frontController window] isMiniaturized]) {
+ [[frontController window] deminiaturize:self];
+ }
+
+ [frontController addNewConnection:self];
+ }
+}
+
+- (SPDatabaseDocument *)makeNewConnectionTabOrWindow
+{
+ SPWindowController *frontController = [self frontController];
+
+ SPDatabaseDocument *frontDocument;
+ // If no window was found or the front most window has no tabs, create a new one
+ if (!frontController || [[frontController valueForKeyPath:@"tabView"] numberOfTabViewItems] == 1) {
+ frontController = [self newWindow];
+ frontDocument = [frontController selectedTableDocument];
+ }
+ // Open the spf file in a new tab if the tab bar is visible
+ else {
+ if ([[frontController window] isMiniaturized]) [[frontController window] deminiaturize:self];
+ frontDocument = [frontController addNewConnection];
+ }
+
+ return frontDocument;
+}
+
+/**
+ * Duplicate the current connection tab
+ */
+- (IBAction)duplicateTab:(id)sender
+{
+ SPDatabaseDocument *theFrontDocument = [self frontDocument];
+
+ if (!theFrontDocument) return [self newTab:sender];
+
+ // Add a new tab to the window
+ if ([[self frontDocumentWindow] isMiniaturized]) {
+ [[self frontDocumentWindow] deminiaturize:self];
+ }
+
+ SPDatabaseDocument *newConnection = [[self frontController] addNewConnection];
+
+ // Get the state of the previously-frontmost document
+ NSDictionary *allStateDetails = @{
+ @"connection" : @YES,
+ @"history" : @YES,
+ @"session" : @YES,
+ @"query" : @YES,
+ @"password" : @YES
+ };
+
+ NSMutableDictionary *frontState = [NSMutableDictionary dictionaryWithDictionary:[theFrontDocument stateIncludingDetails:allStateDetails]];
+
+ // Ensure it's set to autoconnect
+ [frontState setObject:@YES forKey:@"auto_connect"];
+
+ // Set the connection on the new tab
+ [newConnection setState:frontState];
+}
+
+/**
+ * Retrieve the frontmost document window; returns nil if not found.
+ */
+- (NSWindow *)frontDocumentWindow
+{
+ return [[self frontController] window];
+}
+
+- (SPWindowController *)frontController
+{
+ for (NSWindow *aWindow in [NSApp orderedWindows]) {
+ id ctr = [aWindow windowController];
+ if ([ctr isMemberOfClass:[SPWindowController class]]) {
+ return ctr;
+ }
+ }
+ return nil;
+}
+
+/**
+ * When tab drags start, bring all the windows in front of other applications.
+ */
+- (void)tabDragStarted:(id)sender
+{
+ [NSApp arrangeInFront:self];
+}
+
#pragma mark -
- (void)dealloc
diff --git a/Source/SPAppleScriptSupport.h b/Source/SPAppleScriptSupport.h
deleted file mode 100644
index 463a4b19..00000000
--- a/Source/SPAppleScriptSupport.h
+++ /dev/null
@@ -1,41 +0,0 @@
-//
-// SPAppleScriptSupport.h
-// sequel-pro
-//
-// Created by Stuart Connolly (stuconnolly.com) on October 14, 2010.
-// Copyright (c) 2010 Stuart Connolly. All rights reserved.
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
-// More info at <https://github.com/sequelpro/sequelpro>
-
-#import "SPAppController.h"
-
-@interface SPAppController (SPAppleScriptSupport)
-
-- (NSArray *)orderedDocuments;
-- (void)insertInOrderedDocuments:(SPDatabaseDocument *)doc;
-- (NSArray *)orderedWindows;
-- (id)handleQuitScriptCommand:(NSScriptCommand *)command;
-- (id)handleOpenScriptCommand:(NSScriptCommand *)command;
-
-@end
diff --git a/Source/SPAppleScriptSupport.m b/Source/SPAppleScriptSupport.m
deleted file mode 100644
index 17b9e436..00000000
--- a/Source/SPAppleScriptSupport.m
+++ /dev/null
@@ -1,128 +0,0 @@
-//
-// SPAppleScriptSupport.m
-// sequel-pro
-//
-// Created by Stuart Connolly (stuconnolly.com) on October 14, 2010.
-// Copyright (c) 2010 Stuart Connolly. All rights reserved.
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
-// More info at <https://github.com/sequelpro/sequelpro>
-
-#import "SPAppleScriptSupport.h"
-#import "SPWindowController.h"
-#import "SPAppController.h"
-#import "SPPrintController.h"
-#import "SPDatabaseDocument.h"
-#import "SPWindowManagement.h"
-
-@implementation SPAppController (SPAppleScriptSupport)
-
-/**
- * Is needed to interact with AppleScript for set/get internal SP variables
- */
-- (BOOL)application:(NSApplication *)sender delegateHandlesKey:(NSString *)key
-{
- NSLog(@"Not yet implemented.");
-
- return NO;
-}
-
-/**
- * AppleScript call to get the available documents.
- */
-- (NSArray *)orderedDocuments
-{
- NSMutableArray *orderedDocuments = [NSMutableArray array];
-
- for (NSWindow *aWindow in [self orderedWindows])
- {
- if ([[aWindow windowController] isMemberOfClass:[SPWindowController class]]) {
- [orderedDocuments addObjectsFromArray:[[aWindow windowController] documents]];
- }
- }
-
- return orderedDocuments;
-}
-
-/**
- * AppleScript support for 'make new document'.
- *
- * TODO: following tab support this has been disabled - need to discuss reimplmenting vs syntax.
- */
-- (void)insertInOrderedDocuments:(SPDatabaseDocument *)doc
-{
- [self newWindow:self];
-
- // Set autoconnection if appropriate
- if ([[NSUserDefaults standardUserDefaults] boolForKey:SPAutoConnectToDefault]) {
- [[self frontDocument] connect];
- }
-}
-
-/**
- * AppleScript call to get the available windows.
- */
-- (NSArray *)orderedWindows
-{
- return [NSApp orderedWindows];
-}
-
-/**
- * AppleScript handler to quit Sequel Pro
- *
- * This handler is required to allow termination via the Dock or AppleScript event after activating it using AppleScript
- */
-- (id)handleQuitScriptCommand:(NSScriptCommand *)command
-{
- [NSApp terminate:self];
-
- return nil;
-}
-
-/**
- * AppleScript open handler
- *
- * This handler is required to catch the 'open' command if no argument was passed which would cause a crash.
- */
-- (id)handleOpenScriptCommand:(NSScriptCommand *)command
-{
- return nil;
-}
-
-/**
- * AppleScript print handler
- *
- * This handler prints the active view.
- */
-- (id)handlePrintScriptCommand:(NSScriptCommand *)command
-{
- SPDatabaseDocument *frontDoc = [self frontDocument];
-
- if (frontDoc && ![frontDoc isWorking] && ![[frontDoc connectionID] isEqualToString:@"_"]) {
- [frontDoc startPrintDocumentOperation];
- }
-
- return nil;
-}
-
-@end
diff --git a/Source/SPContentFilterManager.m b/Source/SPContentFilterManager.m
index 5dc0c48b..512e19d8 100644
--- a/Source/SPContentFilterManager.m
+++ b/Source/SPContentFilterManager.m
@@ -38,7 +38,6 @@
#import "SPConnectionController.h"
#import "SPSplitView.h"
#import "SPAppController.h"
-#import "SPAppleScriptSupport.h"
static NSString *SPExportFilterAction = @"SPExportFilter";
diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m
index 2a10b900..a82632d0 100644
--- a/Source/SPDatabaseDocument.m
+++ b/Source/SPDatabaseDocument.m
@@ -55,7 +55,6 @@
#import "SPDatabaseData.h"
#import "SPDatabaseStructure.h"
#import "SPAppController.h"
-#import "SPWindowManagement.h"
#import "SPExtendedTableInfo.h"
#import "SPHistoryController.h"
#import "SPPreferenceController.h"
diff --git a/Source/SPNavigatorController.m b/Source/SPNavigatorController.m
index 108727fb..93b4f13d 100644
--- a/Source/SPNavigatorController.m
+++ b/Source/SPNavigatorController.m
@@ -39,7 +39,6 @@
#import "SPLogger.h"
#import "SPTooltip.h"
#import "SPAppController.h"
-#import "SPAppleScriptSupport.h"
#import "SPDatabaseViewController.h"
#import "SPDatabaseStructure.h"
#import "SPThreadAdditions.h"
diff --git a/Source/SPQueryDocumentsController.m b/Source/SPQueryDocumentsController.m
index a9602b61..e4689c41 100644
--- a/Source/SPQueryDocumentsController.m
+++ b/Source/SPQueryDocumentsController.m
@@ -31,7 +31,6 @@
#import "SPQueryDocumentsController.h"
#import "SPCustomQuery.h"
#import "SPAppController.h"
-#import "SPAppleScriptSupport.h"
@implementation SPQueryController (SPQueryDocumentsController)
diff --git a/Source/SPQueryFavoriteManager.m b/Source/SPQueryFavoriteManager.m
index 2f88bbcf..76fdf288 100644
--- a/Source/SPQueryFavoriteManager.m
+++ b/Source/SPQueryFavoriteManager.m
@@ -39,7 +39,6 @@
#import "SPTextView.h"
#import "SPSplitView.h"
#import "SPAppController.h"
-#import "SPAppleScriptSupport.h"
#define SP_MULTIPLE_SELECTION_PLACEHOLDER_STRING NSLocalizedString(@"[multiple selection]", @"[multiple selection]")
#define SP_NO_SELECTION_PLACEHOLDER_STRING NSLocalizedString(@"[no selection]", @"[no selection]")
diff --git a/Source/SPTablesList.m b/Source/SPTablesList.m
index 34d1dfcb..6096b493 100644
--- a/Source/SPTablesList.m
+++ b/Source/SPTablesList.m
@@ -52,7 +52,6 @@
#import "SPThreadAdditions.h"
#import "SPFunctions.h"
#import "SPCharsetCollationHelper.h"
-#import "SPWindowManagement.h"
#import <SPMySQL/SPMySQL.h>
diff --git a/Source/SPTextViewAdditions.m b/Source/SPTextViewAdditions.m
index 88096a8f..a81dcd4d 100644
--- a/Source/SPTextViewAdditions.m
+++ b/Source/SPTextViewAdditions.m
@@ -36,7 +36,6 @@
#import "SPCustomQuery.h"
#ifndef SP_CODA /* headers */
#import "SPAppController.h"
-#import "SPWindowManagement.h"
#endif
#import "SPFieldEditorController.h"
#import "SPTextView.h"
diff --git a/Source/SPWindowManagement.h b/Source/SPWindowManagement.h
deleted file mode 100644
index 4d32d6d4..00000000
--- a/Source/SPWindowManagement.h
+++ /dev/null
@@ -1,55 +0,0 @@
-//
-// SPWindowManagement.h
-// sequel-pro
-//
-// Created by Stuart Connolly (stuconnolly.com) on July 7, 2012.
-// Copyright (c) 2012 Stuart Connolly. All rights reserved.
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
-// More info at <https://github.com/sequelpro/sequelpro>
-
-#import "SPAppController.h"
-
-@class SPWindowController;
-
-/**
- * @category SPWindowManagement SPWindowManagement.h
- *
- * @author Stuart Connolly http://stuconnolly.com/
- *
- * Contains all of the main window management methods.
- */
-@interface SPAppController (SPWindowManagement)
-
-- (IBAction)newWindow:(id)sender;
-- (IBAction)newTab:(id)sender;
-- (IBAction)duplicateTab:(id)sender;
-
-- (SPWindowController *)newWindow;
-- (SPDatabaseDocument *)makeNewConnectionTabOrWindow;
-- (SPWindowController *)frontController;
-
-- (NSWindow *)frontDocumentWindow;
-- (void)tabDragStarted:(id)sender;
-
-@end
diff --git a/Source/SPWindowManagement.m b/Source/SPWindowManagement.m
deleted file mode 100644
index 6225c52f..00000000
--- a/Source/SPWindowManagement.m
+++ /dev/null
@@ -1,182 +0,0 @@
-//
-// SPWindowManagement.m
-// sequel-pro
-//
-// Created by Stuart Connolly (stuconnolly.com) on July 7, 2012.
-// Copyright (c) 2012 Stuart Connolly. All rights reserved.
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-
-#import "SPWindowManagement.h"
-#import "SPWindowController.h"
-#import "SPDatabaseDocument.h"
-
-@implementation SPAppController (SPWindowManagement)
-
-
-- (IBAction)newWindow:(id)sender
-{
- [self newWindow];
-}
-
-/**
- * Create a new window, containing a single tab.
- */
-- (SPWindowController *)newWindow
-{
- static NSPoint cascadeLocation = {.x = 0, .y = 0};
-
- // Create a new window controller, and set up a new connection view within it.
- SPWindowController *newWindowController = [[SPWindowController alloc] initWithWindowNibName:@"MainWindow"];
- NSWindow *newWindow = [newWindowController window];
-
- // Cascading defaults to on - retrieve the window origin automatically assigned by cascading,
- // and convert to a top left point.
- NSPoint topLeftPoint = [newWindow frame].origin;
- topLeftPoint.y += [newWindow frame].size.height;
-
- // The first window should use autosaving; subsequent windows should cascade.
- // So attempt to set the frame autosave name; this will succeed for the very
- // first window, and fail for others.
- BOOL usedAutosave = [newWindow setFrameAutosaveName:@"DBView"];
-
- if (!usedAutosave) {
- [newWindow setFrameUsingName:@"DBView"];
- }
-
- // Add the connection view
- [newWindowController addNewConnection];
-
- // Cascade according to the statically stored cascade location.
- cascadeLocation = [newWindow cascadeTopLeftFromPoint:cascadeLocation];
-
- // Set the window controller as the window's delegate
- [newWindow setDelegate:newWindowController];
-
- // Show the window, and perform frontmost tasks again once the window has drawn
- [newWindowController showWindow:self];
- [[newWindowController selectedTableDocument] didBecomeActiveTabInWindow];
-
- return newWindowController;
-}
-
-/**
- * Create a new tab in the frontmost window.
- */
-- (IBAction)newTab:(id)sender
-{
- SPWindowController *frontController = [self frontController];
-
- // If no window was found, create a new one
- if (!frontController) {
- [self newWindow:self];
- }
- else {
- if ([[frontController window] isMiniaturized]) {
- [[frontController window] deminiaturize:self];
- }
-
- [frontController addNewConnection:self];
- }
-}
-
-- (SPDatabaseDocument *)makeNewConnectionTabOrWindow
-{
- SPWindowController *frontController = [self frontController];
-
- SPDatabaseDocument *frontDocument;
- // If no window was found or the front most window has no tabs, create a new one
- if (!frontController || [[frontController valueForKeyPath:@"tabView"] numberOfTabViewItems] == 1) {
- frontController = [self newWindow];
- frontDocument = [frontController selectedTableDocument];
- }
- // Open the spf file in a new tab if the tab bar is visible
- else {
- if ([[frontController window] isMiniaturized]) [[frontController window] deminiaturize:self];
- frontDocument = [frontController addNewConnection];
- }
-
- return frontDocument;
-}
-
-/**
- * Duplicate the current connection tab
- */
-- (IBAction)duplicateTab:(id)sender
-{
- SPDatabaseDocument *theFrontDocument = [self frontDocument];
-
- if (!theFrontDocument) return [self newTab:sender];
-
- // Add a new tab to the window
- if ([[self frontDocumentWindow] isMiniaturized]) {
- [[self frontDocumentWindow] deminiaturize:self];
- }
-
- SPDatabaseDocument *newConnection = [[self frontController] addNewConnection];
-
- // Get the state of the previously-frontmost document
- NSDictionary *allStateDetails = @{
- @"connection" : @YES,
- @"history" : @YES,
- @"session" : @YES,
- @"query" : @YES,
- @"password" : @YES
- };
-
- NSMutableDictionary *frontState = [NSMutableDictionary dictionaryWithDictionary:[theFrontDocument stateIncludingDetails:allStateDetails]];
-
- // Ensure it's set to autoconnect
- [frontState setObject:@YES forKey:@"auto_connect"];
-
- // Set the connection on the new tab
- [newConnection setState:frontState];
-}
-
-/**
- * Retrieve the frontmost document window; returns nil if not found.
- */
-- (NSWindow *)frontDocumentWindow
-{
- return [[self frontController] window];
-}
-
-- (SPWindowController *)frontController
-{
- for (NSWindow *aWindow in [NSApp orderedWindows]) {
- id ctr = [aWindow windowController];
- if ([ctr isMemberOfClass:[SPWindowController class]]) {
- return ctr;
- }
- }
- return nil;
-}
-
-/**
- * When tab drags start, bring all the windows in front of other applications.
- */
-- (void)tabDragStarted:(id)sender
-{
- [NSApp arrangeInFront:self];
-}
-
-@end
diff --git a/sequel-pro.xcodeproj/project.pbxproj b/sequel-pro.xcodeproj/project.pbxproj
index 4866e18f..588b5377 100644
--- a/sequel-pro.xcodeproj/project.pbxproj
+++ b/sequel-pro.xcodeproj/project.pbxproj
@@ -61,7 +61,6 @@
173C839511AAD32A00B8B084 /* SPXMLExporterDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 173C838F11AAD32A00B8B084 /* SPXMLExporterDelegate.m */; };
1740FABB0FC4372F00CF3699 /* SPDatabaseData.m in Sources */ = {isa = PBXBuildFile; fileRef = 1740FABA0FC4372F00CF3699 /* SPDatabaseData.m */; };
1748D50C15A4444F003562F2 /* SPTableStructureLoading.m in Sources */ = {isa = PBXBuildFile; fileRef = 1748D50B15A4444F003562F2 /* SPTableStructureLoading.m */; };
- 1748D58615A83E54003562F2 /* SPWindowManagement.m in Sources */ = {isa = PBXBuildFile; fileRef = 1748D58515A83E54003562F2 /* SPWindowManagement.m */; };
174CE11E10AB80B5008F892B /* DatabaseProcessList.xib in Resources */ = {isa = PBXBuildFile; fileRef = 174CE11C10AB80B5008F892B /* DatabaseProcessList.xib */; };
174CE14210AB9281008F892B /* SPProcessListController.m in Sources */ = {isa = PBXBuildFile; fileRef = 174CE14110AB9281008F892B /* SPProcessListController.m */; };
175EC63512733B36009A7C0F /* SPExportControllerDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 175EC63412733B36009A7C0F /* SPExportControllerDelegate.m */; };
@@ -83,7 +82,6 @@
1792C13210AD752100ABE758 /* DatabaseServerVariables.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1792C13010AD752100ABE758 /* DatabaseServerVariables.xib */; };
1792C13710AD75C800ABE758 /* SPServerVariablesController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1792C13610AD75C800ABE758 /* SPServerVariablesController.m */; };
1792C26110AE1A2D00ABE758 /* SPConnectionDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1792C26010AE1A2D00ABE758 /* SPConnectionDelegate.m */; };
- 1798AB911267924D000D946A /* SPAppleScriptSupport.m in Sources */ = {isa = PBXBuildFile; fileRef = 1798AB901267924D000D946A /* SPAppleScriptSupport.m */; };
1798F1871550175B004B0AB8 /* SPFavoritesExporter.m in Sources */ = {isa = PBXBuildFile; fileRef = 1798F1821550175B004B0AB8 /* SPFavoritesExporter.m */; };
1798F1881550175B004B0AB8 /* SPFavoritesImporter.m in Sources */ = {isa = PBXBuildFile; fileRef = 1798F1851550175B004B0AB8 /* SPFavoritesImporter.m */; };
1798F18F1550178E004B0AB8 /* SPConnectionControllerDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 1798F18A1550178E004B0AB8 /* SPConnectionControllerDataSource.m */; };
@@ -734,8 +732,6 @@
1740FABA0FC4372F00CF3699 /* SPDatabaseData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPDatabaseData.m; sourceTree = "<group>"; };
1748D50A15A4444F003562F2 /* SPTableStructureLoading.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPTableStructureLoading.h; sourceTree = "<group>"; };
1748D50B15A4444F003562F2 /* SPTableStructureLoading.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPTableStructureLoading.m; sourceTree = "<group>"; };
- 1748D58415A83E54003562F2 /* SPWindowManagement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPWindowManagement.h; sourceTree = "<group>"; };
- 1748D58515A83E54003562F2 /* SPWindowManagement.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPWindowManagement.m; sourceTree = "<group>"; };
174A345112DA4ED000DB0ADE /* create-test-stubs.pl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.perl; path = "create-test-stubs.pl"; sourceTree = "<group>"; };
174CE11D10AB80B5008F892B /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = Interfaces/English.lproj/DatabaseProcessList.xib; sourceTree = "<group>"; };
174CE14010AB9281008F892B /* SPProcessListController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPProcessListController.h; sourceTree = "<group>"; };
@@ -779,8 +775,6 @@
1792C25F10AE1A2D00ABE758 /* SPConnectionDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPConnectionDelegate.h; sourceTree = "<group>"; };
1792C26010AE1A2D00ABE758 /* SPConnectionDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPConnectionDelegate.m; sourceTree = "<group>"; };
1798AB0C12676CD9000D946A /* localize.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = localize.sh; sourceTree = "<group>"; };
- 1798AB8F1267924D000D946A /* SPAppleScriptSupport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPAppleScriptSupport.h; sourceTree = "<group>"; };
- 1798AB901267924D000D946A /* SPAppleScriptSupport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPAppleScriptSupport.m; sourceTree = "<group>"; };
1798F17E1550171B004B0AB8 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
1798F1811550175B004B0AB8 /* SPFavoritesExporter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPFavoritesExporter.h; sourceTree = "<group>"; };
1798F1821550175B004B0AB8 /* SPFavoritesExporter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPFavoritesExporter.m; sourceTree = "<group>"; };
@@ -2096,10 +2090,6 @@
children = (
17E6414A0EF01EF6001BC333 /* SPAppController.h */,
17E6414B0EF01EF6001BC333 /* SPAppController.m */,
- 1798AB8F1267924D000D946A /* SPAppleScriptSupport.h */,
- 1798AB901267924D000D946A /* SPAppleScriptSupport.m */,
- 1748D58415A83E54003562F2 /* SPWindowManagement.h */,
- 1748D58515A83E54003562F2 /* SPWindowManagement.m */,
17D3583C1533766800A654D7 /* Window */,
173567BA12AC1306000DCCEF /* Bundle Support */,
173E70A6107FF61D008733C9 /* Main View Controllers */,
@@ -3431,7 +3421,6 @@
17A20AC6124F9B110095CEFB /* SPServerSupport.m in Sources */,
BC2898F3125F4488001B50E1 /* SPGeometryDataView.m in Sources */,
17148565125F5FF500321285 /* SPDatabaseCharacterSets.m in Sources */,
- 1798AB911267924D000D946A /* SPAppleScriptSupport.m in Sources */,
175EC63512733B36009A7C0F /* SPExportControllerDelegate.m in Sources */,
17D38EBC12771A1C00672B13 /* SPTableStructureDelegate.m in Sources */,
17D38F701279E23A00672B13 /* SPTableFieldValidation.m in Sources */,
@@ -3487,7 +3476,6 @@
17D5B49E1553059F00EF3BB3 /* SPViewCopy.m in Sources */,
176E14D115570FE300FAF326 /* SPBundleCommandRunner.m in Sources */,
1748D50C15A4444F003562F2 /* SPTableStructureLoading.m in Sources */,
- 1748D58615A83E54003562F2 /* SPWindowManagement.m in Sources */,
58DF9F3315AB26C2003B4330 /* SPDateAdditions.m in Sources */,
58DF9F7315AB8509003B4330 /* SPSplitView.m in Sources */,
58DFC91615CB3501003B4330 /* BGHUDButtonCell.m in Sources */,