aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-11-10 13:47:24 +0000
committerBibiko <bibiko@eva.mpg.de>2010-11-10 13:47:24 +0000
commitbb99430f93b2e3c89c28cc44257635709f0fdd39 (patch)
tree74f2eb41f7942c1739641b01febf15f0d23dbfa7
parent169fb3fffeff55cff32952a82adba055dfc050f9 (diff)
downloadsequelpro-bb99430f93b2e3c89c28cc44257635709f0fdd39.tar.gz
sequelpro-bb99430f93b2e3c89c28cc44257635709f0fdd39.tar.bz2
sequelpro-bb99430f93b2e3c89c28cc44257635709f0fdd39.zip
• improved Bundle support; now it the passed input string will be saved as temp file SP_BUNDLE_INPUT_FILE since stdin and shell vars are difficult to handle for a large amount of data
• fixed AppleScript class definition since it was renamed • added support for the URL scheme 'sequel' to allow to interact with Sequel Pro eg via bash: open 'sequelpro://executequery=select%205' [not yet implemented ;)]
-rw-r--r--Resources/Plists/Info.plist12
-rw-r--r--Resources/Scripting/sequel-pro.scriptTerminology2
-rw-r--r--Source/SPAppController.m17
-rw-r--r--Source/SPTextView.m113
4 files changed, 90 insertions, 54 deletions
diff --git a/Resources/Plists/Info.plist b/Resources/Plists/Info.plist
index ecf74ffb..3f900c11 100644
--- a/Resources/Plists/Info.plist
+++ b/Resources/Plists/Info.plist
@@ -302,5 +302,15 @@
</dict>
</dict>
</array>
-</dict>
+ <key>CFBundleURLTypes</key>
+ <array>
+ <dict>
+ <key>CFBundleURLName</key>
+ <string>Sequel Pro URL scheme</string>
+ <key>CFBundleURLSchemes</key>
+ <array>
+ <string>sequelpro</string>
+ </array>
+ </dict>
+ </array></dict>
</plist>
diff --git a/Resources/Scripting/sequel-pro.scriptTerminology b/Resources/Scripting/sequel-pro.scriptTerminology
index cf65a7f3..b19c8ad0 100644
--- a/Resources/Scripting/sequel-pro.scriptTerminology
+++ b/Resources/Scripting/sequel-pro.scriptTerminology
@@ -8,7 +8,7 @@
"PluralName" = "applications";
"Description" = "Sequel Pro's top level scripting object.";
};
- "TableDocument" = {
+ "SPDatabaseDocument" = {
"Name" = "document";
"PluralName" = "documents";
"Description" = "A Sequel Pro document.";
diff --git a/Source/SPAppController.m b/Source/SPAppController.m
index b2876af4..4b5b997c 100644
--- a/Source/SPAppController.m
+++ b/Source/SPAppController.m
@@ -60,6 +60,7 @@
{
// Register application defaults
[[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"PreferenceDefaults" ofType:@"plist"]]];
+
}
/**
@@ -67,6 +68,10 @@
*/
- (void)awakeFromNib
{
+
+ // Register url scheme handle
+ [[NSAppleEventManager sharedAppleEventManager] setEventHandler:self andSelector:@selector(handleEvent:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL];
+
// Set up the prefs controller
prefsController = [[SPPreferenceController alloc] init];
@@ -499,6 +504,18 @@
}
#pragma mark -
+#pragma mark URL scheme handler
+
+/**
+ * “sequelpro://” url dispatcher
+ */
+- (void)handleEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
+{
+ NSURL *url = [NSURL URLWithString:[[event paramDescriptorForKeyword:keyDirectObject] stringValue]];
+ NSLog(@"url = %@", url);
+}
+
+#pragma mark -
#pragma mark Window management
/**
diff --git a/Source/SPTextView.m b/Source/SPTextView.m
index 9de1d0af..8a065c5c 100644
--- a/Source/SPTextView.m
+++ b/Source/SPTextView.m
@@ -3513,13 +3513,67 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
if([cmdData objectForKey:@"command"] && [[cmdData objectForKey:@"command"] length]) {
NSString *cmd = [cmdData objectForKey:@"command"];
+ NSString *inputAction = @"";
+ NSString *inputFallBackAction = @"";
NSError *err = nil;
+ NSString *inputTempFileName = @"/tmp/sp_bundle_task_input";
NSRange currentWordRange, currentQueryRange, currentSelectionRange, currentLineRange;
+ [[NSFileManager defaultManager] removeItemAtPath:inputTempFileName error:nil];
+
+ if([cmdData objectForKey:@"input"])
+ inputAction = [[cmdData objectForKey:@"input"] lowercaseString];
+ if([cmdData objectForKey:@"input_fallback"])
+ inputFallBackAction = [[cmdData objectForKey:@"input_fallback"] lowercaseString];
+
+ currentSelectionRange = [self selectedRange];
+ currentWordRange = [self getRangeForCurrentWord];
+ if(customQueryInstance && [customQueryInstance currentQueryRange].length) {
+ currentQueryRange = [customQueryInstance currentQueryRange];
+ } else {
+ currentQueryRange = currentSelectionRange;
+ }
+ currentLineRange = [[self string] lineRangeForRange:NSMakeRange([self selectedRange].location, 0)];
+
+ NSRange replaceRange = NSMakeRange(currentSelectionRange.location, 0);
+ if([inputAction isEqualToString:@"selectedtext"]) {
+ if(!currentSelectionRange.length) {
+ if([inputFallBackAction isEqualToString:@"currentword"])
+ replaceRange = currentWordRange;
+ else if([inputFallBackAction isEqualToString:@"currentline"])
+ replaceRange = currentLineRange;
+ else if([inputFallBackAction isEqualToString:@"currentquery"])
+ replaceRange = currentQueryRange;
+ else if([inputAction isEqualToString:@"entirecontent"])
+ replaceRange = NSMakeRange(0,[[self string] length]);
+ } else {
+ replaceRange = currentSelectionRange;
+ }
+
+ }
+ else if([inputAction isEqualToString:@"entirecontent"]) {
+ replaceRange = NSMakeRange(0,[[self string] length]);
+ }
+
+ NSError *inputFileError = nil;
+ NSString *input = [NSString stringWithString:[[self string] substringWithRange:replaceRange]];
+ [input writeToFile:inputTempFileName
+ atomically:YES
+ encoding:NSUTF8StringEncoding
+ error:&inputFileError];
+
+ if(inputFileError != nil) {
+ NSString *errorMessage = [inputFileError localizedDescription];
+ SPBeginAlertSheet(NSLocalizedString(@"Bundle Error", @"bundle error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self window], self, nil, nil,
+ [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]);
+ if (cmdData) [cmdData release];
+ return;
+ }
+
NSMutableDictionary *env = [NSMutableDictionary dictionary];
[env setObject:[infoPath stringByDeletingLastPathComponent] forKey:@"SP_BUNDLE_PATH"];
+ [env setObject:inputTempFileName forKey:@"SP_BUNDLE_INPUT_FILE"];
- currentSelectionRange = [self selectedRange];
if(currentSelectionRange.length)
[env setObject:[[self string] substringWithRange:currentSelectionRange] forKey:@"SP_SELECTED_TEXT"];
@@ -3529,19 +3583,12 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
if (tablesListInstance && [tablesListInstance tableName])
[env setObject:[tablesListInstance tableName] forKey:@"SP_SELECTED_TABLE"];
-
- if(customQueryInstance && [customQueryInstance currentQueryRange].length) {
- currentQueryRange = [customQueryInstance currentQueryRange];
+ if(customQueryInstance && [customQueryInstance currentQueryRange].length)
[env setObject:[[self string] substringWithRange:[customQueryInstance currentQueryRange]] forKey:@"SP_CURRENT_QUERY"];
- } else {
- currentQueryRange = currentSelectionRange;
- }
- currentWordRange = [self getRangeForCurrentWord];
if(currentWordRange.length)
[env setObject:[[self string] substringWithRange:currentWordRange] forKey:@"SP_CURRENT_WORD"];
- currentLineRange = [[self string] lineRangeForRange:NSMakeRange([self selectedRange].location, 0)];
if(currentLineRange.length)
[env setObject:[[self string] substringWithRange:currentLineRange] forKey:@"SP_CURRENT_LINE"];
@@ -3555,27 +3602,6 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
}
else if([action isEqualToString:@"insertassnippet"]) {
- NSString *inputAction = @"";
- NSString *inputFallBackAction = @"";
- if([cmdData objectForKey:@"input"])
- inputAction = [[cmdData objectForKey:@"input"] lowercaseString];
- if([cmdData objectForKey:@"input_fallback"])
- inputFallBackAction = [[cmdData objectForKey:@"input_fallback"] lowercaseString];
- NSRange replaceRange = NSMakeRange(currentSelectionRange.location, 0);
- if([inputAction isEqualToString:@"selectedtext"]) {
- if(!currentSelectionRange.length) {
- if([inputFallBackAction isEqualToString:@"currentword"])
- replaceRange = currentWordRange;
- else if([inputFallBackAction isEqualToString:@"currentline"])
- replaceRange = currentLineRange;
- else if([inputFallBackAction isEqualToString:@"currentquery"])
- replaceRange = currentQueryRange;
- else if([inputAction isEqualToString:@"entirecontent"])
- replaceRange = NSMakeRange(0,[[self string] length]);
- } else {
- replaceRange = currentSelectionRange;
- }
- }
[self insertAsSnippet:output atRange:replaceRange];
}
@@ -3586,27 +3612,6 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
}
else if([action isEqualToString:@"replaceselection"]) {
- NSString *inputAction = @"";
- NSString *inputFallBackAction = @"";
- if([cmdData objectForKey:@"input"])
- inputAction = [[cmdData objectForKey:@"input"] lowercaseString];
- if([cmdData objectForKey:@"input_fallback"])
- inputFallBackAction = [[cmdData objectForKey:@"input_fallback"] lowercaseString];
- NSRange replaceRange = NSMakeRange(currentSelectionRange.location, 0);
- if([inputAction isEqualToString:@"selectedtext"]) {
- if(!currentSelectionRange.length) {
- if([inputFallBackAction isEqualToString:@"currentword"])
- replaceRange = currentWordRange;
- else if([inputFallBackAction isEqualToString:@"currentline"])
- replaceRange = currentLineRange;
- else if([inputFallBackAction isEqualToString:@"currentquery"])
- replaceRange = currentQueryRange;
- else if([inputAction isEqualToString:@"entirecontent"])
- replaceRange = NSMakeRange(0,[[self string] length]);
- } else {
- replaceRange = currentSelectionRange;
- }
- }
[self shouldChangeTextInRange:replaceRange replacementString:output];
[self replaceCharactersInRange:replaceRange withString:output];
}
@@ -3624,9 +3629,13 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
SPBeginAlertSheet(NSLocalizedString(@"BASH Error", @"bash error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self window], self, nil, nil,
[NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]);
}
+
+ [[NSFileManager defaultManager] removeItemAtPath:inputTempFileName error:nil];
+
}
-
+
if (cmdData) [cmdData release];
+
}
}