From e4afc0cda57f53dbbb5020a88d85777385cbc941 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 14 Jan 2011 10:16:04 +0000 Subject: =?UTF-8?q?=E2=80=A2=20fixed=20issue=20to=20highlight=20the=20corr?= =?UTF-8?q?ect=20current=20query=20after=20undoing,=20i.e.=20do=20not=20us?= =?UTF-8?q?ing=20the=20cache=20=E2=80=A2=20added=20SP=5FSELECTED=5FTEXT=5F?= =?UTF-8?q?RANGE=20shell=20variable=20for=20Bundle=20support=20of=20scope?= =?UTF-8?q?=20Input=20Text=20=E2=80=A2=20added=20'insertText',=20'setText'?= =?UTF-8?q?,=20'setSelectedTextRange'=20JavaScript=20functions=20to=20=20w?= =?UTF-8?q?indow.system=20bridge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPBundleEditorController.m | 1 + Source/SPBundleHTMLOutputController.m | 72 ++++++++++++++++++++++++++++++++++- Source/SPConstants.h | 1 + Source/SPConstants.m | 1 + Source/SPCustomQuery.h | 3 ++ Source/SPCustomQuery.m | 6 ++- Source/SPTextView.m | 3 ++ Source/SPTextViewAdditions.m | 2 + 8 files changed, 87 insertions(+), 2 deletions(-) diff --git a/Source/SPBundleEditorController.m b/Source/SPBundleEditorController.m index 173a8dbf..3de09e36 100644 --- a/Source/SPBundleEditorController.m +++ b/Source/SPBundleEditorController.m @@ -353,6 +353,7 @@ SPBundleShellVariableSelectedTable, SPBundleShellVariableSelectedTables, SPBundleShellVariableSelectedText, + SPBundleShellVariableSelectedTextRange, SPBundleShellVariableUsedQueryForTable, nil ] retain]; diff --git a/Source/SPBundleHTMLOutputController.m b/Source/SPBundleHTMLOutputController.m index 7ba67403..12af6bcf 100644 --- a/Source/SPBundleHTMLOutputController.m +++ b/Source/SPBundleHTMLOutputController.m @@ -364,6 +364,12 @@ return @"run"; if (aSelector == @selector(getShellEnvironmentForName:)) return @"getShellEnvironmentForName"; + if (aSelector == @selector(insertText:)) + return @"insertText"; + if (aSelector == @selector(setText:)) + return @"setText"; + if (aSelector == @selector(setSelectedTextRange:)) + return @"setSelectedTextRange"; if (aSelector == @selector(makeHTMLOutputWindowKeyWindow)) return @"makeHTMLOutputWindowKeyWindow"; if (aSelector == @selector(closeHTMLOutputWindow)) @@ -378,6 +384,15 @@ if (selector == @selector(getShellEnvironmentForName:)) { return NO; } + if (selector == @selector(insertText:)) { + return NO; + } + if (selector == @selector(setText:)) { + return NO; + } + if (selector == @selector(setSelectedTextRange:)) { + return NO; + } if (selector == @selector(makeHTMLOutputWindowKeyWindow)) { return NO; } @@ -394,6 +409,15 @@ if (strcmp(property, "getShellEnvironmentForName") == 0) { return NO; } + if (strcmp(property, "insertText") == 0) { + return NO; + } + if (strcmp(property, "setText") == 0) { + return NO; + } + if (strcmp(property, "setSelectedTextRange") == 0) { + return NO; + } if (strcmp(property, "makeHTMLOutputWindowKeyWindow") == 0) { return NO; } @@ -447,13 +471,59 @@ /** * JavaScript window.system.makeHTMLOutputWindowKeyWindow() function - * to make the HTML output window the first responder + * to close the HTML window */ - (void)closeHTMLOutputWindow { [[self window] close]; } +/** + * JavaScript window.system.insertText(text) function + * to insert text into the first responder + */ +- (void)insertText:(NSString*)text +{ + id firstResponder = [[NSApp keyWindow] firstResponder]; + if([firstResponder isKindOfClass:[NSTextView class]]) { + [firstResponder insertText:text]; + return; + } + NSBeep(); +} + +/** + * JavaScript window.system.setText(text) function + * to set the content of the first responder to text + */ +- (void)setText:(NSString*)text +{ + id firstResponder = [[NSApp keyWindow] firstResponder]; + if([firstResponder isKindOfClass:[NSTextView class]]) { + [firstResponder setSelectedRange:NSMakeRange(0, [[firstResponder string] length])]; + [firstResponder insertText:text]; + return; + } + NSBeep(); +} + +/** + * JavaScript window.system.setSelectedRange({location,length}) function + * to set the selection range of the first responder + */ +- (void)setSelectedTextRange:(NSString*)range +{ + id firstResponder = [[NSApp keyWindow] firstResponder]; + if([firstResponder isKindOfClass:[NSTextView class]]) { + NSRange theRange = NSIntersectionRange(NSRangeFromString(range), NSMakeRange(0, [[firstResponder string] length])); + if(theRange.location != NSNotFound) { + [firstResponder setSelectedRange:theRange]; + } + return; + } + NSBeep(); +} + /** * JavaScript window.system.run('a_command'|new Array('a_command', 'uuid')) function * to return the result of the BASH command a_command diff --git a/Source/SPConstants.h b/Source/SPConstants.h index f724535f..feb7e699 100644 --- a/Source/SPConstants.h +++ b/Source/SPConstants.h @@ -526,6 +526,7 @@ extern NSString *SPBundleShellVariableSelectedText; extern NSString *SPBundleShellVariableCurrentWord; extern NSString *SPBundleShellVariableCurrentLine; extern NSString *SPBundleShellVariableSelectedRowIndices; +extern NSString *SPBundleShellVariableSelectedTextRange; extern NSString *SPBundleShellVariableAllDatabases; extern NSString *SPBundleShellVariableSelectedTables; extern NSString *SPBundleShellVariableSelectedDatabase; diff --git a/Source/SPConstants.m b/Source/SPConstants.m index fcecb432..e5020abd 100644 --- a/Source/SPConstants.m +++ b/Source/SPConstants.m @@ -351,6 +351,7 @@ NSString *SPBundleShellVariableSelectedRowIndices = @"SP_SELECTED_ROW_ NSString *SPBundleShellVariableSelectedTable = @"SP_SELECTED_TABLE"; NSString *SPBundleShellVariableSelectedTables = @"SP_SELECTED_TABLES"; NSString *SPBundleShellVariableSelectedText = @"SP_SELECTED_TEXT"; +NSString *SPBundleShellVariableSelectedTextRange = @"SP_SELECTED_TEXT_RANGE"; NSString *SPBundleShellVariableUsedQueryForTable = @"SP_USED_QUERY_FOR_TABLE"; const NSInteger SPBundleRedirectActionNone = 200; diff --git a/Source/SPCustomQuery.h b/Source/SPCustomQuery.h index 7a8601a8..317db0c9 100644 --- a/Source/SPCustomQuery.h +++ b/Source/SPCustomQuery.h @@ -147,6 +147,7 @@ BOOL queryIsTableSorter; BOOL isDesc; BOOL isFieldEditable; + BOOL textViewWasChanged; NSNumber *sortField; NSIndexSet *selectionIndexToRestore; @@ -170,6 +171,8 @@ NSString *kCellEditorErrorTooManyMatches; } +@property(assign) BOOL textViewWasChanged; + // IBAction methods - (IBAction)runAllQueries:(id)sender; - (void) runAllQueriesCallback; diff --git a/Source/SPCustomQuery.m b/Source/SPCustomQuery.m index fa54790d..b2859010 100644 --- a/Source/SPCustomQuery.m +++ b/Source/SPCustomQuery.m @@ -45,6 +45,8 @@ @implementation SPCustomQuery +@synthesize textViewWasChanged; + #pragma mark IBAction methods /* @@ -940,7 +942,8 @@ // Split the current text into ranges of queries // only if the textView was really changed, otherwise use the cache - if([[textView textStorage] editedMask] != 0) { + if([[textView textStorage] editedMask] != 0 || [self textViewWasChanged]) { + [self setTextViewWasChanged:NO]; customQueryParser = [[SPSQLParser alloc] initWithString:[textView string]]; [customQueryParser setDelimiterSupport:YES]; queries = [[NSArray alloc] initWithArray:[customQueryParser splitStringIntoRangesByCharacter:';']]; @@ -2580,6 +2583,7 @@ BOOL isLookBehind = YES; NSRange currentSelection = [textView selectedRange]; NSUInteger caretPosition = currentSelection.location; + NSRange qRange = [self queryRangeAtPosition:caretPosition lookBehind:&isLookBehind]; if(qRange.length) diff --git a/Source/SPTextView.m b/Source/SPTextView.m index 30904ba8..32c692b5 100644 --- a/Source/SPTextView.m +++ b/Source/SPTextView.m @@ -3069,6 +3069,8 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) // Do syntax highlighting/re-calculate snippet ranges only if the user really changed the text if(editedMask != 1) { + [customQueryInstance setTextViewWasChanged:YES]; + // Re-calculate snippet ranges if snippet session is active if(snippetControlCounter > -1 && !snippetWasJustInserted && !isProcessingMirroredSnippets) { // Remove any fully nested snippets relative to the current snippet which was edited @@ -3132,6 +3134,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) [self doSyntaxHighlighting]; } else { + [customQueryInstance setTextViewWasChanged:NO]; textBufferSizeIncreased = NO; } diff --git a/Source/SPTextViewAdditions.m b/Source/SPTextViewAdditions.m index d061d3ae..21811513 100644 --- a/Source/SPTextViewAdditions.m +++ b/Source/SPTextViewAdditions.m @@ -622,6 +622,8 @@ if(currentLineRange.length) [env setObject:[[self string] substringWithRange:currentLineRange] forKey:SPBundleShellVariableCurrentLine]; + [env setObject:NSStringFromRange(replaceRange) forKey:SPBundleShellVariableSelectedTextRange]; + NSError *inputFileError = nil; NSString *input = [NSString stringWithString:[[self string] substringWithRange:replaceRange]]; [input writeToFile:bundleInputFilePath -- cgit v1.2.3