diff options
author | stuconnolly <stuart02@gmail.com> | 2010-12-12 21:10:10 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2010-12-12 21:10:10 +0000 |
commit | dc7d9981ad828d4caec28c378f743ddf7e61db96 (patch) | |
tree | 3f100e8dc474798bf5da064f6a29fcf1874ff490 /Source | |
parent | 1ddca4732c3aa46698b8fad25ce1294db3cd32fb (diff) | |
parent | b2015bc3974c04557492bb4a698776824ab6689d (diff) | |
download | sequelpro-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')
-rw-r--r-- | Source/SPAppController.h | 1 | ||||
-rw-r--r-- | Source/SPAppController.m | 66 | ||||
-rw-r--r-- | Source/SPBundleEditorController.m | 84 | ||||
-rw-r--r-- | Source/SPBundleHTMLOutputController.m | 71 | ||||
-rw-r--r-- | Source/SPConnectionController.m | 2 | ||||
-rw-r--r-- | Source/SPConstants.h | 31 | ||||
-rw-r--r-- | Source/SPConstants.m | 47 | ||||
-rw-r--r-- | Source/SPCopyTable.m | 4 | ||||
-rw-r--r-- | Source/SPDatabaseDocument.m | 34 | ||||
-rw-r--r-- | Source/SPStringAdditions.m | 22 | ||||
-rw-r--r-- | Source/SPTextViewAdditions.m | 10 |
11 files changed, 271 insertions, 101 deletions
diff --git a/Source/SPAppController.h b/Source/SPAppController.h index 938a6423..0d68b26c 100644 --- a/Source/SPAppController.h +++ b/Source/SPAppController.h @@ -113,6 +113,7 @@ - (void)handleEventWithURL:(NSURL*)url; - (IBAction)executeBundleItemForApp:(id)sender; +- (NSDictionary*)shellEnvironment; - (void)addHTMLOutputController:(id)controller; 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]; diff --git a/Source/SPBundleEditorController.m b/Source/SPBundleEditorController.m index 272221d4..dffcb20c 100644 --- a/Source/SPBundleEditorController.m +++ b/Source/SPBundleEditorController.m @@ -304,47 +304,49 @@ [commandBundleTreeController setSortDescriptors:[NSArray arrayWithObjects:sortDescriptor, nil]]; shellVariableSuggestions = [[NSArray arrayWithObjects: - @"SP_ALL_DATABASES", - @"SP_ALL_FUNCTIONS", - @"SP_ALL_PROCEDURES", - @"SP_ALL_TABLES", - @"SP_ALL_VIEWS", - @"SP_APP_RESOURCES_DIRECTORY", - @"SP_BUNDLE_EXIT_INSERT_AS_SNIPPET", - @"SP_BUNDLE_EXIT_INSERT_AS_TEXT", - @"SP_BUNDLE_EXIT_NONE", - @"SP_BUNDLE_EXIT_REPLACE_CONTENT", - @"SP_BUNDLE_EXIT_REPLACE_SELECTION", - @"SP_BUNDLE_EXIT_SHOW_AS_HTML", - @"SP_BUNDLE_EXIT_SHOW_AS_HTML_TOOLTIP", - @"SP_BUNDLE_EXIT_SHOW_AS_TEXT_TOOLTIP", - @"SP_BUNDLE_INPUT", - @"SP_BUNDLE_INPUT_TABLE_METADATA", - @"SP_BUNDLE_PATH", - @"SP_BUNDLE_SCOPE", - @"SP_CURRENT_EDITED_COLUMN_NAME", - @"SP_CURRENT_EDITED_TABLE", - @"SP_CURRENT_HOST", - @"SP_CURRENT_LINE", - @"SP_CURRENT_PORT", - @"SP_CURRENT_QUERY", - @"SP_CURRENT_USER", - @"SP_CURRENT_WORD", - @"SP_DATA_TABLE_SOURCE", - @"SP_DATABASE_ENCODING", - @"SP_ICON_FILE", - @"SP_PROCESS_ID", - @"SP_QUERY_FILE", - @"SP_QUERY_RESULT_FILE", - @"SP_QUERY_RESULT_META_FILE", - @"SP_QUERY_RESULT_STATUS_FILE", - @"SP_RDBMS_TYPE", - @"SP_RDBMS_VERSION", - @"SP_SELECTED_DATABASE", - @"SP_SELECTED_ROW_INDICES", - @"SP_SELECTED_TABLE", - @"SP_SELECTED_TABLES", - @"SP_USED_QUERY_FOR_TABLE", + SPBundleShellVariableAllDatabases, + SPBundleShellVariableAllFunctions, + SPBundleShellVariableAllProcedures, + SPBundleShellVariableAllTables, + SPBundleShellVariableAllViews, + SPBundleShellVariableAppResourcesDirectory, + SPBundleShellVariableBlobFileDirectory, + SPBundleShellVariableExitInsertAsSnippet, + SPBundleShellVariableExitInsertAsText, + SPBundleShellVariableExitNone, + SPBundleShellVariableExitReplaceContent, + SPBundleShellVariableExitReplaceSelection, + SPBundleShellVariableExitInsertAsHTML, + SPBundleShellVariableExitInsertAsHTMLTooltip, + SPBundleShellVariableExitInsertAsTextTooltip, + SPBundleShellVariableInputFilePath, + SPBundleShellVariableInputTableMetaData, + SPBundleShellVariableBundlePath, + SPBundleShellVariableBundleScope, + SPBundleShellVariableCurrentEditedColumnName, + SPBundleShellVariableCurrentEditedTable, + SPBundleShellVariableCurrentHost, + SPBundleShellVariableCurrentLine, + SPBundleShellVariableCurrentPort, + SPBundleShellVariableCurrentQuery, + SPBundleShellVariableCurrentUser, + SPBundleShellVariableCurrentWord, + SPBundleShellVariableDataTableSource, + SPBundleShellVariableDatabaseEncoding, + SPBundleShellVariableIconFile, + SPBundleShellVariableProcessID, + SPBundleShellVariableQueryFile, + SPBundleShellVariableQueryResultFile, + SPBundleShellVariableQueryResultMetaFile, + SPBundleShellVariableQueryResultStatusFile, + SPBundleShellVariableRDBMSType, + SPBundleShellVariableRDBMSVersion, + SPBundleShellVariableSelectedDatabase, + SPBundleShellVariableSelectedRowIndices, + SPBundleShellVariableSelectedTable, + SPBundleShellVariableSelectedTables, + SPBundleShellVariableSelectedText, + SPBundleShellVariableUsedQueryForTable, nil ] retain]; diff --git a/Source/SPBundleHTMLOutputController.m b/Source/SPBundleHTMLOutputController.m index 365c15a3..a632a51a 100644 --- a/Source/SPBundleHTMLOutputController.m +++ b/Source/SPBundleHTMLOutputController.m @@ -304,19 +304,28 @@ - (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame { - SPBeginAlertSheet(NSLocalizedString(@"JavaScript Alert", @"javascript alert"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self window], self, nil, nil, - [message description]); + NSAlert *alert = [[NSAlert alloc] init]; + [alert addButtonWithTitle:NSLocalizedString(@"OK", @"OK button")]; + [alert setInformativeText:(message)?:@""]; + [alert setMessageText:@"JavaScript"]; + [alert runModal]; + [alert release]; } - (BOOL)webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame { - NSLog(@"confirm"); - return NO; -} + NSAlert *alert = [[NSAlert alloc] init]; + [alert addButtonWithTitle:NSLocalizedString(@"OK", @"OK button")]; + [alert addButtonWithTitle:NSLocalizedString(@"Cancel", @"cancel button")]; + [alert setInformativeText:(message)?:@""]; + [alert setMessageText:@"JavaScript"]; -- (NSString *)webView:(WebView *)sender runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)defaultText initiatedByFrame:(WebFrame *)frame -{ - return @"be patient"; + NSUInteger returnCode = [alert runModal]; + + [alert release]; + + if(returnCode == NSAlertFirstButtonReturn) return YES; + return NO; } - (void)webView:(WebView *)sender windowScriptObjectAvailable: (WebScriptObject *)windowScriptObject @@ -328,6 +337,10 @@ { if (aSelector == @selector(run:)) return @"run"; + if (aSelector == @selector(getShellEnvironmentForName:)) + return @"getShellEnvironmentForName"; + if (aSelector == @selector(makeHTMLOutputWindowKeyWindow)) + return @"makeHTMLOutputWindowKeyWindow"; return @""; } @@ -335,6 +348,12 @@ if (selector == @selector(run:)) { return NO; } + if (selector == @selector(getShellEnvironmentForName:)) { + return NO; + } + if (selector == @selector(makeHTMLOutputWindowKeyWindow)) { + return NO; + } return YES; } @@ -342,13 +361,41 @@ if (strcmp(property, "run") == 0) { return NO; } + if (strcmp(property, "getShellEnvironmentForName") == 0) { + return NO; + } + if (strcmp(property, "makeHTMLOutputWindowKeyWindow") == 0) { + return NO; + } return YES; } -- (void) windowScriptObjectAvailable:(WebScriptObject*)webScriptObject { +- (void)windowScriptObjectAvailable:(WebScriptObject*)webScriptObject { [webScriptObject setValue:self forKey:@"system"]; } +/** + * JavaScript window.system.getShellEnvironmentForName('a_key') function to + * return the value for key keyName + */ +- (NSString *)getShellEnvironmentForName:(NSString*)keyName +{ + return [[[NSApp delegate] shellEnvironment] objectForKey:keyName]; +} + +/** + * JavaScript window.system.makeHTMLOutputWindowKeyWindow() function + * to make the HTML output window the first responder + */ +- (void)makeHTMLOutputWindowKeyWindow +{ + [[self window] makeKeyAndOrderFront:nil]; +} + +/** + * JavaScript window.system.run('a_command'|new Array('a_command', 'uuid')) function + * to return the result of the BASH command a_command + */ - (NSString *)run:(id)call { @@ -376,12 +423,6 @@ if(!command) return @"No JavaScript command found."; - // Check for internal commands passed via JavaScript - if([command isEqualToString:@"_SP_self_makeKeyWindow"]) { - [[self window] makeKeyAndOrderFront:nil]; - return @""; - } - NSString *output = nil; if(uuid == nil) output = [command runBashCommandWithEnvironment:nil atCurrentDirectoryPath:nil error:&err]; diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m index 89dc6405..b7f42654 100644 --- a/Source/SPConnectionController.m +++ b/Source/SPConnectionController.m @@ -369,7 +369,7 @@ static const NSString *SPExportFavoritesFilename = @"SequelProFavorites.plist"; if (![node isGroup]) { [self initiateConnection:self]; } - // Otherwise start editing the group item's name + // Otherwise start editing the group node's name else { [favoritesOutlineView editColumn:0 row:[favoritesOutlineView selectedRow] withEvent:nil select:YES]; } diff --git a/Source/SPConstants.h b/Source/SPConstants.h index 35238a07..3c5f7072 100644 --- a/Source/SPConstants.h +++ b/Source/SPConstants.h @@ -497,12 +497,41 @@ extern NSString *SPBundleShellVariableQueryResultFile; extern NSString *SPBundleShellVariableQueryResultStatusFile; extern NSString *SPBundleShellVariableQueryResultMetaFile; extern NSString *SPBundleShellVariableInputTableMetaData; -extern NSString *SPBundleShellVariableScope; +extern NSString *SPBundleShellVariableBundleScope; extern NSString *SPBundleShellVariableUsedQueryForTable; extern NSString *SPBundleShellVariableCurrentEditedColumnName; extern NSString *SPBundleShellVariableSelectedTable; extern NSString *SPBundleShellVariableCurrentEditedTable; extern NSString *SPBundleShellVariableDataTableSource; +extern NSString *SPBundleShellVariableCurrentQuery; +extern NSString *SPBundleShellVariableSelectedText; +extern NSString *SPBundleShellVariableCurrentWord; +extern NSString *SPBundleShellVariableCurrentLine; +extern NSString *SPBundleShellVariableSelectedRowIndices; +extern NSString *SPBundleShellVariableAllDatabases; +extern NSString *SPBundleShellVariableSelectedTables; +extern NSString *SPBundleShellVariableSelectedDatabase; +extern NSString *SPBundleShellVariableRDBMSVersion; +extern NSString *SPBundleShellVariableRDBMSType; +extern NSString *SPBundleShellVariableProcessID; +extern NSString *SPBundleShellVariableIconFile; +extern NSString *SPBundleShellVariableAppResourcesDirectory; +extern NSString *SPBundleShellVariableExitNone; +extern NSString *SPBundleShellVariableExitReplaceSelection; +extern NSString *SPBundleShellVariableExitReplaceContent; +extern NSString *SPBundleShellVariableExitInsertAsText; +extern NSString *SPBundleShellVariableExitInsertAsSnippet; +extern NSString *SPBundleShellVariableExitInsertAsHTML; +extern NSString *SPBundleShellVariableExitInsertAsTextTooltip; +extern NSString *SPBundleShellVariableExitInsertAsHTMLTooltip; +extern NSString *SPBundleShellVariableCurrentHost; +extern NSString *SPBundleShellVariableCurrentUser; +extern NSString *SPBundleShellVariableCurrentPort; +extern NSString *SPBundleShellVariableDatabaseEncoding; +extern NSString *SPBundleShellVariableAllProcedures; +extern NSString *SPBundleShellVariableAllFunctions; +extern NSString *SPBundleShellVariableAllViews; +extern NSString *SPBundleShellVariableAllTables; extern const NSInteger SPBundleRedirectActionNone; extern const NSInteger SPBundleRedirectActionReplaceSection; diff --git a/Source/SPConstants.m b/Source/SPConstants.m index ece44709..82b9b2f3 100644 --- a/Source/SPConstants.m +++ b/Source/SPConstants.m @@ -301,21 +301,50 @@ NSString *SPBundleTaskScriptCommandFilePath = @"/tmp/SP_BUNDLE_S NSString *SPBundleTaskCopyBlobFileDirectory = @"/tmp/SP_BUNDLE_COPY_BLOB_FILES"; NSString *SPBundleTaskTableMetaDataFilePath = @"/tmp/SP_BUNDLE_TABLE_META_DATA"; +NSString *SPBundleShellVariableAllDatabases = @"SP_ALL_DATABASES"; +NSString *SPBundleShellVariableAllFunctions = @"SP_ALL_FUNCTIONS"; +NSString *SPBundleShellVariableAllProcedures = @"SP_ALL_PROCEDURES"; +NSString *SPBundleShellVariableAllTables = @"SP_ALL_TABLES"; +NSString *SPBundleShellVariableAllViews = @"SP_ALL_VIEWS"; +NSString *SPBundleShellVariableAppResourcesDirectory = @"SP_APP_RESOURCES_DIRECTORY"; +NSString *SPBundleShellVariableBlobFileDirectory = @"SP_BUNDLE_BLOB_FILES_DIRECTORY"; +NSString *SPBundleShellVariableBundlePath = @"SP_BUNDLE_PATH"; +NSString *SPBundleShellVariableBundleScope = @"SP_BUNDLE_SCOPE"; +NSString *SPBundleShellVariableCurrentEditedColumnName = @"SP_CURRENT_EDITED_COLUMN_NAME"; +NSString *SPBundleShellVariableCurrentEditedTable = @"SP_CURRENT_EDITED_TABLE"; +NSString *SPBundleShellVariableCurrentHost = @"SP_CURRENT_HOST"; +NSString *SPBundleShellVariableCurrentLine = @"SP_CURRENT_LINE"; +NSString *SPBundleShellVariableCurrentPort = @"SP_CURRENT_PORT"; +NSString *SPBundleShellVariableCurrentQuery = @"SP_CURRENT_QUERY"; +NSString *SPBundleShellVariableCurrentUser = @"SP_CURRENT_USER"; +NSString *SPBundleShellVariableCurrentWord = @"SP_CURRENT_WORD"; +NSString *SPBundleShellVariableDatabaseEncoding = @"SP_DATABASE_ENCODING"; +NSString *SPBundleShellVariableDataTableSource = @"SP_DATA_TABLE_SOURCE"; +NSString *SPBundleShellVariableExitInsertAsHTML = @"SP_BUNDLE_EXIT_SHOW_AS_HTML"; +NSString *SPBundleShellVariableExitInsertAsHTMLTooltip = @"SP_BUNDLE_EXIT_SHOW_AS_HTML_TOOLTIP"; +NSString *SPBundleShellVariableExitInsertAsSnippet = @"SP_BUNDLE_EXIT_INSERT_AS_SNIPPET"; +NSString *SPBundleShellVariableExitInsertAsText = @"SP_BUNDLE_EXIT_INSERT_AS_TEXT"; +NSString *SPBundleShellVariableExitInsertAsTextTooltip = @"SP_BUNDLE_EXIT_SHOW_AS_TEXT_TOOLTIP"; +NSString *SPBundleShellVariableExitNone = @"SP_BUNDLE_EXIT_NONE"; +NSString *SPBundleShellVariableExitReplaceContent = @"SP_BUNDLE_EXIT_REPLACE_CONTENT"; +NSString *SPBundleShellVariableExitReplaceSelection = @"SP_BUNDLE_EXIT_REPLACE_SELECTION"; +NSString *SPBundleShellVariableIconFile = @"SP_ICON_FILE"; NSString *SPBundleShellVariableInputFilePath = @"SP_BUNDLE_INPUT"; +NSString *SPBundleShellVariableInputTableMetaData = @"SP_BUNDLE_INPUT_TABLE_METADATA"; NSString *SPBundleShellVariableOutputFilePath = @"SP_BUNDLE_OUTPUT"; -NSString *SPBundleShellVariableBundlePath = @"SP_BUNDLE_PATH"; -NSString *SPBundleShellVariableBlobFileDirectory = @"SP_BUNDLE_BLOB_FILES_DIRECTORY"; +NSString *SPBundleShellVariableProcessID = @"SP_PROCESS_ID"; NSString *SPBundleShellVariableQueryFile = @"SP_QUERY_FILE"; NSString *SPBundleShellVariableQueryResultFile = @"SP_QUERY_RESULT_FILE"; -NSString *SPBundleShellVariableQueryResultStatusFile = @"SP_QUERY_RESULT_STATUS_FILE"; NSString *SPBundleShellVariableQueryResultMetaFile = @"SP_QUERY_RESULT_META_FILE"; -NSString *SPBundleShellVariableInputTableMetaData = @"SP_BUNDLE_INPUT_TABLE_METADATA"; -NSString *SPBundleShellVariableScope = @"SP_BUNDLE_SCOPE"; -NSString *SPBundleShellVariableUsedQueryForTable = @"SP_USED_QUERY_FOR_TABLE"; -NSString *SPBundleShellVariableCurrentEditedColumnName = @"SP_CURRENT_EDITED_COLUMN_NAME"; +NSString *SPBundleShellVariableQueryResultStatusFile = @"SP_QUERY_RESULT_STATUS_FILE"; +NSString *SPBundleShellVariableRDBMSType = @"SP_RDBMS_TYPE"; +NSString *SPBundleShellVariableRDBMSVersion = @"SP_RDBMS_VERSION"; +NSString *SPBundleShellVariableSelectedDatabase = @"SP_SELECTED_DATABASE"; +NSString *SPBundleShellVariableSelectedRowIndices = @"SP_SELECTED_ROW_INDICES"; NSString *SPBundleShellVariableSelectedTable = @"SP_SELECTED_TABLE"; -NSString *SPBundleShellVariableCurrentEditedTable = @"SP_CURRENT_EDITED_TABLE"; -NSString *SPBundleShellVariableDataTableSource = @"SP_DATA_TABLE_SOURCE"; +NSString *SPBundleShellVariableSelectedTables = @"SP_SELECTED_TABLES"; +NSString *SPBundleShellVariableSelectedText = @"SP_SELECTED_TEXT"; +NSString *SPBundleShellVariableUsedQueryForTable = @"SP_USED_QUERY_FOR_TABLE"; const NSInteger SPBundleRedirectActionNone = 200; const NSInteger SPBundleRedirectActionReplaceSection = 201; diff --git a/Source/SPCopyTable.m b/Source/SPCopyTable.m index 3c665693..7a132348 100644 --- a/Source/SPCopyTable.m +++ b/Source/SPCopyTable.m @@ -1153,7 +1153,7 @@ NSInteger kBlobAsImageFile = 4; [env setObject:[[self delegate] usedQuery] forKey:SPBundleShellVariableUsedQueryForTable]; [env setObject:bundleInputTableMetaDataFilePath forKey:SPBundleShellVariableInputTableMetaData]; - [env setObject:SPBundleScopeDataTable forKey:SPBundleShellVariableScope]; + [env setObject:SPBundleScopeDataTable forKey:SPBundleShellVariableBundleScope]; if([self numberOfSelectedRows]) { NSMutableArray *sel = [NSMutableArray array]; @@ -1163,7 +1163,7 @@ NSInteger kBlobAsImageFile = 4; [sel addObject:[NSString stringWithFormat:@"%ld", rowIndex]]; rowIndex = [selectedRows indexGreaterThanIndex:rowIndex]; } - [env setObject:[sel componentsJoinedByString:@"\t"] forKey:@"SP_SELECTED_ROW_INDICES"]; + [env setObject:[sel componentsJoinedByString:@"\t"] forKey:SPBundleShellVariableSelectedRowIndices]; } NSError *inputFileError = nil; diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index a7b85c21..a65dab2b 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -4820,47 +4820,47 @@ if (tablesListInstance) { if([tablesListInstance selectedDatabase]) - [env setObject:[tablesListInstance selectedDatabase] forKey:@"SP_SELECTED_DATABASE"]; + [env setObject:[tablesListInstance selectedDatabase] forKey:SPBundleShellVariableSelectedDatabase]; if ([tablesListInstance tableName]) [env setObject:[tablesListInstance tableName] forKey:SPBundleShellVariableSelectedTable]; if ([tablesListInstance selectedTableItems]) - [env setObject:[[tablesListInstance selectedTableItems] componentsJoinedByString:@"\t"] forKey:@"SP_SELECTED_TABLES"]; + [env setObject:[[tablesListInstance selectedTableItems] componentsJoinedByString:@"\t"] forKey:SPBundleShellVariableSelectedTables]; if ([tablesListInstance allDatabaseNames]) - [env setObject:[[tablesListInstance allDatabaseNames] componentsJoinedByString:@"\t"] forKey:@"SP_ALL_DATABASES"]; + [env setObject:[[tablesListInstance allDatabaseNames] componentsJoinedByString:@"\t"] forKey:SPBundleShellVariableAllDatabases]; if ([tablesListInstance allTableNames]) - [env setObject:[[tablesListInstance allTableNames] componentsJoinedByString:@"\t"] forKey:@"SP_ALL_TABLES"]; + [env setObject:[[tablesListInstance allTableNames] componentsJoinedByString:@"\t"] forKey:SPBundleShellVariableAllTables]; if ([tablesListInstance allViewNames]) - [env setObject:[[tablesListInstance allViewNames] componentsJoinedByString:@"\t"] forKey:@"SP_ALL_VIEWS"]; + [env setObject:[[tablesListInstance allViewNames] componentsJoinedByString:@"\t"] forKey:SPBundleShellVariableAllViews]; if ([tablesListInstance allFunctionNames]) - [env setObject:[[tablesListInstance allFunctionNames] componentsJoinedByString:@"\t"] forKey:@"SP_ALL_FUNCTIONS"]; + [env setObject:[[tablesListInstance allFunctionNames] componentsJoinedByString:@"\t"] forKey:SPBundleShellVariableAllFunctions]; if ([tablesListInstance allProcedureNames]) - [env setObject:[[tablesListInstance allProcedureNames] componentsJoinedByString:@"\t"] forKey:@"SP_ALL_PROCEDURES"]; + [env setObject:[[tablesListInstance allProcedureNames] componentsJoinedByString:@"\t"] forKey:SPBundleShellVariableAllProcedures]; if ([self user]) - [env setObject:[self user] forKey:@"SP_CURRENT_USER"]; + [env setObject:[self user] forKey:SPBundleShellVariableCurrentUser]; if ([self host]) - [env setObject:[self host] forKey:@"SP_CURRENT_HOST"]; + [env setObject:[self host] forKey:SPBundleShellVariableCurrentHost]; if ([self port]) - [env setObject:[self port] forKey:@"SP_CURRENT_PORT"]; + [env setObject:[self port] forKey:SPBundleShellVariableCurrentPort]; - [env setObject:([self databaseEncoding])?:@"" forKey:@"SP_DATABASE_ENCODING"]; + [env setObject:([self databaseEncoding])?:@"" forKey:SPBundleShellVariableDatabaseEncoding]; } if(1) - [env setObject:@"mysql" forKey:@"SP_RDBMS_TYPE"]; + [env setObject:@"mysql" forKey:SPBundleShellVariableRDBMSType]; if([self mySQLVersion]) - [env setObject:[self mySQLVersion] forKey:@"SP_RDBMS_VERSION"]; + [env setObject:[self mySQLVersion] forKey:SPBundleShellVariableRDBMSVersion]; return (NSDictionary*)env; } @@ -5293,14 +5293,18 @@ if ([chooseDatabaseButton indexOfItemWithTitle:targetDatabaseName] == NSNotFound || ![mySQLConnection selectDB:targetDatabaseName]) { + + // End the task first to ensure the database dropdown can be reselected + [self endTask]; + if ( [mySQLConnection isConnected] ) { - SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, parentWindow, self, nil, nil, [NSString stringWithFormat:NSLocalizedString(@"Unable to connect to database %@.\nBe sure that you have the necessary privileges.", @"message of panel when connection to db failed after selecting from popupbutton"), targetDatabaseName]); // Update the database list [[self onMainThread] setDatabases:self]; + + SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, parentWindow, self, nil, nil, [NSString stringWithFormat:NSLocalizedString(@"Unable to select database %@.\nPlease check you have the necessary privileges to view the database, and that the database still exists.", @"message of panel when connection to db failed after selecting from popupbutton"), targetDatabaseName]); } - [self endTask]; [taskPool drain]; return; } diff --git a/Source/SPStringAdditions.m b/Source/SPStringAdditions.m index a3098750..b523907c 100644 --- a/Source/SPStringAdditions.m +++ b/Source/SPStringAdditions.m @@ -519,16 +519,16 @@ NSMutableDictionary *theEnv = [NSMutableDictionary dictionary]; [theEnv setDictionary:shellEnvironment]; - [theEnv setObject:[[NSBundle mainBundle] pathForResource:@"appicon" ofType:@"icns"] forKey:@"SP_ICON_FILE"]; - [theEnv setObject:[NSString stringWithFormat:@"%@/Contents/Resources", [[NSBundle mainBundle] bundlePath]] forKey:@"SP_APP_RESOURCES_DIRECTORY"]; - [theEnv setObject:[NSNumber numberWithInteger:SPBundleRedirectActionNone] forKey:@"SP_BUNDLE_EXIT_NONE"]; - [theEnv setObject:[NSNumber numberWithInteger:SPBundleRedirectActionReplaceSection] forKey:@"SP_BUNDLE_EXIT_REPLACE_SELECTION"]; - [theEnv setObject:[NSNumber numberWithInteger:SPBundleRedirectActionReplaceContent] forKey:@"SP_BUNDLE_EXIT_REPLACE_CONTENT"]; - [theEnv setObject:[NSNumber numberWithInteger:SPBundleRedirectActionInsertAsText] forKey:@"SP_BUNDLE_EXIT_INSERT_AS_TEXT"]; - [theEnv setObject:[NSNumber numberWithInteger:SPBundleRedirectActionInsertAsSnippet] forKey:@"SP_BUNDLE_EXIT_INSERT_AS_SNIPPET"]; - [theEnv setObject:[NSNumber numberWithInteger:SPBundleRedirectActionShowAsHTML] forKey:@"SP_BUNDLE_EXIT_SHOW_AS_HTML"]; - [theEnv setObject:[NSNumber numberWithInteger:SPBundleRedirectActionShowAsTextTooltip] forKey:@"SP_BUNDLE_EXIT_SHOW_AS_TEXT_TOOLTIP"]; - [theEnv setObject:[NSNumber numberWithInteger:SPBundleRedirectActionShowAsHTMLTooltip] forKey:@"SP_BUNDLE_EXIT_SHOW_AS_HTML_TOOLTIP"]; + [theEnv setObject:[[NSBundle mainBundle] pathForResource:@"appicon" ofType:@"icns"] forKey:SPBundleShellVariableIconFile]; + [theEnv setObject:[NSString stringWithFormat:@"%@/Contents/Resources", [[NSBundle mainBundle] bundlePath]] forKey:SPBundleShellVariableAppResourcesDirectory]; + [theEnv setObject:[NSNumber numberWithInteger:SPBundleRedirectActionNone] forKey:SPBundleShellVariableExitNone]; + [theEnv setObject:[NSNumber numberWithInteger:SPBundleRedirectActionReplaceSection] forKey:SPBundleShellVariableExitReplaceSelection]; + [theEnv setObject:[NSNumber numberWithInteger:SPBundleRedirectActionReplaceContent] forKey:SPBundleShellVariableExitReplaceContent]; + [theEnv setObject:[NSNumber numberWithInteger:SPBundleRedirectActionInsertAsText] forKey:SPBundleShellVariableExitInsertAsText]; + [theEnv setObject:[NSNumber numberWithInteger:SPBundleRedirectActionInsertAsSnippet] forKey:SPBundleShellVariableExitInsertAsSnippet]; + [theEnv setObject:[NSNumber numberWithInteger:SPBundleRedirectActionShowAsHTML] forKey:SPBundleShellVariableExitInsertAsHTML]; + [theEnv setObject:[NSNumber numberWithInteger:SPBundleRedirectActionShowAsTextTooltip] forKey:SPBundleShellVariableExitInsertAsTextTooltip]; + [theEnv setObject:[NSNumber numberWithInteger:SPBundleRedirectActionShowAsHTMLTooltip] forKey:SPBundleShellVariableExitInsertAsHTMLTooltip]; // Create and set an unique process ID for each SPDatabaseDocument which has to passed // for each sequelpro:// scheme command as user to be able to identify the url scheme command. @@ -558,7 +558,7 @@ [doc setProcessID:uuid]; - [theEnv setObject:uuid forKey:@"SP_PROCESS_ID"]; + [theEnv setObject:uuid forKey:SPBundleShellVariableProcessID]; [theEnv setObject:[NSString stringWithFormat:@"%@%@", SPURLSchemeQueryInputPathHeader, uuid] forKey:SPBundleShellVariableQueryFile]; [theEnv setObject:[NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultPathHeader, uuid] forKey:SPBundleShellVariableQueryResultFile]; [theEnv setObject:[NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultStatusPathHeader, uuid] forKey:SPBundleShellVariableQueryResultStatusFile]; diff --git a/Source/SPTextViewAdditions.m b/Source/SPTextViewAdditions.m index 5dd7d06c..11defa20 100644 --- a/Source/SPTextViewAdditions.m +++ b/Source/SPTextViewAdditions.m @@ -576,7 +576,7 @@ NSMutableDictionary *env = [NSMutableDictionary dictionary]; [env setObject:[infoPath stringByDeletingLastPathComponent] forKey:SPBundleShellVariableBundlePath]; [env setObject:bundleInputFilePath forKey:SPBundleShellVariableInputFilePath]; - [env setObject:SPBundleScopeInputField forKey:SPBundleShellVariableScope]; + [env setObject:SPBundleScopeInputField forKey:SPBundleShellVariableBundleScope]; id tableSource = [self delegate]; if([[[tableSource class] description] isEqualToString:@"SPFieldEditorController"]) { @@ -611,16 +611,16 @@ } if(selfIsQueryEditor && [[self delegate] currentQueryRange].length) - [env setObject:[[self string] substringWithRange:[[self delegate] currentQueryRange]] forKey:@"SP_CURRENT_QUERY"]; + [env setObject:[[self string] substringWithRange:[[self delegate] currentQueryRange]] forKey:SPBundleShellVariableCurrentQuery]; if(currentSelectionRange.length) - [env setObject:[[self string] substringWithRange:currentSelectionRange] forKey:@"SP_SELECTED_TEXT"]; + [env setObject:[[self string] substringWithRange:currentSelectionRange] forKey:SPBundleShellVariableSelectedText]; if(currentWordRange.length) - [env setObject:[[self string] substringWithRange:currentWordRange] forKey:@"SP_CURRENT_WORD"]; + [env setObject:[[self string] substringWithRange:currentWordRange] forKey:SPBundleShellVariableCurrentWord]; if(currentLineRange.length) - [env setObject:[[self string] substringWithRange:currentLineRange] forKey:@"SP_CURRENT_LINE"]; + [env setObject:[[self string] substringWithRange:currentLineRange] forKey:SPBundleShellVariableCurrentLine]; NSError *inputFileError = nil; NSString *input = [NSString stringWithString:[[self string] substringWithRange:replaceRange]]; |