From 44cf4df2bbe2e9208faef346abc0a64e62432592 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Tue, 7 Dec 2010 11:16:55 +0000 Subject: =?UTF-8?q?=E2=80=A2=20Bundle=20command=20support=20-=20fixed=20is?= =?UTF-8?q?sue=20for=20commands=20without=20assigning=20a=20key=20equivale?= =?UTF-8?q?nt=20-=20output=20table=20meta=20data=20about=20type,=20type=20?= =?UTF-8?q?grouping,=20length,=20auto=5Finc,=20PRI=20key=20etc.=20for=20Da?= =?UTF-8?q?ta=20Table=20scope=20commands=20and=20sequelpro=20url=20scheme?= =?UTF-8?q?=20command=20ExecuteQuery?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPAppController.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'Source/SPAppController.m') diff --git a/Source/SPAppController.m b/Source/SPAppController.m index 304e1d3e..3054892f 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -1302,7 +1302,9 @@ if([cmdData objectForKey:SPBundleFileCategoryKey] && [[cmdData objectForKey:SPBundleFileCategoryKey] length]) [aDict setObject:[cmdData objectForKey:SPBundleFileCategoryKey] forKey:SPBundleFileCategoryKey]; - [aDict setObject:[cmdData objectForKey:SPBundleFileKeyEquivalentKey] forKey:@"key"]; + if([cmdData objectForKey:SPBundleFileKeyEquivalentKey] && [[cmdData objectForKey:SPBundleFileKeyEquivalentKey] length]) + [aDict setObject:[cmdData objectForKey:SPBundleFileKeyEquivalentKey] forKey:@"key"]; + for(NSString* scope in scopes) [[bundleItems objectForKey:scope] addObject:aDict]; } -- cgit v1.2.3 From d6560942643fd41f3aa3f378c595387a26d35bdc Mon Sep 17 00:00:00 2001 From: Bibiko Date: Tue, 7 Dec 2010 11:56:49 +0000 Subject: =?UTF-8?q?=E2=80=A2=20fixed=20issue=20for=20starting=20General=20?= =?UTF-8?q?scope=20commands=20via=20keyboard=20short-cut?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPAppController.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/SPAppController.m') diff --git a/Source/SPAppController.m b/Source/SPAppController.m index 3054892f..7d6c11ed 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -1491,7 +1491,7 @@ } } else if([scope isEqualToString:SPBundleScopeGeneral]) { - if(checkForKeyEquivalents && [assignedKeyEquivalents objectForKey:keyEqKey]) { + if(checkForKeyEquivalents && [assignedKeyEquivalents count]) { NSInteger idx = 0; if([assignedKeyEquivalents count] > 1) idx = [SPChooseMenuItemDialog withItems:assignedKeyEquivalents atPosition:[NSEvent mouseLocation]]; @@ -1502,7 +1502,7 @@ NSMenuItem *aMenuItem = [[[NSMenuItem alloc] init] autorelease]; [aMenuItem setTag:0]; [aMenuItem setToolTip:[eq objectForKey:@"path"]]; - [[[NSApp mainWindow] firstResponder] executeBundleItemForApp:aMenuItem]; + [self executeBundleItemForApp:aMenuItem]; } } } else { -- cgit v1.2.3 From d51530a48813b08d9694fed3a7a24998d495d5b5 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Wed, 8 Dec 2010 11:05:28 +0000 Subject: =?UTF-8?q?=E2=80=A2=20Bundle=20commands=20-=20reworked=20invocati?= =?UTF-8?q?on=20via=20keyboard=20short-cut=20to=20allow=20to=20fall=20back?= =?UTF-8?q?=20to=20General=20scope=20-=20added=20chance=20to=20redirect=20?= =?UTF-8?q?the=20output=20action=20via=20command=20exit=20codes;=20useful?= =?UTF-8?q?=20if=20the=20normal=20output=20is=20an=20HTML=20window=20but?= =?UTF-8?q?=20an=20error=20occurred,=20now=20one=20can=20display=20the=20e?= =?UTF-8?q?rror=20as=20tooltip=20for=20instance=20-=20unified=20file=20han?= =?UTF-8?q?d-shake=20file=20names=20by=20one=20uuid=20-=20made=20usage=20o?= =?UTF-8?q?f=20more=20constants=20and=20renamed=20some=20shell=20vars?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPAppController.m | 140 +++++++++++++++++++++++++++++++---------------- 1 file changed, 94 insertions(+), 46 deletions(-) (limited to 'Source/SPAppController.m') diff --git a/Source/SPAppController.m b/Source/SPAppController.m index 7d6c11ed..63011789 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -640,7 +640,7 @@ // Try to find the SPDatabaseDocument which sent the the url scheme command // For speed check the front most first otherwise iterate through all - if(passedProcessID) { + if(passedProcessID && [passedProcessID length]) { if([activeProcessID isEqualToString:passedProcessID]) { processDocument = [[[self frontDocumentWindow] delegate] selectedTableDocument]; } else { @@ -691,18 +691,26 @@ return; } - // If command failed notify the file handle hand shake mechanism - NSString *out = @"1"; - [out writeToFile:[NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultStatusPathHeader, passedProcessID] - atomically:YES - encoding:NSUTF8StringEncoding - error:nil]; - out = @"Scheme Error"; - [out writeToFile:[NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultPathHeader, passedProcessID] - atomically:YES - encoding:NSUTF8StringEncoding - error:nil]; + if(processDocument != nil) { + // If command failed notify the file handle hand shake mechanism + NSString *out = @"1"; + [out writeToFile:[NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultStatusPathHeader, passedProcessID] + atomically:YES + encoding:NSUTF8StringEncoding + error:nil]; + out = @"Scheme Error"; + [out writeToFile:[NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultPathHeader, passedProcessID] + atomically:YES + encoding:NSUTF8StringEncoding + error:nil]; + } + if(passedProcessID == nil || ![passedProcessID length]) { + SPBeginAlertSheet(NSLocalizedString(@"sequelpro URL Scheme Error", @"sequelpro url Scheme Error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [NSApp mainWindow], self, nil, nil, + [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [command description], NSLocalizedString(@"An error occur while executing a scheme command. If the scheme command was invoked by a Bundle command, it could be that the command still runs. You can try to terminate it by pressing ⌘+. or via the Activities pane.", @"an error occur while executing a scheme command. if the scheme command was invoked by a bundle command, it could be that the command still runs. you can try to terminate it by pressing ⌘+. or via the activities pane.")]); + } else { + NSBeep(); + } if(processDocument) NSLog(@"process doc ID: %@\n%@", [processDocument processID], [processDocument tabTitleForTooltip]); @@ -753,40 +761,18 @@ NSString *inputAction = @""; NSString *inputFallBackAction = @""; NSError *err = nil; - NSString *bundleInputFilePath = [NSString stringWithFormat:@"%@_%@", SPBundleTaskInputFilePath, [NSString stringWithNewUUID]]; + NSString *uuid = [NSString stringWithNewUUID]; + NSString *bundleInputFilePath = [NSString stringWithFormat:@"%@_%@", SPBundleTaskInputFilePath, uuid]; [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil]; - if([cmdData objectForKey:SPBundleFileInputSourceKey]) - inputAction = [[cmdData objectForKey:SPBundleFileInputSourceKey] lowercaseString]; - if([cmdData objectForKey:SPBundleFileInputSourceFallBackKey]) - inputFallBackAction = [[cmdData objectForKey:SPBundleFileInputSourceFallBackKey] lowercaseString]; - NSMutableDictionary *env = [NSMutableDictionary dictionary]; - [env setObject:[infoPath stringByDeletingLastPathComponent] forKey:@"SP_BUNDLE_PATH"]; - [env setObject:bundleInputFilePath forKey:@"SP_BUNDLE_INPUT_FILE"]; + [env setObject:[infoPath stringByDeletingLastPathComponent] forKey:SPBundleShellVariableBundlePath]; + [env setObject:bundleInputFilePath forKey:SPBundleShellVariableInputFilePath]; + [env setObject:SPBundleScopeGeneral forKey:SPBundleShellVariableScope]; - NSError *inputFileError = nil; NSString *input = @""; - if([inputAction isEqualToString:SPBundleInputSourceSelectedTableRowsAsTab]) { - input = [self rowsAsTabStringWithHeaders:YES onlySelectedRows:YES]; - } - else if([inputAction isEqualToString:SPBundleInputSourceSelectedTableRowsAsCsv]) { - input = [self rowsAsCsvStringWithHeaders:YES onlySelectedRows:YES]; - } - else if([inputAction isEqualToString:SPBundleInputSourceSelectedTableRowsAsSqlInsert]) { - input = [self rowsAsSqlInsertsOnlySelectedRows:YES]; - } - else if([inputAction isEqualToString:SPBundleInputSourceTableRowsAsTab]) { - input = [self rowsAsTabStringWithHeaders:YES onlySelectedRows:NO]; - } - else if([inputAction isEqualToString:SPBundleInputSourceTableRowsAsCsv]) { - input = [self rowsAsCsvStringWithHeaders:YES onlySelectedRows:NO]; - } - else if([inputAction isEqualToString:SPBundleInputSourceTableRowsAsSqlInsert]) { - input = [self rowsAsSqlInsertsOnlySelectedRows:NO]; - } - + NSError *inputFileError = nil; if(input == nil) input = @""; [input writeToFile:bundleInputFilePath atomically:YES @@ -795,7 +781,7 @@ if(inputFileError != nil) { NSString *errorMessage = [inputFileError localizedDescription]; - SPBeginAlertSheet(NSLocalizedString(@"Bundle Error", @"bundle error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [NSApp mainWindow], self, nil, nil, + SPBeginAlertSheet(NSLocalizedString(@"Bundle Error", @"bundle error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self window], self, nil, nil, [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]); if (cmdData) [cmdData release]; return; @@ -807,15 +793,53 @@ contextInfo:[NSDictionary dictionaryWithObjectsAndKeys: ([cmdData objectForKey:SPBundleFileNameKey])?:@"-", @"name", NSLocalizedString(@"General", @"general menu item label"), @"scope", + uuid, SPBundleFileInternalexecutionUUID, nil] error:&err]; [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil]; + NSString *action = [[cmdData objectForKey:SPBundleFileOutputActionKey] lowercaseString]; + + // Redirect due exit code + if(err != nil) { + if([err code] == SPBundleRedirectActionNone) { + action = SPBundleOutputActionNone; + err = nil; + } + else if([err code] == SPBundleRedirectActionReplaceSection) { + action = SPBundleOutputActionReplaceSelection; + err = nil; + } + else if([err code] == SPBundleRedirectActionReplaceContent) { + action = SPBundleOutputActionReplaceContent; + err = nil; + } + else if([err code] == SPBundleRedirectActionInsertAsText) { + action = SPBundleOutputActionInsertAsText; + err = nil; + } + else if([err code] == SPBundleRedirectActionInsertAsSnippet) { + action = SPBundleOutputActionInsertAsSnippet; + err = nil; + } + else if([err code] == SPBundleRedirectActionShowAsHTML) { + action = SPBundleOutputActionShowAsHTML; + err = nil; + } + else if([err code] == SPBundleRedirectActionShowAsTextTooltip) { + action = SPBundleOutputActionShowAsTextTooltip; + err = nil; + } + else if([err code] == SPBundleRedirectActionShowAsHTMLTooltip) { + action = SPBundleOutputActionShowAsHTMLTooltip; + err = nil; + } + } + if(err == nil && output) { if([cmdData objectForKey:SPBundleFileOutputActionKey] && [[cmdData objectForKey:SPBundleFileOutputActionKey] length] && ![[cmdData objectForKey:SPBundleFileOutputActionKey] isEqualToString:SPBundleOutputActionNone]) { - NSString *action = [[cmdData objectForKey:SPBundleFileOutputActionKey] lowercaseString]; NSPoint pos = [NSEvent mouseLocation]; pos.y -= 16; @@ -1411,7 +1435,7 @@ [mItem setTag:1000000 + i++]; [mItem setRepresentedObject:[NSDictionary dictionaryWithObjectsAndKeys: scope, @"scope", - [item objectForKey:@"key"], @"key", nil]]; + ([item objectForKey:@"key"])?:@"", @"key", nil]]; if([item objectForKey:SPBundleFileCategoryKey]) { [[categoryMenus objectAtIndex:[bundleCategories indexOfObject:[item objectForKey:SPBundleFileCategoryKey]]] addItem:mItem]; @@ -1433,16 +1457,42 @@ - (IBAction)bundleCommandDispatcher:(id)sender { - BOOL checkForKeyEquivalents = ([[NSApp currentEvent] type] == NSKeyDown) ? YES : NO; + NSEvent *event = [NSApp currentEvent]; + BOOL checkForKeyEquivalents = ([event type] == NSKeyDown) ? YES : NO; + + id firstResponder = [[NSApp mainWindow] firstResponder]; NSString *scope = [[sender representedObject] objectForKey:@"scope"]; NSString *keyEqKey = nil; NSMutableArray *assignedKeyEquivalents = nil; if(checkForKeyEquivalents) { + + // Get the current scope in order to find out which command with a specific key + // should run + if([firstResponder respondsToSelector:@selector(executeBundleItemForInputField:)]) + scope = SPBundleScopeInputField; + else if([firstResponder respondsToSelector:@selector(executeBundleItemForDataTable:)]) + scope = SPBundleScopeDataTable; + else + scope = SPBundleScopeGeneral; + keyEqKey = [[sender representedObject] objectForKey:@"key"]; + assignedKeyEquivalents = [NSMutableArray array]; [assignedKeyEquivalents setArray:[[bundleKeyEquivalents objectForKey:scope] objectForKey:keyEqKey]]; + // Fall back to general scope and check for key + if(![assignedKeyEquivalents count]) { + scope = SPBundleScopeGeneral; + [assignedKeyEquivalents setArray:[[bundleKeyEquivalents objectForKey:scope] objectForKey:keyEqKey]]; + } + // Nothing found thus bail + if(![assignedKeyEquivalents count]) { + NSBeep(); + return; + } + + // Sort if more than one found if([assignedKeyEquivalents count] > 1) { NSSortDescriptor *aSortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"title" ascending:YES selector:@selector(caseInsensitiveCompare:)] autorelease]; NSArray *sorted = [assignedKeyEquivalents sortedArrayUsingDescriptors:[NSArray arrayWithObject:aSortDescriptor]]; @@ -1450,8 +1500,6 @@ } } - id firstResponder = [[NSApp mainWindow] firstResponder]; - if([scope isEqualToString:SPBundleScopeInputField] && [firstResponder respondsToSelector:@selector(executeBundleItemForInputField:)]) { if(checkForKeyEquivalents && [assignedKeyEquivalents count]) { NSInteger idx = 0; -- cgit v1.2.3