aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2010-12-11 21:52:44 +0000
committerstuconnolly <stuart02@gmail.com>2010-12-11 21:52:44 +0000
commit1ddca4732c3aa46698b8fad25ce1294db3cd32fb (patch)
tree177ce5977ef37ea98ceae04bbce2f9ba73a0da4d /Source
parent66f0041a06b8710cd3ed3b5ff2c8cbb54004efba (diff)
parentcb2baf9cb4ce1e33e6756969b1f71eb0e011f2c8 (diff)
downloadsequelpro-1ddca4732c3aa46698b8fad25ce1294db3cd32fb.tar.gz
sequelpro-1ddca4732c3aa46698b8fad25ce1294db3cd32fb.tar.bz2
sequelpro-1ddca4732c3aa46698b8fad25ce1294db3cd32fb.zip
Bring outlineview branch up to date with trunk (r2989:3005).
Diffstat (limited to 'Source')
-rw-r--r--Source/SPAppController.m2
-rw-r--r--Source/SPBundleEditorController.m18
-rw-r--r--Source/SPBundleHTMLOutputController.h3
-rw-r--r--Source/SPBundleHTMLOutputController.m234
-rw-r--r--Source/SPConstants.h5
-rw-r--r--Source/SPConstants.m5
-rw-r--r--Source/SPCopyTable.m4
-rw-r--r--Source/SPCustomQuery.m55
-rw-r--r--Source/SPDatabaseDocument.m5
-rw-r--r--Source/SPFieldEditorController.h4
-rw-r--r--Source/SPFieldEditorController.m2
-rw-r--r--Source/SPNarrowDownCompletion.m1
-rw-r--r--Source/SPStringAdditions.m9
-rw-r--r--Source/SPTableContent.m6
-rw-r--r--Source/SPTablesList.m9
-rw-r--r--Source/SPTextViewAdditions.m32
16 files changed, 346 insertions, 48 deletions
diff --git a/Source/SPAppController.m b/Source/SPAppController.m
index f51cfc13..7278f5db 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 4091e606..272221d4 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];
@@ -327,12 +322,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",
@@ -1038,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];
@@ -1095,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.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..365c15a3 100644
--- a/Source/SPBundleHTMLOutputController.m
+++ b/Source/SPBundleHTMLOutputController.m
@@ -22,10 +22,8 @@
//
// More info at <http://code.google.com/p/sequel-pro/>
-
#import "SPBundleHTMLOutputController.h"
-
-
+#import "SPAlertSheets.h"
@implementation SPBundleHTMLOutputController
@@ -43,6 +41,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;
@@ -54,29 +59,13 @@
return @"BundleHTMLOutput";
}
-- (void)windowControllerDidLoadNib:(NSWindowController *) aController
-{
- [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
{
[[self window] orderFront:nil];
- NSString *fullContent = @"%@";
- fullContent = [NSString stringWithFormat:fullContent, content];
- [self setInitHTMLSourceString:fullContent];
- [[webView mainFrame] loadHTMLString:@"<html></html>" baseURL:nil];
- [[webView mainFrame] loadHTMLString:fullContent baseURL:nil];
+ [self setInitHTMLSourceString:content];
+ [[webView mainFrame] loadHTMLString:content baseURL:nil];
}
@@ -113,15 +102,12 @@
- (void)dealloc
{
- if(webView) [webView release];
if(webPreferences) [webPreferences release];
- // [super dealloc];
}
- (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 +143,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:@"<pre>%@</pre>", [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 +208,37 @@
[webView close];
[self setInitHTMLSourceString:@""];
windowUUID = @"";
- // [[notification object] release];
+ [self 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) {
@@ -236,6 +300,126 @@
}
#pragma mark -
+#pragma mark JS support
+
+- (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]);
+}
+
+- (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:(id)call
+{
+
+ 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.";
+
+ // 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];
+ 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 -
#pragma mark multi-touch trackpad support
/**
diff --git a/Source/SPConstants.h b/Source/SPConstants.h
index 09763e45..35238a07 100644
--- a/Source/SPConstants.h
+++ b/Source/SPConstants.h
@@ -498,6 +498,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 1ef054bb..ece44709 100644
--- a/Source/SPConstants.m
+++ b/Source/SPConstants.m
@@ -311,6 +311,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..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];
@@ -2386,6 +2393,54 @@
#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
*/
- (void)tableViewColumnDidResize:(NSNotification *)aNotification
diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m
index f1ac803f..a7b85c21 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"];
@@ -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"];
}
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/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/SPStringAdditions.m b/Source/SPStringAdditions.m
index 97339201..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];
@@ -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;
@@ -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/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/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]];
diff --git a/Source/SPTextViewAdditions.m b/Source/SPTextViewAdditions.m
index 6ca111b5..5dd7d06c 100644
--- a/Source/SPTextViewAdditions.m
+++ b/Source/SPTextViewAdditions.m
@@ -578,6 +578,38 @@
[env setObject:bundleInputFilePath forKey:SPBundleShellVariableInputFilePath];
[env setObject:SPBundleScopeInputField forKey:SPBundleShellVariableScope];
+ id tableSource = [self delegate];
+ 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];
+ 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"];