From 3187b984cc76491bf1aabacdf8b2deb5046eaf0a Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 9 Dec 2010 20:54:16 +0000 Subject: =?UTF-8?q?=E2=80=A2=20Bundle=20Commands=20-=20added=20shell=20var?= =?UTF-8?q?s=20SP=5FCURRENT=5FEDITED=5FCOLUMN=5FNAME,=20SP=5FCURRENT=5FEDI?= =?UTF-8?q?TED=5FTABLE=20for=20Input=20Field=20scoped=20commands=20if=20in?= =?UTF-8?q?voked=20from=20a=20table=20cell=20field=20editor=20-=20added=20?= =?UTF-8?q?shell=20var=20SP=5FTABLE=5FDATA=5FSOURCE=20(content=20or=20quer?= =?UTF-8?q?y)=20-=20fixed=20table=20row=20change=20trigger=20for=20custom?= =?UTF-8?q?=20query=20tableView?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPBundleEditorController.m | 3 +++ Source/SPConstants.h | 5 ++++ Source/SPConstants.m | 5 ++++ Source/SPCopyTable.m | 4 +++- Source/SPCustomQuery.m | 48 +++++++++++++++++++++++++++++++++++++++ Source/SPDatabaseDocument.m | 2 +- Source/SPStringAdditions.m | 3 +++ Source/SPTextViewAdditions.m | 25 ++++++++++++++++++++ 8 files changed, 93 insertions(+), 2 deletions(-) diff --git a/Source/SPBundleEditorController.m b/Source/SPBundleEditorController.m index 4091e606..1aced5e8 100644 --- a/Source/SPBundleEditorController.m +++ b/Source/SPBundleEditorController.m @@ -327,12 +327,15 @@ @"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", diff --git a/Source/SPConstants.h b/Source/SPConstants.h index 1e48f2c2..d6a0ee5f 100644 --- a/Source/SPConstants.h +++ b/Source/SPConstants.h @@ -502,6 +502,11 @@ extern NSString *SPBundleShellVariableQueryResultStatusFile; extern NSString *SPBundleShellVariableQueryResultMetaFile; extern NSString *SPBundleShellVariableInputTableMetaData; extern NSString *SPBundleShellVariableScope; +extern NSString *SPBundleShellVariableUsedQueryForTable; +extern NSString *SPBundleShellVariableCurrentEditedColumnName; +extern NSString *SPBundleShellVariableSelectedTable; +extern NSString *SPBundleShellVariableCurrentEditedTable; +extern NSString *SPBundleShellVariableDataTableSource; extern const NSInteger SPBundleRedirectActionNone; extern const NSInteger SPBundleRedirectActionReplaceSection; diff --git a/Source/SPConstants.m b/Source/SPConstants.m index cd683a5b..67c51b53 100644 --- a/Source/SPConstants.m +++ b/Source/SPConstants.m @@ -315,6 +315,11 @@ NSString *SPBundleShellVariableQueryResultStatusFile = @"SP_QUERY_RESULT_ 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 *SPBundleShellVariableSelectedTable = @"SP_SELECTED_TABLE"; +NSString *SPBundleShellVariableCurrentEditedTable = @"SP_CURRENT_EDITED_TABLE"; +NSString *SPBundleShellVariableDataTableSource = @"SP_DATA_TABLE_SOURCE"; const NSInteger SPBundleRedirectActionNone = 200; const NSInteger SPBundleRedirectActionReplaceSection = 201; diff --git a/Source/SPCopyTable.m b/Source/SPCopyTable.m index 58339976..3c665693 100644 --- a/Source/SPCopyTable.m +++ b/Source/SPCopyTable.m @@ -1150,7 +1150,7 @@ NSInteger kBlobAsImageFile = 4; [env setObject:bundleInputFilePath forKey:SPBundleShellVariableInputFilePath]; if([[self delegate] respondsToSelector:@selector(usedQuery)] && [[self delegate] usedQuery]) - [env setObject:[[self delegate] usedQuery] forKey:@"SP_USED_QUERY_FOR_TABLE"]; + [env setObject:[[self delegate] usedQuery] forKey:SPBundleShellVariableUsedQueryForTable]; [env setObject:bundleInputTableMetaDataFilePath forKey:SPBundleShellVariableInputTableMetaData]; [env setObject:SPBundleScopeDataTable forKey:SPBundleShellVariableScope]; @@ -1223,6 +1223,7 @@ NSInteger kBlobAsImageFile = 4; NSMutableString *tableMetaData = [NSMutableString string]; if([[self delegate] isKindOfClass:[SPCustomQuery class]]) { + [env setObject:@"query" forKey:SPBundleShellVariableDataTableSource]; NSArray *defs = [[self delegate] dataColumnDefinitions]; for(NSDictionary* col in defs) { [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"type"]]; @@ -1235,6 +1236,7 @@ NSInteger kBlobAsImageFile = 4; } } else if([[self delegate] isKindOfClass:[SPTableContent class]]) { + [env setObject:@"content" forKey:SPBundleShellVariableDataTableSource]; NSArray *defs = [[self delegate] dataColumnDefinitions]; for(NSDictionary* col in defs) { [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"type"]]; diff --git a/Source/SPCustomQuery.m b/Source/SPCustomQuery.m index ef38461c..c313edaf 100644 --- a/Source/SPCustomQuery.m +++ b/Source/SPCustomQuery.m @@ -2385,6 +2385,54 @@ #pragma mark - #pragma mark TableView notifications +/** + * Check triggering of Bundle command for row selection changes + */ +- (void)tableViewSelectionDidChange:(NSNotification *)aNotification +{ + + // Check our notification object is our table content view + if ([aNotification object] != customQueryView) return; + + NSArray *triggeredCommands = [[NSApp delegate] bundleCommandsForTrigger:SPBundleTriggerActionTableRowChanged]; + for(NSString* cmdPath in triggeredCommands) { + NSArray *data = [cmdPath componentsSeparatedByString:@"|"]; + NSMenuItem *aMenuItem = [[[NSMenuItem alloc] init] autorelease]; + [aMenuItem setTag:0]; + [aMenuItem setToolTip:[data objectAtIndex:0]]; + + // For HTML output check if corresponding window already exists + BOOL stopTrigger = NO; + if([[data objectAtIndex:2] length]) { + BOOL correspondingWindowFound = NO; + NSString *uuid = [data objectAtIndex:2]; + for(id win in [NSApp windows]) { + if([[[[win delegate] class] description] isEqualToString:@"SPBundleHTMLOutputController"]) { + if([[[win delegate] windowUUID] isEqualToString:uuid]) { + correspondingWindowFound = YES; + break; + } + } + } + if(!correspondingWindowFound) stopTrigger = YES; + } + if(!stopTrigger) { + if([[data objectAtIndex:1] isEqualToString:SPBundleScopeGeneral]) { + [[[NSApp delegate] onMainThread] executeBundleItemForApp:aMenuItem]; + } + else if([[data objectAtIndex:1] isEqualToString:SPBundleScopeDataTable]) { + if([[[[[NSApp mainWindow] firstResponder] class] description] isEqualToString:@"SPCopyTable"]) + [[[[NSApp mainWindow] firstResponder] onMainThread] executeBundleItemForDataTable:aMenuItem]; + } + else if([[data objectAtIndex:1] isEqualToString:SPBundleScopeInputField]) { + if([[[NSApp mainWindow] firstResponder] isKindOfClass:[NSTextView class]]) + [[[[NSApp mainWindow] firstResponder] onMainThread] executeBundleItemForInputField:aMenuItem]; + } + } + } + +} + /** * Saves the new column size in the preferences for columns which map to fields */ diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index 5f05573c..216a3004 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -4823,7 +4823,7 @@ [env setObject:[tablesListInstance selectedDatabase] forKey:@"SP_SELECTED_DATABASE"]; if ([tablesListInstance tableName]) - [env setObject:[tablesListInstance tableName] forKey:@"SP_SELECTED_TABLE"]; + [env setObject:[tablesListInstance tableName] forKey:SPBundleShellVariableSelectedTable]; if ([tablesListInstance selectedTableItems]) [env setObject:[[tablesListInstance selectedTableItems] componentsJoinedByString:@"\t"] forKey:@"SP_SELECTED_TABLES"]; diff --git a/Source/SPStringAdditions.m b/Source/SPStringAdditions.m index 012f365c..4b06a028 100644 --- a/Source/SPStringAdditions.m +++ b/Source/SPStringAdditions.m @@ -567,6 +567,9 @@ if([doc shellVariables]) [theEnv addEntriesFromDictionary:[doc shellVariables]]; + if([theEnv objectForKey:SPBundleShellVariableCurrentEditedColumnName] && [[theEnv objectForKey:SPBundleShellVariableDataTableSource] isEqualToString:@"content"]) + [theEnv setObject:[theEnv objectForKey:SPBundleShellVariableSelectedTable] forKey:SPBundleShellVariableCurrentEditedTable]; + } if(theEnv != nil && [theEnv count]) diff --git a/Source/SPTextViewAdditions.m b/Source/SPTextViewAdditions.m index 6ca111b5..c85b5c51 100644 --- a/Source/SPTextViewAdditions.m +++ b/Source/SPTextViewAdditions.m @@ -578,6 +578,31 @@ [env setObject:bundleInputFilePath forKey:SPBundleShellVariableInputFilePath]; [env setObject:SPBundleScopeInputField forKey:SPBundleShellVariableScope]; + + id tableSource = [self delegate]; + if([[[tableSource class] description] isEqualToString:@"SPCopyTable"]) { + NSInteger editedCol = [tableSource editedColumn]; + if(editedCol > -1) { + NSString *colName = [[[[tableSource tableColumns] objectAtIndex:editedCol] headerCell] stringValue]; + if([[[[tableSource dataSource] class] description] hasSuffix:@"Content"]) { + [env setObject:[colName description] forKey:SPBundleShellVariableCurrentEditedColumnName]; + [env setObject:@"content" forKey:SPBundleShellVariableDataTableSource]; + } else { + NSArray *defs = [[tableSource delegate] dataColumnDefinitions]; + for(NSDictionary* col in defs) { + if([[col objectForKey:@"name"] isEqualToString:colName]) { + [env setObject:[col objectForKey:@"org_name"] forKey:SPBundleShellVariableCurrentEditedColumnName]; + [env setObject:[col objectForKey:@"org_table"] forKey:SPBundleShellVariableCurrentEditedTable]; + break; + } + } + [env setObject:@"query" forKey:SPBundleShellVariableDataTableSource]; + } + if([[tableSource delegate] respondsToSelector:@selector(usedQuery)] && [[tableSource delegate] usedQuery]) + [env setObject:[[tableSource delegate] usedQuery] forKey:SPBundleShellVariableUsedQueryForTable]; + } + } + if(selfIsQueryEditor && [[self delegate] currentQueryRange].length) [env setObject:[[self string] substringWithRange:[[self delegate] currentQueryRange]] forKey:@"SP_CURRENT_QUERY"]; -- cgit v1.2.3