diff options
author | rowanbeentje <rowan@beent.je> | 2009-04-10 15:34:14 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2009-04-10 15:34:14 +0000 |
commit | 06a412a95e9882c71d40272999f65a89e3447564 (patch) | |
tree | 9d48b50c6d322ef3787aec3d394940cafa976628 /Source | |
parent | a199e73f7acf177cf197fea3e4dc0abe2ab4789b (diff) | |
download | sequelpro-06a412a95e9882c71d40272999f65a89e3447564.tar.gz sequelpro-06a412a95e9882c71d40272999f65a89e3447564.tar.bz2 sequelpro-06a412a95e9882c71d40272999f65a89e3447564.zip |
- Make MainController the application delegate, and override standard automatic creation methods to only trigger automatic connection (if enabled in prefs) for automatically created windows
Diffstat (limited to 'Source')
-rw-r--r-- | Source/MainController.m | 22 | ||||
-rw-r--r-- | Source/TableDocument.h | 2 | ||||
-rw-r--r-- | Source/TableDocument.m | 12 |
3 files changed, 33 insertions, 3 deletions
diff --git a/Source/MainController.m b/Source/MainController.m index 06f5d739..2e80e396 100644 --- a/Source/MainController.m +++ b/Source/MainController.m @@ -131,6 +131,28 @@ #pragma mark Other methods /** + * Override the default open-blank-document methods to automatically connect + * automatically opened windows. + */ +- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender +{ + TableDocument *firstTableDocument; + + // Manually open a new document, setting MainController as sender to trigger autoconnection + if (firstTableDocument = [[NSDocumentController sharedDocumentController] makeUntitledDocumentOfType:@"DocumentType" error:nil]) { + if ([[NSUserDefaults standardUserDefaults] boolForKey:@"AutoConnectToDefault"]) { + [firstTableDocument setShouldAutomaticallyConnect:YES]; + } + [[NSDocumentController sharedDocumentController] addDocument:firstTableDocument]; + [firstTableDocument makeWindowControllers]; + [firstTableDocument showWindows]; + } + + // Return NO to the automatic opening + return NO; +} + +/** * What exactly is this for? */ - (id)handleQuitScriptCommand:(NSScriptCommand *)command diff --git a/Source/TableDocument.h b/Source/TableDocument.h index 7c9ce223..f58faad5 100644 --- a/Source/TableDocument.h +++ b/Source/TableDocument.h @@ -92,12 +92,14 @@ BOOL _supportsEncoding; NSString *_encoding; BOOL _encodingViaLatin1; + BOOL _shouldOpenConnectionAutomatically; NSToolbar *mainToolbar; NSToolbarItem *chooseDatabaseToolbarItem; } //start sheet +- (void)setShouldAutomaticallyConnect:(BOOL)shouldAutomaticallyConnect; - (IBAction)connectToDB:(id)sender; - (IBAction)connect:(id)sender; - (IBAction)cancelConnectSheet:(id)sender; diff --git a/Source/TableDocument.m b/Source/TableDocument.m index 7f674341..19825570 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -115,6 +115,14 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocum //start sheet /** + * Set whether the connection sheet should automaticall start connecting + */ +- (void)setShouldAutomaticallyConnect:(BOOL)shouldAutomaticallyConnect +{ + _shouldOpenConnectionAutomatically = shouldAutomaticallyConnect; +} + +/** * tries to connect to a database server, shows connect sheet prompting user to * enter details/select favorite and shoows alert sheets on failure. */ @@ -133,11 +141,9 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocum // Connect automatically to the last used or default favourite // connectSheet must open first. - // TODO: Auto connect on startup only. New connections should NOT automatically connect. - if ([prefs boolForKey:@"AutoConnectToDefault"]) { + if (_shouldOpenConnectionAutomatically) { [self connect:self]; } - } |