From eb5fa28ec49e2aaecb5fd38c86f42a530498267b Mon Sep 17 00:00:00 2001 From: Bibiko Date: Wed, 8 Dec 2010 19:35:24 +0000 Subject: =?UTF-8?q?=E2=80=A2=20Bundle=20Editor:=20removed=20unnecessary=20?= =?UTF-8?q?tooltip;=20replace=20menu=20item=20title=20'Save'=20by=20'Expor?= =?UTF-8?q?t'=20=E2=80=A2=20improved=20check=20whether=20a=20doc=20window?= =?UTF-8?q?=20has=20a=20connection=20or=20not=20for=20running=20a=20Bundle?= =?UTF-8?q?=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPStringAdditions.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source') diff --git a/Source/SPStringAdditions.m b/Source/SPStringAdditions.m index 97339201..012f365c 100644 --- a/Source/SPStringAdditions.m +++ b/Source/SPStringAdditions.m @@ -537,14 +537,14 @@ if([[[NSApp mainWindow] delegate] respondsToSelector:@selector(selectedTableDocument)]) doc = [[[NSApp mainWindow] delegate] selectedTableDocument]; // Check if connected - if([[doc connectionID] isEqualToString:@"_"]) + if([doc getConnection] == nil) doc = nil; else { for (NSWindow *aWindow in [NSApp orderedWindows]) { if([[[[aWindow windowController] class] description] isEqualToString:@"SPWindowController"]) { if([[[aWindow windowController] documents] count] && [[[[[[aWindow windowController] documents] objectAtIndex:0] class] description] isEqualToString:@"SPDatabaseDocument"]) { // Check if connected - if(![[[[[aWindow windowController] documents] objectAtIndex:0] connectionID] isEqualToString:@"_"]) + if([[[[aWindow windowController] documents] objectAtIndex:0] getConnection]) doc = [[[aWindow windowController] documents] objectAtIndex:0]; else doc = nil; -- cgit v1.2.3 From 34eac092acd118620c2653731e283ca8aa7fc383 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Wed, 8 Dec 2010 22:51:45 +0000 Subject: =?UTF-8?q?=E2=80=A2=20added=20Save=20Page=20As=20and=20View=20Sou?= =?UTF-8?q?rce=20to=20HTML=20output=20window's=20context=20menu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPBundleHTMLOutputController.h | 3 ++ Source/SPBundleHTMLOutputController.m | 81 ++++++++++++++++++++++++++++++++++- 2 files changed, 82 insertions(+), 2 deletions(-) (limited to 'Source') diff --git a/Source/SPBundleHTMLOutputController.h b/Source/SPBundleHTMLOutputController.h index 9ad79a1e..0ad38241 100644 --- a/Source/SPBundleHTMLOutputController.h +++ b/Source/SPBundleHTMLOutputController.h @@ -45,4 +45,7 @@ - (void)displayHTMLContent:(NSString *)content withOptions:(NSDictionary *)displayOptions; - (void)displayURLString:(NSString *)url withOptions:(NSDictionary *)displayOptions; +- (void)showSourceCode; +- (void)saveDocument; + @end diff --git a/Source/SPBundleHTMLOutputController.m b/Source/SPBundleHTMLOutputController.m index b89606f9..a630eb06 100644 --- a/Source/SPBundleHTMLOutputController.m +++ b/Source/SPBundleHTMLOutputController.m @@ -24,6 +24,7 @@ #import "SPBundleHTMLOutputController.h" +#import "SPAlertSheets.h" @@ -121,7 +122,6 @@ - (void)keyDown:(NSEvent *)theEvent { long allFlags = (NSShiftKeyMask|NSControlKeyMask|NSAlternateKeyMask|NSCommandKeyMask); - NSString *characters = [theEvent characters]; NSString *charactersIgnMod = [theEvent charactersIgnoringModifiers]; unichar insertedCharacter = [characters characterAtIndex:0]; @@ -157,11 +157,63 @@ } +/** + * Sheet did end method + */ +- (void)sheetDidEnd:(id)sheet returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo +{ + + // Order out current sheet to suppress overlapping of sheets + if ([sheet respondsToSelector:@selector(orderOut:)]) + [sheet orderOut:nil]; + else if ([sheet respondsToSelector:@selector(window)]) + [[sheet window] orderOut:nil]; + + if([contextInfo isEqualToString:@"saveDocument"]) { + if (returnCode == NSOKButton) { + NSString *sourceCode = [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('html')[0].outerHTML"]; + NSError *err = nil; + [sourceCode writeToFile:[sheet filename] + atomically:YES + encoding:NSUTF8StringEncoding + error:&err]; + if(err != nil) { + SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self window], self, nil, nil, + [NSString stringWithFormat:@"%@", [err localizedDescription]]); + } + + } + } +} + - (IBAction)printDocument:(id)sender { [[[[webView mainFrame] frameView] documentView] print:sender]; } +- (void)showSourceCode +{ + NSString *sourceCode = [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('html')[0].outerHTML"]; + SPBundleHTMLOutputController *c = [[SPBundleHTMLOutputController alloc] init]; + [c displayHTMLContent:[NSString stringWithFormat:@"
%@
", [sourceCode HTMLEscapeString]] withOptions:nil]; + [[NSApp delegate] addHTMLOutputController:c]; +} + +- (void)saveDocument +{ + NSSavePanel *panel = [NSSavePanel savePanel]; + + [panel setRequiredFileType:@"html"]; + + [panel setExtensionHidden:NO]; + [panel setAllowsOtherFileTypes:YES]; + [panel setCanSelectHiddenExtension:YES]; + [panel setCanCreateDirectories:YES]; + + [panel beginSheetForDirectory:nil file:@"output" modalForWindow:[self window] modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:@"saveDocument"]; +} + + #pragma mark - - (void)windowWillClose:(NSNotification *)notification @@ -170,11 +222,36 @@ [webView close]; [self setInitHTMLSourceString:@""]; windowUUID = @""; - // [[notification object] release]; } #pragma mark - +- (NSArray *)webView:(WebView *)sender contextMenuItemsForElement:(NSDictionary *)element defaultMenuItems:(NSArray *)defaultMenuItems +{ + NSMutableArray *webViewMenuItems = [[defaultMenuItems mutableCopy] autorelease]; + + [webViewMenuItems addObject:[NSMenuItem separatorItem]]; + + NSMenuItem *anItem; + anItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"View Source", @"view html source code menu item title") action:@selector(showSourceCode) keyEquivalent:@""]; + [anItem setEnabled:YES]; + [anItem setTarget:self]; + [webViewMenuItems addObject:anItem]; + [anItem release]; + anItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Save Page As…", @"save page as menu item title") action:@selector(saveDocument) keyEquivalent:@""]; + [anItem setEnabled:YES]; + [anItem setTarget:self]; + [webViewMenuItems addObject:anItem]; + [anItem release]; + anItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Print Page…", @"print page menu item title") action:@selector(printDocument:) keyEquivalent:@""]; + [anItem setEnabled:YES]; + [anItem setTarget:self]; + [webViewMenuItems addObject:anItem]; + [anItem release]; + + return webViewMenuItems; +} + - (WebView *)webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request { if(request != nil) { -- cgit v1.2.3 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(-) (limited to 'Source') 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 From 370e35a72e344c5a2c29ff76cdf1e84b4f475807 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 9 Dec 2010 21:26:48 +0000 Subject: =?UTF-8?q?=E2=80=A2=20Bundle=20commands=20-=20added=20the=20shell?= =?UTF-8?q?=20vars=20for=20edited=20field=20info=20as=20well=20if=20Field?= =?UTF-8?q?=20Editor=20sheet=20is=20used?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPCustomQuery.m | 7 +++++++ Source/SPFieldEditorController.h | 4 ++++ Source/SPFieldEditorController.m | 2 ++ Source/SPTableContent.m | 6 +++++- Source/SPTextViewAdditions.m | 11 +++++++++-- 5 files changed, 27 insertions(+), 3 deletions(-) (limited to 'Source') diff --git a/Source/SPCustomQuery.m b/Source/SPCustomQuery.m index c313edaf..e8420b7c 100644 --- a/Source/SPCustomQuery.m +++ b/Source/SPCustomQuery.m @@ -2342,6 +2342,13 @@ if([columnDefinition objectForKey:@"null"]) allowNULL = (![[columnDefinition objectForKey:@"null"] integerValue]); + [fieldEditor setEditedFieldInfo:[NSDictionary dictionaryWithObjectsAndKeys: + [columnDefinition objectForKey:@"org_name"], @"colName", + [columnDefinition objectForKey:@"org_table"], @"tableName", + [self usedQuery], @"usedQuery", + @"query", @"tableSource", + nil]]; + [fieldEditor setTextMaxLength:fieldLength]; [fieldEditor setFieldType:(fieldType==nil) ? @"" : fieldType]; [fieldEditor setFieldEncoding:(fieldEncoding==nil) ? @"" : fieldEncoding]; diff --git a/Source/SPFieldEditorController.h b/Source/SPFieldEditorController.h index 625e9869..568ba629 100644 --- a/Source/SPFieldEditorController.h +++ b/Source/SPFieldEditorController.h @@ -163,8 +163,12 @@ BOOL _isGeometry; NSUndoManager *esUndoManager; + NSDictionary *editedFieldInfo; + } +@property(readwrite, retain) NSDictionary *editedFieldInfo; + - (IBAction)closeEditSheet:(id)sender; - (IBAction)openEditSheet:(id)sender; - (IBAction)saveEditSheet:(id)sender; diff --git a/Source/SPFieldEditorController.m b/Source/SPFieldEditorController.m index 17595947..2e761f80 100644 --- a/Source/SPFieldEditorController.m +++ b/Source/SPFieldEditorController.m @@ -34,6 +34,8 @@ @implementation SPFieldEditorController +@synthesize editedFieldInfo; + /** * Initialise an instance of SPFieldEditorController using the XIB “FieldEditorSheet.xib”. Init the available Quciklook format by reading * EditorQuickLookTypes.plist and if given user-defined format store in the Preferences for key (SPQuickLookTypes). diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m index 4f466470..1e9bdf5f 100644 --- a/Source/SPTableContent.m +++ b/Source/SPTableContent.m @@ -4036,7 +4036,11 @@ if(fieldEditor) [fieldEditor release], fieldEditor = nil; fieldEditor = [[SPFieldEditorController alloc] init]; - + [fieldEditor setEditedFieldInfo:[NSDictionary dictionaryWithObjectsAndKeys: + [[aTableColumn headerCell] stringValue], @"colName", + [self usedQuery], @"usedQuery", + @"content", @"tableSource", + nil]]; [fieldEditor setTextMaxLength:fieldLength]; [fieldEditor setFieldType:(fieldType==nil) ? @"" : fieldType]; [fieldEditor setFieldEncoding:(fieldEncoding==nil) ? @"" : fieldEncoding]; diff --git a/Source/SPTextViewAdditions.m b/Source/SPTextViewAdditions.m index c85b5c51..5dd7d06c 100644 --- a/Source/SPTextViewAdditions.m +++ b/Source/SPTextViewAdditions.m @@ -578,9 +578,16 @@ [env setObject:bundleInputFilePath forKey:SPBundleShellVariableInputFilePath]; [env setObject:SPBundleScopeInputField forKey:SPBundleShellVariableScope]; - id tableSource = [self delegate]; - if([[[tableSource class] description] isEqualToString:@"SPCopyTable"]) { + if([[[tableSource class] description] isEqualToString:@"SPFieldEditorController"]) { + NSDictionary *editedFieldInfo = [tableSource editedFieldInfo]; + [env setObject:[editedFieldInfo objectForKey:@"colName"] forKey:SPBundleShellVariableCurrentEditedColumnName]; + if([editedFieldInfo objectForKey:@"tableName"]) + [env setObject:[editedFieldInfo objectForKey:@"tableName"] forKey:SPBundleShellVariableCurrentEditedTable]; + [env setObject:[editedFieldInfo objectForKey:@"usedQuery"] forKey:SPBundleShellVariableUsedQueryForTable]; + [env setObject:[editedFieldInfo objectForKey:@"tableSource"] forKey:SPBundleShellVariableDataTableSource]; + } + else if([[[tableSource class] description] isEqualToString:@"SPCopyTable"]) { NSInteger editedCol = [tableSource editedColumn]; if(editedCol > -1) { NSString *colName = [[[[tableSource tableColumns] objectAtIndex:editedCol] headerCell] stringValue]; -- cgit v1.2.3 From e645692c25fbd9a40e9c7ab65f33f7748f77a211 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 10 Dec 2010 10:22:25 +0000 Subject: =?UTF-8?q?=E2=80=A2=20Bundle=20command=20support=20-=20renamed=20?= =?UTF-8?q?menu=20item=20-=20minor=20code=20cleaning?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPAppController.m | 2 +- Source/SPBundleEditorController.m | 12 ------------ 2 files changed, 1 insertion(+), 13 deletions(-) (limited to 'Source') diff --git a/Source/SPAppController.m b/Source/SPAppController.m index 63011789..aa587aba 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -1364,7 +1364,7 @@ [menu addItem:[NSMenuItem separatorItem]]; [menu setAutoenablesItems:YES]; NSArray *scopes = [NSArray arrayWithObjects:SPBundleScopeInputField, SPBundleScopeDataTable, SPBundleScopeGeneral, nil]; - NSArray *scopeTitles = [NSArray arrayWithObjects:NSLocalizedString(@"Input Fields", @"input fields menu item label"), + NSArray *scopeTitles = [NSArray arrayWithObjects:NSLocalizedString(@"Input Field", @"input field menu item label"), NSLocalizedString(@"Data Table", @"data table menu item label"), NSLocalizedString(@"General", @"general menu item label"),nil]; diff --git a/Source/SPBundleEditorController.m b/Source/SPBundleEditorController.m index 1aced5e8..99da4bc4 100644 --- a/Source/SPBundleEditorController.m +++ b/Source/SPBundleEditorController.m @@ -297,11 +297,6 @@ [anItem setTag:kDataTableScopeArrayIndex]; [inputGeneralScopePopUpMenu addItem:anItem]; [anItem release]; - // [inputGeneralScopePopUpMenu addItem:[NSMenuItem separatorItem]]; - // anItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Disable Command", @"disable command menu label") action:@selector(scopeButtonChanged:) keyEquivalent:@""]; - // [anItem setTag:kDisabledScopeTag]; - // [inputGeneralScopePopUpMenu addItem:anItem]; - // [anItem release]; [scopePopupButton setMenu:inputGeneralScopePopUpMenu]; [keyEquivalentField setCanCaptureGlobalHotKeys:YES]; @@ -1041,13 +1036,6 @@ - (void)windowWillClose:(NSNotification *)notification { - // Clear some stuff if window will close to save memory - // [touchedBundleArray removeAllObjects]; - // [[[commandBundleTree objectForKey:kChildrenKey] objectAtIndex:0] setObject:[NSMutableArray array] forKey:kChildrenKey]; - // [[[commandBundleTree objectForKey:kChildrenKey] objectAtIndex:1] setObject:[NSMutableArray array] forKey:kChildrenKey]; - // [[[commandBundleTree objectForKey:kChildrenKey] objectAtIndex:2] setObject:[NSMutableArray array] forKey:kChildrenKey]; - // [commandsOutlineView reloadData]; - // Remove temporary drag file if any if(draggedFilePath) { [[NSFileManager defaultManager] removeItemAtPath:draggedFilePath error:nil]; -- cgit v1.2.3 From c1561b572cb258a8ff1b8290c56cc22604d4aadd Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 10 Dec 2010 14:38:31 +0000 Subject: =?UTF-8?q?=E2=80=A2=20Bundle=20HTML=20output=20-=20fixed=20init?= =?UTF-8?q?=20and=20release=20issue=20-=20started=20to=20allow=20JavaScrip?= =?UTF-8?q?t=20(from=20inside=20the=20HTML=20output=20window=20via=20js-ob?= =?UTF-8?q?ject=20window.system)=20to=20communicate=20with=20SequelPro?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPBundleHTMLOutputController.m | 73 +++++++++++++++++++++++++++++------ 1 file changed, 62 insertions(+), 11 deletions(-) (limited to 'Source') diff --git a/Source/SPBundleHTMLOutputController.m b/Source/SPBundleHTMLOutputController.m index a630eb06..8ae91400 100644 --- a/Source/SPBundleHTMLOutputController.m +++ b/Source/SPBundleHTMLOutputController.m @@ -26,8 +26,6 @@ #import "SPBundleHTMLOutputController.h" #import "SPAlertSheets.h" - - @implementation SPBundleHTMLOutputController @synthesize docTitle; @@ -44,6 +42,13 @@ [[self window] setReleasedWhenClosed:YES]; + [webView setContinuousSpellCheckingEnabled:NO]; + [webView setGroupName:@"SequelProBundleHTMLOutput"]; + [webView setDrawsBackground:YES]; + [webView setEditable:NO]; + [webView setShouldCloseWithWindow:YES]; + [webView setShouldUpdateWhileOffscreen:NO]; + } return self; @@ -59,13 +64,6 @@ { [super windowControllerDidLoadNib:aController]; - [webView setContinuousSpellCheckingEnabled:NO]; - [webView setGroupName:@"SequelProBundleHTMLOutput"]; - [webView setDrawsBackground:YES]; - [webView setEditable:NO]; - [webView setShouldCloseWithWindow:YES]; - [webView setShouldUpdateWhileOffscreen:NO]; - } - (void)displayHTMLContent:(NSString *)content withOptions:(NSDictionary *)displayOptions @@ -114,9 +112,7 @@ - (void)dealloc { - if(webView) [webView release]; if(webPreferences) [webPreferences release]; - // [super dealloc]; } - (void)keyDown:(NSEvent *)theEvent @@ -222,6 +218,7 @@ [webView close]; [self setInitHTMLSourceString:@""]; windowUUID = @""; + [self release]; } #pragma mark - @@ -312,6 +309,60 @@ } } +#pragma mark - +#pragma mark JS support + +- (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame +{ + NSLog(@"alert %@", message); +} + +- (BOOL)webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame +{ + NSLog(@"confirm"); + return NO; +} + +- (NSString *)webView:(WebView *)sender runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)defaultText initiatedByFrame:(WebFrame *)frame +{ + return @"be patient"; +} + +- (void)webView:(WebView *)sender windowScriptObjectAvailable: (WebScriptObject *)windowScriptObject +{ + [windowScriptObject setValue:self forKey:@"system"]; +} + ++ (NSString *)webScriptNameForSelector:(SEL)aSelector +{ + if (aSelector == @selector(run:)) + return @"run"; + return @""; +} + ++ (BOOL)isSelectorExcludedFromWebScript:(SEL)selector { + if (selector == @selector(run:)) { + return NO; + } + return YES; +} + ++ (BOOL)isKeyExcludedFromWebScript:(const char *)property { + if (strcmp(property, "run") == 0) { + return NO; + } + return YES; +} + +- (void) windowScriptObjectAvailable:(WebScriptObject*)webScriptObject { + [webScriptObject setValue:self forKey:@"system"]; +} + +- (NSString *)run:(NSString*)command +{ + return [NSString stringWithFormat:@"Hallo-%@", [command description]]; +} + #pragma mark - #pragma mark multi-touch trackpad support -- cgit v1.2.3 From 9f7545289ce2d8eda170baa14d740540cf25188f Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 10 Dec 2010 14:43:44 +0000 Subject: =?UTF-8?q?=E2=80=A2=20Bundle=20HTML=20output=20-=20display=20a=20?= =?UTF-8?q?JavaScript=20alert=20as=20sheet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPBundleHTMLOutputController.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Source') diff --git a/Source/SPBundleHTMLOutputController.m b/Source/SPBundleHTMLOutputController.m index 8ae91400..e675e9f5 100644 --- a/Source/SPBundleHTMLOutputController.m +++ b/Source/SPBundleHTMLOutputController.m @@ -314,7 +314,8 @@ - (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame { - NSLog(@"alert %@", message); + SPBeginAlertSheet(NSLocalizedString(@"JavaScript Alert", @"javascript alert"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self window], self, nil, nil, + [message description]); } - (BOOL)webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame -- cgit v1.2.3 From 31a6e2c7d4f6503a00d24a75c820123c1cce7562 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 10 Dec 2010 19:21:09 +0000 Subject: =?UTF-8?q?=E2=80=A2=20Bundle=20command=20support=20-=20fix=20issu?= =?UTF-8?q?e=20for=20shortcut=20recorder=20for=20Asian=20language=20input?= =?UTF-8?q?=20-=20finished=20JavaScript=20support=20inside=20the=20HTML=20?= =?UTF-8?q?output=20window=20to=20run=20BASH=20system=20commands=20via=20"?= =?UTF-8?q?var=20returnValue=20=3D=20window.system.run(cmd)"=20whereby=20c?= =?UTF-8?q?md=20is=20either=20a=20normal=20string=20or=20an=20array=20of?= =?UTF-8?q?=20the=20dimension=20of=202=20(command,=20processID)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPBundleEditorController.m | 3 +- Source/SPBundleHTMLOutputController.m | 64 +++++++++++++++++++++++++++++++++-- Source/SPStringAdditions.m | 2 +- 3 files changed, 64 insertions(+), 5 deletions(-) (limited to 'Source') diff --git a/Source/SPBundleEditorController.m b/Source/SPBundleEditorController.m index 99da4bc4..272221d4 100644 --- a/Source/SPBundleEditorController.m +++ b/Source/SPBundleEditorController.m @@ -1086,7 +1086,8 @@ } if(newKeyCombo.flags & NSCommandKeyMask) [keyEq appendString:@"@"]; - [keyEq appendString:theChar]; + if(theChar) + [keyEq appendString:theChar]; } [[self _currentSelectedObject] setObject:keyEq forKey:SPBundleFileKeyEquivalentKey]; diff --git a/Source/SPBundleHTMLOutputController.m b/Source/SPBundleHTMLOutputController.m index e675e9f5..c57c79f4 100644 --- a/Source/SPBundleHTMLOutputController.m +++ b/Source/SPBundleHTMLOutputController.m @@ -22,7 +22,6 @@ // // More info at - #import "SPBundleHTMLOutputController.h" #import "SPAlertSheets.h" @@ -359,9 +358,68 @@ [webScriptObject setValue:self forKey:@"system"]; } -- (NSString *)run:(NSString*)command +- (NSString *)run:(id)call { - return [NSString stringWithFormat:@"Hallo-%@", [command description]]; + + NSError *err = nil; + NSString *command = nil; + NSString *uuid = nil; + + if([call isKindOfClass:[NSString class]]) + command = [NSString stringWithString:call]; + else if([[[call class] description] isEqualToString:@"WebScriptObject"]){ + command = [call webScriptValueAtIndex:0]; + uuid = [call webScriptValueAtIndex:1]; + } + else { + NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Error while executing JavaScript BASH command", @"error while executing javascript bash command") + defaultButton:NSLocalizedString(@"OK", @"OK button") + alternateButton:nil + otherButton:nil + informativeTextWithFormat:NSLocalizedString(@"Passed parameter couldn't be interpreted. Only string or array (with 2 elements) are allowed.", @"Passed parameter couldn't be interpreted. Only string or array (with 2 elements) are allowed.")]; + + [alert setAlertStyle:NSCriticalAlertStyle]; + [alert runModal]; + return @""; + } + + if(!command) return @"No JavaScript command found."; + + NSString *output = nil; + if(uuid == nil) + output = [command runBashCommandWithEnvironment:nil atCurrentDirectoryPath:nil error:&err]; + else + output = [command runBashCommandWithEnvironment:nil + atCurrentDirectoryPath:nil + callerInstance:[NSApp delegate] + contextInfo:[NSDictionary dictionaryWithObjectsAndKeys: + @"JavaScript", @"name", + NSLocalizedString(@"General", @"general menu item label"), @"scope", + uuid, SPBundleFileInternalexecutionUUID, + nil] + error:&err]; + + + if(err != nil) { + NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Error while executing JavaScript BASH command", @"error while executing javascript bash command") + defaultButton:NSLocalizedString(@"OK", @"OK button") + alternateButton:nil + otherButton:nil + informativeTextWithFormat:[err localizedDescription]]; + + [alert setAlertStyle:NSCriticalAlertStyle]; + [alert runModal]; + return @""; + } + + if(output) + return output; + else { + NSLog(@"No valid output for JavaScript command found."); + NSBeep(); + return @""; + } + } #pragma mark - diff --git a/Source/SPStringAdditions.m b/Source/SPStringAdditions.m index 4b06a028..a3098750 100644 --- a/Source/SPStringAdditions.m +++ b/Source/SPStringAdditions.m @@ -462,7 +462,7 @@ NSMutableArray *scriptHeaderArguments = [NSMutableArray array]; NSString *scriptPath = @""; - NSString *uuid = (contextInfo && [contextInfo objectForKey:SPBundleFileInternalexecutionUUID]) ? [contextInfo objectForKey:@"exeUUID"] : [NSString stringWithNewUUID]; + NSString *uuid = (contextInfo && [contextInfo objectForKey:SPBundleFileInternalexecutionUUID]) ? [contextInfo objectForKey:SPBundleFileInternalexecutionUUID] : [NSString stringWithNewUUID]; NSString *stdoutFilePath = [NSString stringWithFormat:@"%@_%@", SPBundleTaskOutputFilePath, uuid]; NSString *scriptFilePath = [NSString stringWithFormat:@"%@_%@", SPBundleTaskScriptCommandFilePath, uuid]; -- cgit v1.2.3 From 22028889fba4e487d132b4c42f8a22df5922a5c8 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 10 Dec 2010 19:33:53 +0000 Subject: =?UTF-8?q?=E2=80=A2=C2=A0avoided=20to=20execute=20SHOW=20VARIABLE?= =?UTF-8?q?S=20LIKE=20'character=5Fset=5Fdatabase'=20twice=20for=20setting?= =?UTF-8?q?=20shell=20variables=20for=20Bundle=20commands?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPDatabaseDocument.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'Source') diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index 216a3004..c51a87e3 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -4852,8 +4852,7 @@ if ([self port]) [env setObject:[self port] forKey:@"SP_CURRENT_PORT"]; - if ([self databaseEncoding]) - [env setObject:[self databaseEncoding] forKey:@"SP_DATABASE_ENCODING"]; + [env setObject:([self databaseEncoding])?:@"" forKey:@"SP_DATABASE_ENCODING"]; } -- cgit v1.2.3 From f4c56bb02798ebfbbaba7e7f182843b72f276264 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Sat, 11 Dec 2010 12:42:00 +0000 Subject: =?UTF-8?q?=E2=80=A2=20fix=20table=20name=20encoding=20problem=20(?= =?UTF-8?q?return=20name=20can=20be=20NSNull)=20which=20can=20arise=20whil?= =?UTF-8?q?e=20SPTablesList=20updateTables=20method,=20=E2=80=A2=20added?= =?UTF-8?q?=20[theView=20breakUndoCoalescing];=20before=20inserting=20the?= =?UTF-8?q?=20grey=20completion=20suggestion=20due=20to=20possible=20undo?= =?UTF-8?q?=20exceptions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPNarrowDownCompletion.m | 1 + Source/SPTablesList.m | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'Source') diff --git a/Source/SPNarrowDownCompletion.m b/Source/SPNarrowDownCompletion.m index 81f4e28b..f86c66c5 100644 --- a/Source/SPNarrowDownCompletion.m +++ b/Source/SPNarrowDownCompletion.m @@ -953,6 +953,7 @@ NSString* toInsert = [curMatch substringFromIndex:[originalFilterString length]]; theCharRange.length += [toInsert length] - currentAutocompleteLength; theParseRange.length += [toInsert length]; + [theView breakUndoCoalescing]; [theView insertText:[toInsert lowercaseString]]; autocompletePlaceholderWasInserted = YES; diff --git a/Source/SPTablesList.m b/Source/SPTablesList.m index bbc40164..54e0f400 100644 --- a/Source/SPTablesList.m +++ b/Source/SPTablesList.m @@ -106,7 +106,14 @@ } else { for ( i = 0 ; i < [theResult numOfRows] ; i++ ) { resultRow = [theResult fetchRowAsArray]; - NSString *tableName = [NSString stringWithUTF8String:[[resultRow objectAtIndex:0] cStringUsingEncoding:[mySQLConnection stringEncoding]]]; + // Due to encoding problems it can be the case that [resultRow objectAtIndex:0] + // return NSNull, thus catch that case for safety reasons + NSString *row = [resultRow objectAtIndex:0]; + NSString *tableName; + if([row isKindOfClass:[NSString class]]) + tableName = [NSString stringWithUTF8String:[row cStringUsingEncoding:[mySQLConnection stringEncoding]]]; + else + tableName = @"..."; [tables addObject:tableName]; if ([[resultRow objectAtIndex:1] isEqualToString:@"VIEW"]) { [tableTypes addObject:[NSNumber numberWithInteger:SPTableTypeView]]; -- cgit v1.2.3 From cb2baf9cb4ce1e33e6756969b1f71eb0e011f2c8 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Sat, 11 Dec 2010 13:09:07 +0000 Subject: =?UTF-8?q?=E2=80=A2=20the=20default=20behaviour=20is=20that=20'Sh?= =?UTF-8?q?ow=20HTML=20Window'=20will=20order=20front=20the=20window=20but?= =?UTF-8?q?=20the=20focus=20remains=20at=20the=20caller=20for=20convenienc?= =?UTF-8?q?e=20but=20under=20some=20circumstances=20it=20could=20be=20usef?= =?UTF-8?q?ul=20to=20make=20the=20HTML=20window=20the=20first=20responder;?= =?UTF-8?q?=20now=20this=20can=20be=20done=20via=20JavaScript=20like:=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPBundleHTMLOutputController.m | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'Source') diff --git a/Source/SPBundleHTMLOutputController.m b/Source/SPBundleHTMLOutputController.m index c57c79f4..365c15a3 100644 --- a/Source/SPBundleHTMLOutputController.m +++ b/Source/SPBundleHTMLOutputController.m @@ -59,22 +59,13 @@ return @"BundleHTMLOutput"; } -- (void)windowControllerDidLoadNib:(NSWindowController *) aController -{ - [super windowControllerDidLoadNib:aController]; - -} - - (void)displayHTMLContent:(NSString *)content withOptions:(NSDictionary *)displayOptions { [[self window] orderFront:nil]; - NSString *fullContent = @"%@"; - fullContent = [NSString stringWithFormat:fullContent, content]; - [self setInitHTMLSourceString:fullContent]; - [[webView mainFrame] loadHTMLString:@"" baseURL:nil]; - [[webView mainFrame] loadHTMLString:fullContent baseURL:nil]; + [self setInitHTMLSourceString:content]; + [[webView mainFrame] loadHTMLString:content baseURL:nil]; } @@ -385,6 +376,12 @@ 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]; -- cgit v1.2.3