From e83978c06efee794faa0603c6e6653fd1647b26a Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 11 Nov 2010 22:47:42 +0000 Subject: =?UTF-8?q?=E2=80=A2=20some=20sequelpro://...@passToDoc/ExecuteQue?= =?UTF-8?q?ry/csv=20improvements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPTextView.m | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'Source/SPTextView.m') diff --git a/Source/SPTextView.m b/Source/SPTextView.m index 34c87822..da4c3f04 100644 --- a/Source/SPTextView.m +++ b/Source/SPTextView.m @@ -3510,13 +3510,13 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) if (cmdData) [cmdData release]; return; } else { - if([cmdData objectForKey:@"command"] && [[cmdData objectForKey:@"command"] length]) { + if([cmdData objectForKey:@"command"] && [[cmdData objectForKey:@"command"] length] && [cmdData objectForKey:@"scope"] && [[cmdData objectForKey:@"scope"] isEqualToString:@"editor"]) { NSString *cmd = [cmdData objectForKey:@"command"]; NSString *inputAction = @""; NSString *inputFallBackAction = @""; NSError *err = nil; - NSString *inputTempFileName = @"/tmp/sp_bundle_task_input"; + NSString *inputTempFileName = @"/tmp/SP_BUNDLE_TASK_INPUT"; NSRange currentWordRange, currentQueryRange, currentSelectionRange, currentLineRange; [[NSFileManager defaultManager] removeItemAtPath:inputTempFileName error:nil]; @@ -3555,21 +3555,6 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) replaceRange = NSMakeRange(0,[[self string] length]); } - NSError *inputFileError = nil; - NSString *input = [NSString stringWithString:[[self string] substringWithRange:replaceRange]]; - [input writeToFile:inputTempFileName - atomically:YES - encoding:NSUTF8StringEncoding - error:&inputFileError]; - - if(inputFileError != nil) { - NSString *errorMessage = [inputFileError localizedDescription]; - 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; - } - NSMutableDictionary *env = [NSMutableDictionary dictionary]; [env setObject:[infoPath stringByDeletingLastPathComponent] forKey:@"SP_BUNDLE_PATH"]; [env setObject:inputTempFileName forKey:@"SP_BUNDLE_INPUT_FILE"]; @@ -3613,8 +3598,25 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) if(currentLineRange.length) [env setObject:[[self string] substringWithRange:currentLineRange] forKey:@"SP_CURRENT_LINE"]; + NSError *inputFileError = nil; + NSString *input = [NSString stringWithString:[[self string] substringWithRange:replaceRange]]; + [input writeToFile:inputTempFileName + atomically:YES + encoding:NSUTF8StringEncoding + error:&inputFileError]; + + if(inputFileError != nil) { + NSString *errorMessage = [inputFileError localizedDescription]; + 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; + } + NSString *output = [cmd runBashCommandWithEnvironment:env atCurrentDirectoryPath:nil error:&err]; + [[NSFileManager defaultManager] removeItemAtPath:inputTempFileName error:nil]; + if(err == nil && [cmdData objectForKey:@"output"]) { if([[cmdData objectForKey:@"output"] length] && ![[cmdData objectForKey:@"output"] isEqualToString:@"nop"]) { NSString *action = [[cmdData objectForKey:@"output"] lowercaseString]; @@ -3652,8 +3654,6 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]); } - [[NSFileManager defaultManager] removeItemAtPath:inputTempFileName error:nil]; - } if (cmdData) [cmdData release]; -- cgit v1.2.3