From 26865c7ea66092de62009cc8f1212863326f4a49 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Tue, 31 Aug 2010 19:18:50 +0000 Subject: =?UTF-8?q?=E2=80=A2=20fixed=20AppleScript=20crash=20after=20calli?= =?UTF-8?q?ng=20'open'=20without=20any=20parameter=20-=20this=20should=20f?= =?UTF-8?q?ix=20the=20issues=20108,=201398,=20226=20,=201157,=201473=20?= =?UTF-8?q?=E2=80=A2=20added=20AppleScript=20support=20for=20command=20'pr?= =?UTF-8?q?int'=20-=20it=20prints=20the=20active=20view=20=E2=80=A2=20rena?= =?UTF-8?q?med=20SP=20classes=20in=20sequel-pro.scriptSuite=20=E2=80=A2=20?= =?UTF-8?q?AppleScript=20command=20'make=20new=20document'=20opens=20a=20n?= =?UTF-8?q?ew=20window=20and=20connects=20to=20default=20automatically=20i?= =?UTF-8?q?f=20set?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Resources/Scripting/sequel-pro.scriptSuite | 6 +++-- Source/SPAppController.m | 37 +++++++++++++++++++++++------- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/Resources/Scripting/sequel-pro.scriptSuite b/Resources/Scripting/sequel-pro.scriptSuite index 1385660a..0647ee18 100644 --- a/Resources/Scripting/sequel-pro.scriptSuite +++ b/Resources/Scripting/sequel-pro.scriptSuite @@ -8,10 +8,12 @@ "Superclass" = "NSCoreSuite.NSApplication"; "SupportedCommands" = { "NSCoreSuite.Quit" = "handleQuitScriptCommand:"; + "NSCoreSuite.Open" = "handleOpenScriptCommand:"; + "NSCoreSuite.Print" = "handlePrintScriptCommand:"; }; "ToManyRelationships" = { "orderedDocuments" = { - "Type" = "TableDocument"; + "Type" = "SPDatabaseDocument"; "AppleEventCode" = "docu"; }; "orderedWindows" = { @@ -20,7 +22,7 @@ }; }; }; - "TableDocument" = { + "SPDatabaseDocument" = { "Superclass" = "NSCoreSuite.NSDocument"; "AppleEventCode" = "docu"; }; diff --git a/Source/SPAppController.m b/Source/SPAppController.m index 88890c46..c6d89c02 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -199,6 +199,7 @@ */ - (void)application:(NSApplication *)app openFiles:(NSArray *)filenames { + for (NSString *filename in filenames) { // Opens a sql file and insert its content into the Custom Query editor @@ -889,7 +890,7 @@ // } // - (void)handleOpenEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent // { -// NSLog(@"OPEN %@", [event description]); +// NSLog(@"OPEN "); // } // // - (void)applicationWillFinishLaunching:(NSNotification *)aNotification @@ -898,7 +899,7 @@ // [aeManager setEventHandler:self andSelector:@selector(handleQuitEvent:withReplyEvent:) forEventClass:kCoreEventClass andEventID:kAEQuitApplication]; // [aeManager setEventHandler:self andSelector:@selector(handleOpenEvent:withReplyEvent:) forEventClass:kCoreEventClass andEventID:kAEOpenApplication]; // } -// + /** * Is needed to interact with AppleScript for set/get internal SP variables @@ -933,12 +934,12 @@ - (void)insertInOrderedDocuments:(SPDatabaseDocument *)doc { [self newWindow:self]; -/* if ([[NSUserDefaults standardUserDefaults] boolForKey:SPAutoConnectToDefault]) - [doc setShouldAutomaticallyConnect:YES]; - - [[NSDocumentController sharedDocumentController] addDocument:doc]; - [doc makeWindowControllers]; - [doc showWindows];*/ + + // Set autoconnection if appropriate + if ([[NSUserDefaults standardUserDefaults] boolForKey:SPAutoConnectToDefault]) { + [[self frontDocument] connect]; + } + } /** @@ -959,6 +960,26 @@ return nil; } +/** + * AppleScript handler + * This handler is needed to catch an 'open' command if no argument was passed which would cause a crash + */ +- (id)handleOpenScriptCommand:(NSScriptCommand *)command +{ + return nil; +} + +/** + * AppleScript handler for print + * This handler prints the active view + */ +- (id)handlePrintScriptCommand:(NSScriptCommand *)command +{ + SPDatabaseDocument *frontDoc = [self frontDocument]; + if (frontDoc && ![frontDoc isWorking] && ![[frontDoc connectionID] isEqualToString:@"_"]) + [frontDoc startPrintDocumentOperation]; +} + #pragma mark - /** -- cgit v1.2.3