diff options
author | Bibiko <bibiko@eva.mpg.de> | 2011-01-14 10:16:04 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2011-01-14 10:16:04 +0000 |
commit | e4afc0cda57f53dbbb5020a88d85777385cbc941 (patch) | |
tree | 8ce697f1acd9f43f3fd98beb35dfc6aa2df7b690 | |
parent | eec292b2a6a348f061630bebc5bfd7d39aa57ea0 (diff) | |
download | sequelpro-e4afc0cda57f53dbbb5020a88d85777385cbc941.tar.gz sequelpro-e4afc0cda57f53dbbb5020a88d85777385cbc941.tar.bz2 sequelpro-e4afc0cda57f53dbbb5020a88d85777385cbc941.zip |
• fixed issue to highlight the correct current query after undoing, i.e. do not using the cache
• added SP_SELECTED_TEXT_RANGE shell variable for Bundle support of scope Input Text
• added 'insertText', 'setText', 'setSelectedTextRange' JavaScript functions to window.system bridge
-rw-r--r-- | Source/SPBundleEditorController.m | 1 | ||||
-rw-r--r-- | Source/SPBundleHTMLOutputController.m | 72 | ||||
-rw-r--r-- | Source/SPConstants.h | 1 | ||||
-rw-r--r-- | Source/SPConstants.m | 1 | ||||
-rw-r--r-- | Source/SPCustomQuery.h | 3 | ||||
-rw-r--r-- | Source/SPCustomQuery.m | 6 | ||||
-rw-r--r-- | Source/SPTextView.m | 3 | ||||
-rw-r--r-- | 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,7 +471,7 @@ /** * JavaScript window.system.makeHTMLOutputWindowKeyWindow() function - * to make the HTML output window the first responder + * to close the HTML window */ - (void)closeHTMLOutputWindow { @@ -455,6 +479,52 @@ } /** + * 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 |