From e8f4c4a9e16b0747647cc914c13d7597800b108d Mon Sep 17 00:00:00 2001 From: Bibiko Date: Sun, 12 Dec 2010 13:32:48 +0000 Subject: =?UTF-8?q?=E2=80=A2=20HTML=20output=20window's=20JavaScript=20sup?= =?UTF-8?q?port=20-=20changed=20the=20approach=20to=20make=20the=20HTML=20?= =?UTF-8?q?output=20window=20the=20key=20window;=20now=20it=20could=20be?= =?UTF-8?q?=20done=20directly=20via=20a=20JavaScript=20command:=20window.s?= =?UTF-8?q?ystem.makeHTMLOutputWindowKeyWindow()=20-=20added=20the=20chanc?= =?UTF-8?q?e=20to=20ask=20Sequel=20Pro=20via=20JavaScript=20for=20run-time?= =?UTF-8?q?=20shell=20variables=20via=20window.system.getShellEnvironmentF?= =?UTF-8?q?orName('shell=5Fvar=5Fname')=20=E2=80=A2=20more=20usage=20of=20?= =?UTF-8?q?constants?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPAppController.m | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'Source/SPAppController.m') 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 #import @@ -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]; -- cgit v1.2.3 From b2015bc3974c04557492bb4a698776824ab6689d Mon Sep 17 00:00:00 2001 From: Bibiko Date: Sun, 12 Dec 2010 19:20:57 +0000 Subject: =?UTF-8?q?=E2=80=A2=20made=20usage=20of=20more=20constants=20to?= =?UTF-8?q?=20avoid=20double-storing=20strings=20=E2=80=A2=20fixed=20JavaS?= =?UTF-8?q?cript=20alert=20and=20confirm=20window=20in=20HTML=20output=20w?= =?UTF-8?q?indow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPAppController.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Source/SPAppController.m') diff --git a/Source/SPAppController.m b/Source/SPAppController.m index a002f5cf..cf36d161 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -770,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; @@ -910,7 +910,7 @@ if(!currentQueryRange.length) currentQueryRange = currentSelectionRange; - [env setObject:SPBundleScopeInputField forKey:SPBundleShellVariableScope]; + [env setObject:SPBundleScopeInputField forKey:SPBundleShellVariableBundleScope]; if(selfIsQueryEditor && [[firstResponder delegate] currentQueryRange].length) [env setObject:[[firstResponder string] substringWithRange:[[firstResponder delegate] currentQueryRange]] forKey:SPBundleShellVariableCurrentQuery]; @@ -940,10 +940,10 @@ [env setObject:[sel componentsJoinedByString:@"\t"] forKey:SPBundleShellVariableSelectedRowIndices]; } - [env setObject:SPBundleScopeDataTable forKey:SPBundleShellVariableScope]; + [env setObject:SPBundleScopeDataTable forKey:SPBundleShellVariableBundleScope]; } else { - [env setObject:SPBundleScopeGeneral forKey:SPBundleShellVariableScope]; + [env setObject:SPBundleScopeGeneral forKey:SPBundleShellVariableBundleScope]; } return env; } -- cgit v1.2.3