From 9f5c7db05e8a999df38b200d93031b1475adf5dc Mon Sep 17 00:00:00 2001 From: Bibiko Date: Tue, 23 Nov 2010 12:45:07 +0000 Subject: =?UTF-8?q?=E2=80=A2=20Bundle=20Editor=20-=20bailed=20out=20from?= =?UTF-8?q?=20approach=20to=20assign=20more=20than=20one=20scope=20to=20Bu?= =?UTF-8?q?ndle=20commands;=20now=20there're=20three=20scopes=20available:?= =?UTF-8?q?=20Input=20Field=20(incl.=20Query=20Editor=20since=20it=20only?= =?UTF-8?q?=20differs=20in=20current=5Fquery=20and=20insert=5Fas=5Fsnippet?= =?UTF-8?q?=20which=20falls=20back=20to=20current=5Fline=20and=20tooltip?= =?UTF-8?q?=20message),=20Data=20Table,=20and=20General=20(which=20means?= =?UTF-8?q?=20that=20these=20commands=20are=20available=20app-wide)=20-=20?= =?UTF-8?q?moved=20"Disable=20Command"=20to=20scope=20popup=20menu=20since?= =?UTF-8?q?=20it's=20related=20-=20Input=20Field=20and=20Data=20Table=20co?= =?UTF-8?q?mmands=20will=20be=20shown=20as=20submenus=20in=20the=20Bundles?= =?UTF-8?q?=20main=20menu;=20all=20General=20commands=20will=20be=20added?= =?UTF-8?q?=20without=20creating=20a=20special=20submenu=20(only=20Categor?= =?UTF-8?q?y=20submenus=20will=20be=20generated)=20-=20fixed=20and=20simpl?= =?UTF-8?q?ified=20several=20issues?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPTextViewAdditions.m | 83 +++++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 36 deletions(-) (limited to 'Source/SPTextViewAdditions.m') 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 -- cgit v1.2.3