aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPAppController.m
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2009-11-14 23:52:04 +0000
committerstuconnolly <stuart02@gmail.com>2009-11-14 23:52:04 +0000
commit75ba85f4729c13bae72bc09b1b1cebf878b113e8 (patch)
tree2ea2fdc4218d3e73174d44547d92724fdfd6ae94 /Source/SPAppController.m
parent28cfb63306ea0bb45d99324f26a4775458f34206 (diff)
downloadsequelpro-75ba85f4729c13bae72bc09b1b1cebf878b113e8.tar.gz
sequelpro-75ba85f4729c13bae72bc09b1b1cebf878b113e8.tar.bz2
sequelpro-75ba85f4729c13bae72bc09b1b1cebf878b113e8.zip
If SP is already running, but there are no documents open, clicking the dock icon (casuing a reopen call) shouldn't cause the auto-connect to kick in.
Diffstat (limited to 'Source/SPAppController.m')
-rw-r--r--Source/SPAppController.m48
1 files changed, 36 insertions, 12 deletions
diff --git a/Source/SPAppController.m b/Source/SPAppController.m
index 317935f9..49f8c201 100644
--- a/Source/SPAppController.m
+++ b/Source/SPAppController.m
@@ -391,8 +391,7 @@
#pragma mark Other methods
/**
- * Override the default open-blank-document methods to automatically connect
- * automatically opened windows.
+ * Override the default open-blank-document methods to automatically connect automatically opened windows.
*/
- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender
{
@@ -403,6 +402,7 @@
if ([[NSUserDefaults standardUserDefaults] boolForKey:SPAutoConnectToDefault]) {
[firstTableDocument setShouldAutomaticallyConnect:YES];
}
+
[[NSDocumentController sharedDocumentController] addDocument:firstTableDocument];
[firstTableDocument makeWindowControllers];
[firstTableDocument showWindows];
@@ -413,6 +413,28 @@
}
/**
+ * Implement this method to prevent the above being called in the case of a reopen (for example, clicking
+ * the dock icon) where we don't want the auto-connect to kick in.
+ */
+- (BOOL)applicationShouldHandleReopen:(NSApplication *)sender hasVisibleWindows:(BOOL)flag
+{
+ // Only create a new document (without auto-connect) when there are already no documents open.
+ if ([[[NSDocumentController sharedDocumentController] documents] count] == 0) {
+ TableDocument *firstTableDocument;
+
+ // Manually open a new document, setting SPAppController as sender to trigger autoconnection
+ if (firstTableDocument = [[NSDocumentController sharedDocumentController] makeUntitledDocumentOfType:@"SequelPro connection" error:nil]) {
+ [[NSDocumentController sharedDocumentController] addDocument:firstTableDocument];
+ [firstTableDocument makeWindowControllers];
+ [firstTableDocument showWindows];
+ }
+ }
+
+ // Return NO to the automatic opening
+ return NO;
+}
+
+/**
* Insert content of a plain text file for a given path.
* In addition it tries to figure out the file's text encoding heuristically.
*/
@@ -505,16 +527,6 @@
}
}
-/**
- * Deallocate prefs controller
- */
-- (void)dealloc
-{
- [prefsController release], prefsController = nil;
-
- [super dealloc];
-}
-
#pragma mark -
#pragma mark AppleScript support
@@ -585,4 +597,16 @@
return nil;
}
+#pragma mark -
+
+/**
+ * Deallocate prefs controller
+ */
+- (void)dealloc
+{
+ [prefsController release], prefsController = nil;
+
+ [super dealloc];
+}
+
@end