diff options
author | Bibiko <bibiko@eva.mpg.de> | 2010-12-12 13:32:48 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2010-12-12 13:32:48 +0000 |
commit | e8f4c4a9e16b0747647cc914c13d7597800b108d (patch) | |
tree | de3b19850afe7b07c5d84e0321e5bbb63fde8877 /Source/SPAppController.m | |
parent | e3a67c9070a9c331c68503be481a6eda18402d96 (diff) | |
download | sequelpro-e8f4c4a9e16b0747647cc914c13d7597800b108d.tar.gz sequelpro-e8f4c4a9e16b0747647cc914c13d7597800b108d.tar.bz2 sequelpro-e8f4c4a9e16b0747647cc914c13d7597800b108d.zip |
• HTML output window's JavaScript support
- changed the approach to make the HTML output window the key window; now it could be done directly via a JavaScript command: window.system.makeHTMLOutputWindowKeyWindow()
- added the chance to ask Sequel Pro via JavaScript for run-time shell variables via window.system.getShellEnvironmentForName('shell_var_name')
• more usage of constants
Diffstat (limited to 'Source/SPAppController.m')
-rw-r--r-- | Source/SPAppController.m | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/Source/SPAppController.m b/Source/SPAppController.m index aa587aba..a002f5cf 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -37,6 +37,7 @@ #import "SPBundleHTMLOutputController.h" #import "SPAlertSheets.h" #import "SPChooseMenuItemDialog.h" +#import "SPCustomQuery.h" #import <PSMTabBar/PSMTabBarControl.h> #import <Sparkle/Sparkle.h> @@ -884,6 +885,69 @@ } +/** + * Return of certain shell variables mainly for usage in JavaScript support inside the + * HTML output window to allow to ask on run-time + */ +- (NSDictionary*)shellEnvironment +{ + NSMutableDictionary *env = [NSMutableDictionary dictionary]; + SPDatabaseDocument *doc = [self frontDocument]; + if(doc) [env addEntriesFromDictionary:[doc shellVariables]]; + id firstResponder = [[NSApp keyWindow] firstResponder]; + if([firstResponder respondsToSelector:@selector(executeBundleItemForInputField:)]) { + BOOL selfIsQueryEditor = ([[[firstResponder class] description] isEqualToString:@"SPTextView"]) ; + NSRange currentWordRange, currentSelectionRange, currentLineRange, currentQueryRange; + currentSelectionRange = [firstResponder selectedRange]; + currentWordRange = [firstResponder getRangeForCurrentWord]; + currentLineRange = [[firstResponder string] lineRangeForRange:NSMakeRange([firstResponder selectedRange].location, 0)]; + + if(selfIsQueryEditor) { + currentQueryRange = [[firstResponder delegate] currentQueryRange]; + } else { + currentQueryRange = currentLineRange; + } + if(!currentQueryRange.length) + currentQueryRange = currentSelectionRange; + + [env setObject:SPBundleScopeInputField forKey:SPBundleShellVariableScope]; + + if(selfIsQueryEditor && [[firstResponder delegate] currentQueryRange].length) + [env setObject:[[firstResponder string] substringWithRange:[[firstResponder delegate] currentQueryRange]] forKey:SPBundleShellVariableCurrentQuery]; + + if(currentSelectionRange.length) + [env setObject:[[firstResponder string] substringWithRange:currentSelectionRange] forKey:SPBundleShellVariableSelectedText]; + + if(currentWordRange.length) + [env setObject:[[firstResponder string] substringWithRange:currentWordRange] forKey:SPBundleShellVariableCurrentWord]; + + if(currentLineRange.length) + [env setObject:[[firstResponder string] substringWithRange:currentLineRange] forKey:SPBundleShellVariableCurrentLine]; + } + else if([firstResponder respondsToSelector:@selector(executeBundleItemForDataTable:)]) { + + if([[firstResponder delegate] respondsToSelector:@selector(usedQuery)] && [[firstResponder delegate] usedQuery]) + [env setObject:[[firstResponder delegate] usedQuery] forKey:SPBundleShellVariableUsedQueryForTable]; + + if([firstResponder numberOfSelectedRows]) { + NSMutableArray *sel = [NSMutableArray array]; + NSIndexSet *selectedRows = [firstResponder selectedRowIndexes]; + NSUInteger rowIndex = [selectedRows firstIndex]; + while ( rowIndex != NSNotFound ) { + [sel addObject:[NSString stringWithFormat:@"%ld", rowIndex]]; + rowIndex = [selectedRows indexGreaterThanIndex:rowIndex]; + } + [env setObject:[sel componentsJoinedByString:@"\t"] forKey:SPBundleShellVariableSelectedRowIndices]; + } + + [env setObject:SPBundleScopeDataTable forKey:SPBundleShellVariableScope]; + + } else { + [env setObject:SPBundleScopeGeneral forKey:SPBundleShellVariableScope]; + } + return env; +} + - (void)registerActivity:(NSDictionary*)commandDict { [runningActivitiesArray addObject:commandDict]; |