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 | |
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
-rw-r--r-- | Interfaces/English.lproj/MainMenu.xib | 17 | ||||
-rw-r--r-- | Source/MainController.m | 22 | ||||
-rw-r--r-- | Source/TableDocument.h | 2 | ||||
-rw-r--r-- | Source/TableDocument.m | 12 |
4 files changed, 45 insertions, 8 deletions
diff --git a/Interfaces/English.lproj/MainMenu.xib b/Interfaces/English.lproj/MainMenu.xib index a8f48a65..325f5892 100644 --- a/Interfaces/English.lproj/MainMenu.xib +++ b/Interfaces/English.lproj/MainMenu.xib @@ -8,7 +8,6 @@ <string key="IBDocument.HIToolboxVersion">353.00</string> <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> <bool key="EncodedWithXMLCoder">YES</bool> - <integer value="849"/> </object> <object class="NSArray" key="IBDocument.PluginDependencies"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -2282,6 +2281,14 @@ </object> <int key="connectionID">911</int> </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">delegate</string> + <reference key="source" ref="515727999"/> + <reference key="destination" ref="432083121"/> + </object> + <int key="connectionID">912</int> + </object> </object> <object class="IBMutableOrderedSet" key="objectRecords"> <object class="NSArray" key="orderedObjects"> @@ -3822,7 +3829,7 @@ <reference ref="9"/> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <reference ref="9"/> - <string>{{801, 542}, {146, 213}}</string> + <string>{{585, 542}, {146, 213}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <reference ref="9"/> <string>{{654, 613}, {157, 223}}</string> @@ -3855,7 +3862,7 @@ <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <reference ref="9"/> <string>{{449, 1007}, {197, 53}}</string> - <string>{{653, 755}, {511, 20}}</string> + <string>{{437, 755}, {511, 20}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <reference ref="9"/> <string>{{506, 836}, {511, 20}}</string> @@ -4066,7 +4073,7 @@ </object> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{947, 582}, {115, 63}}</string> + <string>{{731, 582}, {115, 63}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <object class="NSMutableDictionary"> <string key="NS.key.0">ToolTip</string> @@ -4153,7 +4160,7 @@ w6gg4oaSIGZhY2FkZV0</string> </object> </object> <nil key="sourceID"/> - <int key="maxID">911</int> + <int key="maxID">912</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <object class="NSMutableArray" key="referencedPartialClassDescriptions"> 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]; } - } |