aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-11-11 12:43:46 +0000
committerBibiko <bibiko@eva.mpg.de>2010-11-11 12:43:46 +0000
commitf5a548c05eb23afd80d3c7f105233542b0cfe8aa (patch)
treea822cf20087f43a9942769c1ded82735a592ceed
parentf633a067d2120cca67fd1b2782688424cadde9d4 (diff)
downloadsequelpro-f5a548c05eb23afd80d3c7f105233542b0cfe8aa.tar.gz
sequelpro-f5a548c05eb23afd80d3c7f105233542b0cfe8aa.tar.bz2
sequelpro-f5a548c05eb23afd80d3c7f105233542b0cfe8aa.zip
• added to Bundle shell command these variables:
SP_ALL_DATABASES, SP_ALL_TABLES, SP_ALL_VIEWS, SP_ALL_FUNCTIONS, SP_ALL_PROCEDURES, SP_RDBMS_VERSION, SP_RDBMS_TYPE [hard-coded yet ;)] • some minor improvements to editor Bundle support • fixed issue while running a bash command that the SP GUI doesn't block • added first sequelpro url scheme functionality - sequelpro://$SP_PROCESS_ID/passToDoc/SelectTable/a_name - sequelpro://$SP_PROCESS_ID/passToDoc/SelectDatabase/a_db_name - sequelpro://$SP_PROCESS_ID/passToDoc/SelectDatabase/a_db_name/a_table_name
-rw-r--r--Source/SPAppController.m9
-rw-r--r--Source/SPArrayAdditions.h1
-rw-r--r--Source/SPArrayAdditions.m15
-rw-r--r--Source/SPDatabaseDocument.h3
-rw-r--r--Source/SPDatabaseDocument.m43
-rw-r--r--Source/SPStringAdditions.m3
-rw-r--r--Source/SPTextView.m68
7 files changed, 118 insertions, 24 deletions
diff --git a/Source/SPAppController.m b/Source/SPAppController.m
index adb4eb95..c6c5c44a 100644
--- a/Source/SPAppController.m
+++ b/Source/SPAppController.m
@@ -551,6 +551,15 @@
}
}
+
+ if(processDocument && command && [command isEqualToString:@"passToDoc"]) {
+ NSMutableDictionary *cmdDict = [NSMutableDictionary dictionary];
+ [cmdDict setObject:parameter forKey:@"parameter"];
+ [cmdDict setObject:passedProcessID forKey:@"id"];
+ [processDocument handleSchemeCommand:cmdDict];
+ return;
+ }
+
if(processDocument)
NSLog(@"process doc ID: %@\n%@", [processDocument processID], [processDocument tabTitleForTooltip]);
else
diff --git a/Source/SPArrayAdditions.h b/Source/SPArrayAdditions.h
index 85ff061c..89ea53e4 100644
--- a/Source/SPArrayAdditions.h
+++ b/Source/SPArrayAdditions.h
@@ -41,6 +41,7 @@ static inline void NSMutableArrayReplaceObject(NSArray *self, CFIndex idx, id an
- (NSString *)componentsJoinedAndBacktickQuoted;
- (NSString *)componentsJoinedByCommas;
+- (NSString *)componentsJoinedBySpacesAndQuoted;
- (NSString *)componentsJoinedByPeriodAndBacktickQuoted;
- (NSString *)componentsJoinedByPeriodAndBacktickQuotedAndIgnoreFirst;
- (NSArray *)subarrayWithIndexes:(NSIndexSet *)indexes;
diff --git a/Source/SPArrayAdditions.m b/Source/SPArrayAdditions.m
index 7cc5bb4e..9f9e7705 100644
--- a/Source/SPArrayAdditions.m
+++ b/Source/SPArrayAdditions.m
@@ -60,6 +60,21 @@
return result;
}
+- (NSString *)componentsJoinedBySpacesAndQuoted
+{
+ NSMutableString *result = [NSMutableString string];
+ [result setString:@""];
+
+ for (NSString *component in self)
+ {
+ if ([result length])
+ [result appendString:@" "];
+
+ [result appendString:[NSString stringWithFormat:@"\"%@\"", [component stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""]]];
+ }
+ return result;
+}
+
- (NSString *)componentsJoinedByPeriodAndBacktickQuoted
{
NSMutableString *result = [NSMutableString string];
diff --git a/Source/SPDatabaseDocument.h b/Source/SPDatabaseDocument.h
index 0934f1ff..aeeaa302 100644
--- a/Source/SPDatabaseDocument.h
+++ b/Source/SPDatabaseDocument.h
@@ -353,4 +353,7 @@
- (void)setParentWindow:(NSWindow *)aWindow;
- (NSWindow *)parentWindow;
+// Scripting
+- (void)handleSchemeCommand:(NSDictionary*)commandDict;
+
@end
diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m
index c8f7bc7d..c5f574d9 100644
--- a/Source/SPDatabaseDocument.m
+++ b/Source/SPDatabaseDocument.m
@@ -4382,6 +4382,49 @@
}
#pragma mark -
+#pragma mark Scheme scripting methods
+
+- (void)handleSchemeCommand:(NSDictionary*)commandDict
+{
+
+ NSArray *params = [commandDict objectForKey:@"parameter"];
+ if(![params count]) return;
+
+ NSString *command = [params objectAtIndex:0];
+ NSString *docProcessID = [self processID];
+ if(!docProcessID) docProcessID = @"";
+
+ // Authenticate command
+ if(![docProcessID isEqualToString:[commandDict objectForKey:@"id"]]) return;
+
+ if([command isEqualToString:@"SelectTable"]) {
+ if([params count] == 2) {
+ NSString *tableName = [params objectAtIndex:1];
+ if([tableName length]) {
+ [tablesListInstance selectItemWithName:tableName];
+ return;
+ }
+ }
+ }
+ else if([command isEqualToString:@"SelectDatabase"]) {
+ if (_isWorkingLevel) return;
+ if([params count] > 1) {
+ NSString *dbName = [params objectAtIndex:1];
+ NSString *tableName = nil;
+ if([dbName length]) {
+ if([params count] == 3) {
+ tableName = [params objectAtIndex:2];
+ }
+ [self selectDatabase:dbName item:tableName];
+ return;
+ }
+ }
+ }
+
+ NSLog(@"received: %@", commandDict);
+}
+
+#pragma mark -
#pragma mark Text field delegate methods
/**
diff --git a/Source/SPStringAdditions.m b/Source/SPStringAdditions.m
index c57ccacb..7909bd70 100644
--- a/Source/SPStringAdditions.m
+++ b/Source/SPStringAdditions.m
@@ -452,7 +452,7 @@
untilDate:[NSDate distantPast]
inMode:NSDefaultRunLoopMode
dequeue:YES];
- usleep(10000);
+ usleep(1000);
if(!event) continue;
if ([event type] == NSKeyDown) {
unichar key = [[event characters] length] == 1 ? [[event characters] characterAtIndex:0] : 0;
@@ -461,6 +461,7 @@
userTerminated = YES;
break;
}
+ [NSApp sendEvent:event];
} else {
[NSApp sendEvent:event];
}
diff --git a/Source/SPTextView.m b/Source/SPTextView.m
index 8a065c5c..34c87822 100644
--- a/Source/SPTextView.m
+++ b/Source/SPTextView.m
@@ -3580,6 +3580,27 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
if (tablesListInstance && [tablesListInstance selectedDatabase])
[env setObject:[tablesListInstance selectedDatabase] forKey:@"SP_SELECTED_DATABASE"];
+ if (tablesListInstance && [tablesListInstance allDatabaseNames])
+ [env setObject:[[tablesListInstance allDatabaseNames] componentsJoinedBySpacesAndQuoted] forKey:@"SP_ALL_DATABASES"];
+
+ if (tablesListInstance && [tablesListInstance allTableNames])
+ [env setObject:[[tablesListInstance allTableNames] componentsJoinedBySpacesAndQuoted] forKey:@"SP_ALL_TABLES"];
+
+ if (tablesListInstance && [tablesListInstance allViewNames])
+ [env setObject:[[tablesListInstance allViewNames] componentsJoinedBySpacesAndQuoted] forKey:@"SP_ALL_VIEWS"];
+
+ if (tablesListInstance && [tablesListInstance allFunctionNames])
+ [env setObject:[[tablesListInstance allFunctionNames] componentsJoinedBySpacesAndQuoted] forKey:@"SP_ALL_FUNCTIONS"];
+
+ if (tablesListInstance && [tablesListInstance allProcedureNames])
+ [env setObject:[[tablesListInstance allProcedureNames] componentsJoinedBySpacesAndQuoted] forKey:@"SP_ALL_PROCEDURES"];
+
+ if(tableDocumentInstance && [tableDocumentInstance mySQLVersion])
+ [env setObject:[tableDocumentInstance mySQLVersion] forKey:@"SP_RDBMS_VERSION"];
+
+ if(1)
+ [env setObject:@"mysql" forKey:@"SP_RDBMS_TYPE"];
+
if (tablesListInstance && [tablesListInstance tableName])
[env setObject:[tablesListInstance tableName] forKey:@"SP_SELECTED_TABLE"];
@@ -3594,36 +3615,37 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
NSString *output = [cmd runBashCommandWithEnvironment:env atCurrentDirectoryPath:nil error:&err];
- if(err == nil && [cmdData objectForKey:@"output"] && [[cmdData objectForKey:@"output"] length] && ![[cmdData objectForKey:@"output"] isEqualToString:@"nop"]) {
- NSString *action = [[cmdData objectForKey:@"output"] lowercaseString];
+ if(err == nil && [cmdData objectForKey:@"output"]) {
+ if([[cmdData objectForKey:@"output"] length] && ![[cmdData objectForKey:@"output"] isEqualToString:@"nop"]) {
+ NSString *action = [[cmdData objectForKey:@"output"] lowercaseString];
- if([action isEqualToString:@"insertastext"]) {
- [self insertText:output];
- }
+ if([action isEqualToString:@"insertastext"]) {
+ [self insertText:output];
+ }
- else if([action isEqualToString:@"insertassnippet"]) {
- [self insertAsSnippet:output atRange:replaceRange];
- }
+ else if([action isEqualToString:@"insertassnippet"]) {
+ [self insertAsSnippet:output atRange:replaceRange];
+ }
- else if([action isEqualToString:@"replacecontent"]) {
- if([[self string] length])
- [self setSelectedRange:NSMakeRange(0,[[self string] length])];
- [self insertText:output];
- }
+ else if([action isEqualToString:@"replacecontent"]) {
+ if([[self string] length])
+ [self setSelectedRange:NSMakeRange(0,[[self string] length])];
+ [self insertText:output];
+ }
- else if([action isEqualToString:@"replaceselection"]) {
- [self shouldChangeTextInRange:replaceRange replacementString:output];
- [self replaceCharactersInRange:replaceRange withString:output];
- }
+ else if([action isEqualToString:@"replaceselection"]) {
+ [self shouldChangeTextInRange:replaceRange replacementString:output];
+ [self replaceCharactersInRange:replaceRange withString:output];
+ }
- else if([action isEqualToString:@"showastexttooltip"]) {
- [SPTooltip showWithObject:output];
- }
+ else if([action isEqualToString:@"showastexttooltip"]) {
+ [SPTooltip showWithObject:output];
+ }
- else if([action isEqualToString:@"showashtmltooltip"]) {
- [SPTooltip showWithObject:output ofType:@"html"];
+ else if([action isEqualToString:@"showashtmltooltip"]) {
+ [SPTooltip showWithObject:output ofType:@"html"];
+ }
}
-
} else {
NSString *errorMessage = [err localizedDescription];
SPBeginAlertSheet(NSLocalizedString(@"BASH Error", @"bash error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self window], self, nil, nil,