aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-11-16 13:54:31 +0000
committerBibiko <bibiko@eva.mpg.de>2010-11-16 13:54:31 +0000
commit422c1a7b2ad474e8bef20e787bca44b954d1e2ef (patch)
treedd844fcbd6875dcfacd646fd0bb4904f94aee93b
parent46ba2532fb0c540889178b4fc922de61597c27de (diff)
downloadsequelpro-422c1a7b2ad474e8bef20e787bca44b954d1e2ef.tar.gz
sequelpro-422c1a7b2ad474e8bef20e787bca44b954d1e2ef.tar.bz2
sequelpro-422c1a7b2ad474e8bef20e787bca44b954d1e2ef.zip
• Bundle support
- further minor improvements - make usage of more constants
-rw-r--r--Source/SPConstants.h7
-rw-r--r--Source/SPConstants.m70
-rw-r--r--Source/SPStringAdditions.m21
3 files changed, 61 insertions, 37 deletions
diff --git a/Source/SPConstants.h b/Source/SPConstants.h
index 64003bad..da17cf78 100644
--- a/Source/SPConstants.h
+++ b/Source/SPConstants.h
@@ -433,6 +433,12 @@ extern NSString *SPBundleInputSourceEntireContent;
extern NSString *SPBundleInputSourceCurrentWord;
extern NSString *SPBundleInputSourceCurrentQuery;
extern NSString *SPBundleInputSourceCurrentLine;
+extern NSString *SPBundleInputSourceSelectedTableRowsAsTab;
+extern NSString *SPBundleInputSourceSelectedTableRowsAsCsv;
+extern NSString *SPBundleInputSourceSelectedTableRowsAsSqlInsert;
+extern NSString *SPBundleInputSourceTableRowsAsTab;
+extern NSString *SPBundleInputSourceTableRowsAsCsv;
+extern NSString *SPBundleInputSourceTableRowsAsSqlInsert;
extern NSString *SPBundleInputSourceNone;
extern NSString *SPBundleOutputActionNone;
extern NSString *SPBundleOutputActionInsertAsText;
@@ -455,6 +461,7 @@ extern NSString *SPBundleInternPathToFileKey;
extern NSString *SPBundleInternKeyEquivalentKey;
extern NSString *SPBundleFileName;
extern NSString *SPBundleTaskInputFilePath;
+extern NSString *SPBundleTaskScriptCommandFilePath;
// sequel URL scheme
extern NSString *SPURLSchemeQueryInputPathHeader;
diff --git a/Source/SPConstants.m b/Source/SPConstants.m
index f0277c72..892941cf 100644
--- a/Source/SPConstants.m
+++ b/Source/SPConstants.m
@@ -243,37 +243,45 @@ NSString *SPFavoriteSSLCACertFileLocationEnabledKey = @"sslCACertFileLocati
NSString *SPFavoriteSSLCACertFileLocationKey = @"sslCACertFileLocation";
// Bundle Files and Bundle Editor
-NSString *SPBundleScopeQueryEditor = @"editor";
-NSString *SPBundleScopeDataTable = @"datatable";
-NSString *SPBundleScopeInputField = @"inputfield";
-NSString *SPBundleScopeGeneral = @"general";
-NSString *SPBundleInputSourceSelectedText = @"selectedtext";
-NSString *SPBundleInputSourceEntireContent = @"entirecontent";
-NSString *SPBundleInputSourceCurrentWord = @"currentword";
-NSString *SPBundleInputSourceCurrentQuery = @"currentquery";
-NSString *SPBundleInputSourceCurrentLine = @"currentline";
-NSString *SPBundleInputSourceNone = @"none";
-NSString *SPBundleOutputActionNone = @"none";
-NSString *SPBundleOutputActionInsertAsText = @"insertastext";
-NSString *SPBundleOutputActionInsertAsSnippet = @"insertassnippet";
-NSString *SPBundleOutputActionReplaceSelection = @"replaceselection";
-NSString *SPBundleOutputActionReplaceContent = @"replacecontent";
-NSString *SPBundleOutputActionShowAsTextTooltip = @"showastexttooltip";
-NSString *SPBundleOutputActionShowAsHTMLTooltip = @"showashtmltooltip";
-NSString *SPBundleFileCommandKey = @"command";
-NSString *SPBundleFileScopeKey = @"scope";
-NSString *SPBundleFileNameKey = @"name";
-NSString *SPBundleFileCategoryKey = @"category";
-NSString *SPBundleFileInputSourceKey = @"input";
-NSString *SPBundleFileInputSourceFallBackKey = @"input_fallback";
-NSString *SPBundleFileOutputActionKey = @"output";
-NSString *SPBundleFileKeyEquivalentKey = @"keyEquivalent";
-NSString *SPBundleFileTooltipKey = @"tooltip";
-NSString *SPBundleInternLabelKey = @"label";
-NSString *SPBundleInternPathToFileKey = @"path";
-NSString *SPBundleInternKeyEquivalentKey = @"keyEquivalent";
-NSString *SPBundleFileName = @"info.plist";
-NSString *SPBundleTaskInputFilePath = @"/tmp/SP_BUNDLE_TASK_INPUT";
+NSString *SPBundleScopeQueryEditor = @"editor";
+NSString *SPBundleScopeDataTable = @"datatable";
+NSString *SPBundleScopeInputField = @"inputfield";
+NSString *SPBundleScopeGeneral = @"general";
+NSString *SPBundleInputSourceSelectedText = @"selectedtext";
+NSString *SPBundleInputSourceEntireContent = @"entirecontent";
+NSString *SPBundleInputSourceCurrentWord = @"currentword";
+NSString *SPBundleInputSourceCurrentQuery = @"currentquery";
+NSString *SPBundleInputSourceCurrentLine = @"currentline";
+NSString *SPBundleInputSourceSelectedTableRowsAsTab = @"selectedtablerowsastab";
+NSString *SPBundleInputSourceSelectedTableRowsAsCsv = @"selectedtablerowsascsv";
+NSString *SPBundleInputSourceSelectedTableRowsAsSqlInsert = @"selectedtablerowsassqlinsert";
+NSString *SPBundleInputSourceTableRowsAsTab = @"tablerowsastab";
+NSString *SPBundleInputSourceTableRowsAsCsv = @"tablerowsascsv";
+NSString *SPBundleInputSourceTableRowsAsSqlInsert = @"tablerowsassqlinsert";
+NSString *SPBundleInputSourceNone = @"none";
+NSString *SPBundleOutputActionNone = @"none";
+NSString *SPBundleOutputActionInsertAsText = @"insertastext";
+NSString *SPBundleOutputActionInsertAsSnippet = @"insertassnippet";
+NSString *SPBundleOutputActionReplaceSelection = @"replaceselection";
+NSString *SPBundleOutputActionReplaceContent = @"replacecontent";
+NSString *SPBundleOutputActionShowAsTextTooltip = @"showastexttooltip";
+NSString *SPBundleOutputActionShowAsHTMLTooltip = @"showashtmltooltip";
+NSString *SPBundleFileCommandKey = @"command";
+NSString *SPBundleFileScopeKey = @"scope";
+NSString *SPBundleFileNameKey = @"name";
+NSString *SPBundleFileCategoryKey = @"category";
+NSString *SPBundleFileInputSourceKey = @"input";
+NSString *SPBundleFileInputSourceFallBackKey = @"input_fallback";
+NSString *SPBundleFileOutputActionKey = @"output";
+NSString *SPBundleFileKeyEquivalentKey = @"keyEquivalent";
+NSString *SPBundleFileTooltipKey = @"tooltip";
+NSString *SPBundleInternLabelKey = @"label";
+NSString *SPBundleInternPathToFileKey = @"path";
+NSString *SPBundleInternKeyEquivalentKey = @"keyEquivalent";
+
+NSString *SPBundleFileName = @"command.plist";
+NSString *SPBundleTaskInputFilePath = @"/tmp/SP_BUNDLE_TASK_INPUT";
+NSString *SPBundleTaskScriptCommandFilePath = @"/tmp/SP_SCRIPT_COMMAND";
// sequel URL scheme
NSString *SPURLSchemeQueryInputPathHeader = @"/tmp/SP_QUERY_";
diff --git a/Source/SPStringAdditions.m b/Source/SPStringAdditions.m
index 7f93659e..3198f2ff 100644
--- a/Source/SPStringAdditions.m
+++ b/Source/SPStringAdditions.m
@@ -417,12 +417,15 @@
BOOL userTerminated = NO;
BOOL redirectForScript = NO;
+ BOOL isDir = NO;
+
NSMutableArray *scriptHeaderArguments = [NSMutableArray array];
NSString *scriptPath = @"";
- NSString *scriptContentPath = @"/tmp/SP_SCRIPT_COMMAND";
- [[NSFileManager defaultManager] removeItemAtPath:scriptContentPath error:nil];
+ [[NSFileManager defaultManager] removeItemAtPath:SPBundleTaskScriptCommandFilePath error:nil];
+ // Parse first line for magic header #! ; if found save the script content and run the command after #! with that file.
+ // This allows to write perl, ruby, osascript scripts natively.
if([self length] > 3 && [self hasPrefix:@"#!"] && [shellEnvironment objectForKey:@"SP_BUNDLE_PATH"]) {
NSRange firstLineRange = NSMakeRange(2, [self rangeOfString:@"\n"].location - 2);
@@ -437,14 +440,13 @@
[scriptHeaderArguments removeObject:scriptPath];
}
- BOOL isDir = NO;
if([scriptPath hasPrefix:@"/"] && [[NSFileManager defaultManager] fileExistsAtPath:scriptPath isDirectory:&isDir] && !isDir) {
NSString *script = [self substringWithRange:NSMakeRange(NSMaxRange(firstLineRange), [self length] - NSMaxRange(firstLineRange))];
NSError *writeError = nil;
- [script writeToFile:scriptContentPath atomically:YES encoding:NSUTF8StringEncoding error:writeError];
+ [script writeToFile:SPBundleTaskScriptCommandFilePath atomically:YES encoding:NSUTF8StringEncoding error:writeError];
if(writeError == nil) {
redirectForScript = YES;
- [scriptHeaderArguments insertObject:scriptContentPath atIndex:0];
+ [scriptHeaderArguments insertObject:SPBundleTaskScriptCommandFilePath atIndex:0];
} else {
NSBeep();
NSLog(@"Couldn't write script file.");
@@ -475,6 +477,11 @@
}
[doc setProcessID:processID];
+ [theEnv setObject:[NSString stringWithFormat:@"%@%@", SPURLSchemeQueryInputPathHeader, processID] forKey:@"SP_QUERY_FILE_PATH"];
+ [theEnv setObject:[NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultPathHeader, processID] forKey:@"SP_QUERY_RESULT_FILE_PATH"];
+ [theEnv setObject:[NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultStatusPathHeader, processID] forKey:@"SP_QUERY_RESULT_STATUS_FILE_PATH"];
+ [theEnv setObject:[NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultMetaPathHeader, processID] forKey:@"SP_QUERY_RESULT_META_FILE_PATH"];
+
if([doc shellVariables])
[theEnv addEntriesFromDictionary:[doc shellVariables]];
@@ -483,6 +490,8 @@
if(path != nil)
[bashTask setCurrentDirectoryPath:path];
+ else if([shellEnvironment objectForKey:@"SP_BUNDLE_PATH"] && [[NSFileManager defaultManager] fileExistsAtPath:[shellEnvironment objectForKey:@"SP_BUNDLE_PATH"] isDirectory:&isDir] && isDir)
+ [bashTask setCurrentDirectoryPath:[shellEnvironment objectForKey:@"SP_BUNDLE_PATH"]];
if(redirectForScript)
[bashTask setArguments:scriptHeaderArguments];
@@ -530,7 +539,7 @@
}
if(redirectForScript)
- [[NSFileManager defaultManager] removeItemAtPath:scriptContentPath error:nil];
+ [[NSFileManager defaultManager] removeItemAtPath:SPBundleTaskScriptCommandFilePath error:nil];
// If return from bash re-activate Sequel Pro
[NSApp activateIgnoringOtherApps:YES];