diff options
author | Bibiko <bibiko@eva.mpg.de> | 2010-11-23 12:45:07 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2010-11-23 12:45:07 +0000 |
commit | 9f5c7db05e8a999df38b200d93031b1475adf5dc (patch) | |
tree | f7da8d5ba93108838486d42d4e9fa5ee6d9c2a2c /Source/SPTextViewAdditions.m | |
parent | fe9a592ca3be829570f5bd88efd5b427120556e5 (diff) | |
download | sequelpro-9f5c7db05e8a999df38b200d93031b1475adf5dc.tar.gz sequelpro-9f5c7db05e8a999df38b200d93031b1475adf5dc.tar.bz2 sequelpro-9f5c7db05e8a999df38b200d93031b1475adf5dc.zip |
• Bundle Editor
- bailed out from approach to assign more than one scope to Bundle commands; now there're three scopes available: Input Field (incl. Query Editor since it only differs in current_query and insert_as_snippet which falls back to current_line and tooltip message), Data Table, and General (which means that these commands are available app-wide)
- moved "Disable Command" to scope popup menu since it's related
- Input Field and Data Table commands will be shown as submenus in the Bundles main menu; all General commands will be added without creating a special submenu (only Category submenus will be generated)
- fixed and simplified several issues
Diffstat (limited to 'Source/SPTextViewAdditions.m')
-rw-r--r-- | Source/SPTextViewAdditions.m | 83 |
1 files changed, 47 insertions, 36 deletions
diff --git a/Source/SPTextViewAdditions.m b/Source/SPTextViewAdditions.m index a33d80e4..1bc45aad 100644 --- a/Source/SPTextViewAdditions.m +++ b/Source/SPTextViewAdditions.m @@ -25,6 +25,7 @@ #import "SPAlertSheets.h" #import "SPTooltip.h" #import "SPBundleHTMLOutputController.h" +#import "SPCustomQuery.h" @implementation NSTextView (SPTextViewAdditions) @@ -528,10 +529,12 @@ NSError *err = nil; NSString *bundleInputFilePath = [NSString stringWithFormat:@"%@_%@", SPBundleTaskInputFilePath, [NSString stringWithNewUUID]]; - NSRange currentWordRange, currentSelectionRange, currentLineRange; + NSRange currentWordRange, currentSelectionRange, currentLineRange, currentQueryRange; [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil]; + BOOL selfIsQueryEditor = ([[[self class] description] isEqualToString:@"SPTextView"]) ; + if([cmdData objectForKey:SPBundleFileInputSourceKey]) inputAction = [[cmdData objectForKey:SPBundleFileInputSourceKey] lowercaseString]; if([cmdData objectForKey:SPBundleFileInputSourceFallBackKey]) @@ -541,6 +544,14 @@ currentWordRange = [self getRangeForCurrentWord]; currentLineRange = [[self string] lineRangeForRange:NSMakeRange([self selectedRange].location, 0)]; + if(selfIsQueryEditor) { + currentQueryRange = [[self delegate] currentQueryRange]; + } else { + currentQueryRange = currentLineRange; + } + if(!currentQueryRange.length) + currentQueryRange = currentSelectionRange; + NSRange replaceRange = NSMakeRange(currentSelectionRange.location, 0); if([inputAction isEqualToString:SPBundleInputSourceSelectedText]) { if(!currentSelectionRange.length) { @@ -548,6 +559,8 @@ replaceRange = currentWordRange; else if([inputFallBackAction isEqualToString:SPBundleInputSourceCurrentLine]) replaceRange = currentLineRange; + else if([inputFallBackAction isEqualToString:SPBundleInputSourceCurrentQuery]) + replaceRange = currentQueryRange; else if([inputAction isEqualToString:SPBundleInputSourceEntireContent]) replaceRange = NSMakeRange(0,[[self string] length]); } else { @@ -563,6 +576,9 @@ [env setObject:[infoPath stringByDeletingLastPathComponent] forKey:@"SP_BUNDLE_PATH"]; [env setObject:bundleInputFilePath forKey:@"SP_BUNDLE_INPUT_FILE"]; + if(selfIsQueryEditor && [[self delegate] currentQueryRange].length) + [env setObject:[[self string] substringWithRange:[[self delegate] currentQueryRange]] forKey:@"SP_CURRENT_QUERY"]; + if(currentSelectionRange.length) [env setObject:[[self string] substringWithRange:currentSelectionRange] forKey:@"SP_SELECTED_TEXT"]; @@ -596,26 +612,7 @@ && ![[cmdData objectForKey:SPBundleFileOutputActionKey] isEqualToString:SPBundleOutputActionNone]) { NSString *action = [[cmdData objectForKey:SPBundleFileOutputActionKey] lowercaseString]; - if([action isEqualToString:SPBundleOutputActionInsertAsText]) { - [self insertText:output]; - } - - else if([action isEqualToString:SPBundleOutputActionInsertAsSnippet]) { - [self insertAsSnippet:output atRange:replaceRange]; - } - - else if([action isEqualToString:SPBundleOutputActionReplaceContent]) { - if([[self string] length]) - [self setSelectedRange:NSMakeRange(0, [[self string] length])]; - [self insertText:output]; - } - - else if([action isEqualToString:SPBundleOutputActionReplaceSelection]) { - [self shouldChangeTextInRange:replaceRange replacementString:output]; - [self replaceCharactersInRange:replaceRange withString:output]; - } - - else if([action isEqualToString:SPBundleOutputActionShowAsTextTooltip]) { + if([action isEqualToString:SPBundleOutputActionShowAsTextTooltip]) { [SPTooltip showWithObject:output]; } @@ -627,6 +624,35 @@ SPBundleHTMLOutputController *c = [[SPBundleHTMLOutputController alloc] init]; [c displayHTMLContent:output withOptions:nil]; } + + if([self isEditable]) { + + if([action isEqualToString:SPBundleOutputActionInsertAsText]) { + [self insertText:output]; + } + + else if([action isEqualToString:SPBundleOutputActionInsertAsSnippet]) { + if([self respondsToSelector:@selector(insertAsSnippet:atRange:)]) + [self insertAsSnippet:output atRange:replaceRange]; + else + [SPTooltip showWithObject:NSLocalizedString(@"Input Field doesn't support insertion of snippets.", @"input field doesn't support insertion of snippets.")]; + } + + else if([action isEqualToString:SPBundleOutputActionReplaceContent]) { + if([[self string] length]) + [self setSelectedRange:NSMakeRange(0, [[self string] length])]; + [self insertText:output]; + } + + else if([action isEqualToString:SPBundleOutputActionReplaceSelection]) { + [self shouldChangeTextInRange:replaceRange replacementString:output]; + [self replaceCharactersInRange:replaceRange withString:output]; + } + + } else { + [SPTooltip showWithObject:NSLocalizedString(@"Input Field is not editable.", @"input field is not editable.")]; + } + } } else { NSString *errorMessage = [err localizedDescription]; @@ -722,21 +748,6 @@ } -- (BOOL)validateMenuItem:(NSMenuItem *)menuItem -{ - - if([menuItem action] == @selector(executeBundleItemForEditor:)) - { - return NO; - } - if([menuItem action] == @selector(executeBundleItemForInputField:)) - { - return YES; - } - - return YES; - -} #pragma mark - #pragma mark multi-touch trackpad support |