From 75ba85f4729c13bae72bc09b1b1cebf878b113e8 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Sat, 14 Nov 2009 23:52:04 +0000 Subject: 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. --- Source/SPAppController.m | 48 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 12 deletions(-) (limited to 'Source') 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]; @@ -412,6 +412,28 @@ return NO; } +/** + * 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 -- cgit v1.2.3