aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPAppController.m
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2010-12-12 21:10:10 +0000
committerstuconnolly <stuart02@gmail.com>2010-12-12 21:10:10 +0000
commitdc7d9981ad828d4caec28c378f743ddf7e61db96 (patch)
tree3f100e8dc474798bf5da064f6a29fcf1874ff490 /Source/SPAppController.m
parent1ddca4732c3aa46698b8fad25ce1294db3cd32fb (diff)
parentb2015bc3974c04557492bb4a698776824ab6689d (diff)
downloadsequelpro-dc7d9981ad828d4caec28c378f743ddf7e61db96.tar.gz
sequelpro-dc7d9981ad828d4caec28c378f743ddf7e61db96.tar.bz2
sequelpro-dc7d9981ad828d4caec28c378f743ddf7e61db96.zip
Bring outline view branch up to date with trunk (r3007:3010).
Diffstat (limited to 'Source/SPAppController.m')
-rw-r--r--Source/SPAppController.m66
1 files changed, 65 insertions, 1 deletions
diff --git a/Source/SPAppController.m b/Source/SPAppController.m
index 7278f5db..841a4d69 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>
@@ -769,7 +770,7 @@
NSMutableDictionary *env = [NSMutableDictionary dictionary];
[env setObject:[infoPath stringByDeletingLastPathComponent] forKey:SPBundleShellVariableBundlePath];
[env setObject:bundleInputFilePath forKey:SPBundleShellVariableInputFilePath];
- [env setObject:SPBundleScopeGeneral forKey:SPBundleShellVariableScope];
+ [env setObject:SPBundleScopeGeneral forKey:SPBundleShellVariableBundleScope];
NSString *input = @"";
NSError *inputFileError = nil;
@@ -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:SPBundleShellVariableBundleScope];
+
+ 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:SPBundleShellVariableBundleScope];
+
+ } else {
+ [env setObject:SPBundleScopeGeneral forKey:SPBundleShellVariableBundleScope];
+ }
+ return env;
+}
+
- (void)registerActivity:(NSDictionary*)commandDict
{
[runningActivitiesArray addObject:commandDict];