From 06a412a95e9882c71d40272999f65a89e3447564 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Fri, 10 Apr 2009 15:34:14 +0000 Subject: - Make MainController the application delegate, and override standard automatic creation methods to only trigger automatic connection (if enabled in prefs) for automatically created windows --- Source/MainController.m | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'Source/MainController.m') diff --git a/Source/MainController.m b/Source/MainController.m index 06f5d739..2e80e396 100644 --- a/Source/MainController.m +++ b/Source/MainController.m @@ -130,6 +130,28 @@ #pragma mark - #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? */ -- cgit v1.2.3