diff options
author | Bibiko <bibiko@eva.mpg.de> | 2010-11-10 13:47:24 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2010-11-10 13:47:24 +0000 |
commit | bb99430f93b2e3c89c28cc44257635709f0fdd39 (patch) | |
tree | 74f2eb41f7942c1739641b01febf15f0d23dbfa7 /Source/SPTextView.m | |
parent | 169fb3fffeff55cff32952a82adba055dfc050f9 (diff) | |
download | sequelpro-bb99430f93b2e3c89c28cc44257635709f0fdd39.tar.gz sequelpro-bb99430f93b2e3c89c28cc44257635709f0fdd39.tar.bz2 sequelpro-bb99430f93b2e3c89c28cc44257635709f0fdd39.zip |
• improved Bundle support; now it the passed input string will be saved as temp file SP_BUNDLE_INPUT_FILE since stdin and shell vars are difficult to handle for a large amount of data
• fixed AppleScript class definition since it was renamed
• added support for the URL scheme 'sequel' to allow to interact with Sequel Pro eg via bash: open 'sequelpro://executequery=select%205' [not yet implemented ;)]
Diffstat (limited to 'Source/SPTextView.m')
-rw-r--r-- | Source/SPTextView.m | 113 |
1 files changed, 61 insertions, 52 deletions
diff --git a/Source/SPTextView.m b/Source/SPTextView.m index 9de1d0af..8a065c5c 100644 --- a/Source/SPTextView.m +++ b/Source/SPTextView.m @@ -3513,13 +3513,67 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) if([cmdData objectForKey:@"command"] && [[cmdData objectForKey:@"command"] length]) { NSString *cmd = [cmdData objectForKey:@"command"]; + NSString *inputAction = @""; + NSString *inputFallBackAction = @""; NSError *err = nil; + NSString *inputTempFileName = @"/tmp/sp_bundle_task_input"; NSRange currentWordRange, currentQueryRange, currentSelectionRange, currentLineRange; + [[NSFileManager defaultManager] removeItemAtPath:inputTempFileName error:nil]; + + if([cmdData objectForKey:@"input"]) + inputAction = [[cmdData objectForKey:@"input"] lowercaseString]; + if([cmdData objectForKey:@"input_fallback"]) + inputFallBackAction = [[cmdData objectForKey:@"input_fallback"] lowercaseString]; + + currentSelectionRange = [self selectedRange]; + currentWordRange = [self getRangeForCurrentWord]; + if(customQueryInstance && [customQueryInstance currentQueryRange].length) { + currentQueryRange = [customQueryInstance currentQueryRange]; + } else { + currentQueryRange = currentSelectionRange; + } + currentLineRange = [[self string] lineRangeForRange:NSMakeRange([self selectedRange].location, 0)]; + + NSRange replaceRange = NSMakeRange(currentSelectionRange.location, 0); + if([inputAction isEqualToString:@"selectedtext"]) { + if(!currentSelectionRange.length) { + if([inputFallBackAction isEqualToString:@"currentword"]) + replaceRange = currentWordRange; + else if([inputFallBackAction isEqualToString:@"currentline"]) + replaceRange = currentLineRange; + else if([inputFallBackAction isEqualToString:@"currentquery"]) + replaceRange = currentQueryRange; + else if([inputAction isEqualToString:@"entirecontent"]) + replaceRange = NSMakeRange(0,[[self string] length]); + } else { + replaceRange = currentSelectionRange; + } + + } + else if([inputAction isEqualToString:@"entirecontent"]) { + 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"]; - currentSelectionRange = [self selectedRange]; if(currentSelectionRange.length) [env setObject:[[self string] substringWithRange:currentSelectionRange] forKey:@"SP_SELECTED_TEXT"]; @@ -3529,19 +3583,12 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) if (tablesListInstance && [tablesListInstance tableName]) [env setObject:[tablesListInstance tableName] forKey:@"SP_SELECTED_TABLE"]; - - if(customQueryInstance && [customQueryInstance currentQueryRange].length) { - currentQueryRange = [customQueryInstance currentQueryRange]; + if(customQueryInstance && [customQueryInstance currentQueryRange].length) [env setObject:[[self string] substringWithRange:[customQueryInstance currentQueryRange]] forKey:@"SP_CURRENT_QUERY"]; - } else { - currentQueryRange = currentSelectionRange; - } - currentWordRange = [self getRangeForCurrentWord]; if(currentWordRange.length) [env setObject:[[self string] substringWithRange:currentWordRange] forKey:@"SP_CURRENT_WORD"]; - currentLineRange = [[self string] lineRangeForRange:NSMakeRange([self selectedRange].location, 0)]; if(currentLineRange.length) [env setObject:[[self string] substringWithRange:currentLineRange] forKey:@"SP_CURRENT_LINE"]; @@ -3555,27 +3602,6 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) } else if([action isEqualToString:@"insertassnippet"]) { - NSString *inputAction = @""; - NSString *inputFallBackAction = @""; - if([cmdData objectForKey:@"input"]) - inputAction = [[cmdData objectForKey:@"input"] lowercaseString]; - if([cmdData objectForKey:@"input_fallback"]) - inputFallBackAction = [[cmdData objectForKey:@"input_fallback"] lowercaseString]; - NSRange replaceRange = NSMakeRange(currentSelectionRange.location, 0); - if([inputAction isEqualToString:@"selectedtext"]) { - if(!currentSelectionRange.length) { - if([inputFallBackAction isEqualToString:@"currentword"]) - replaceRange = currentWordRange; - else if([inputFallBackAction isEqualToString:@"currentline"]) - replaceRange = currentLineRange; - else if([inputFallBackAction isEqualToString:@"currentquery"]) - replaceRange = currentQueryRange; - else if([inputAction isEqualToString:@"entirecontent"]) - replaceRange = NSMakeRange(0,[[self string] length]); - } else { - replaceRange = currentSelectionRange; - } - } [self insertAsSnippet:output atRange:replaceRange]; } @@ -3586,27 +3612,6 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) } else if([action isEqualToString:@"replaceselection"]) { - NSString *inputAction = @""; - NSString *inputFallBackAction = @""; - if([cmdData objectForKey:@"input"]) - inputAction = [[cmdData objectForKey:@"input"] lowercaseString]; - if([cmdData objectForKey:@"input_fallback"]) - inputFallBackAction = [[cmdData objectForKey:@"input_fallback"] lowercaseString]; - NSRange replaceRange = NSMakeRange(currentSelectionRange.location, 0); - if([inputAction isEqualToString:@"selectedtext"]) { - if(!currentSelectionRange.length) { - if([inputFallBackAction isEqualToString:@"currentword"]) - replaceRange = currentWordRange; - else if([inputFallBackAction isEqualToString:@"currentline"]) - replaceRange = currentLineRange; - else if([inputFallBackAction isEqualToString:@"currentquery"]) - replaceRange = currentQueryRange; - else if([inputAction isEqualToString:@"entirecontent"]) - replaceRange = NSMakeRange(0,[[self string] length]); - } else { - replaceRange = currentSelectionRange; - } - } [self shouldChangeTextInRange:replaceRange replacementString:output]; [self replaceCharactersInRange:replaceRange withString:output]; } @@ -3624,9 +3629,13 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) SPBeginAlertSheet(NSLocalizedString(@"BASH Error", @"bash 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]); } + + [[NSFileManager defaultManager] removeItemAtPath:inputTempFileName error:nil]; + } - + if (cmdData) [cmdData release]; + } } |