From f5a548c05eb23afd80d3c7f105233542b0cfe8aa Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 11 Nov 2010 12:43:46 +0000 Subject: =?UTF-8?q?=E2=80=A2=20added=20to=20Bundle=20shell=20command=20the?= =?UTF-8?q?se=20variables:=20SP=5FALL=5FDATABASES,=20SP=5FALL=5FTABLES,=20?= =?UTF-8?q?SP=5FALL=5FVIEWS,=20SP=5FALL=5FFUNCTIONS,=20SP=5FALL=5FPROCEDUR?= =?UTF-8?q?ES,=20SP=5FRDBMS=5FVERSION,=20SP=5FRDBMS=5FTYPE=20[hard-coded?= =?UTF-8?q?=20yet=20;)]=20=E2=80=A2=20some=20minor=20improvements=20to=20e?= =?UTF-8?q?ditor=20Bundle=20support=20=E2=80=A2=20fixed=20issue=20while=20?= =?UTF-8?q?running=20a=20bash=20command=20that=20the=20SP=20GUI=20doesn't?= =?UTF-8?q?=20block=20=E2=80=A2=20added=20first=20sequelpro=20url=20scheme?= =?UTF-8?q?=20functionality=20-=20sequelpro://$SP=5FPROCESS=5FID/passToDoc?= =?UTF-8?q?/SelectTable/a=5Fname=20-=20sequelpro://$SP=5FPROCESS=5FID/pass?= =?UTF-8?q?ToDoc/SelectDatabase/a=5Fdb=5Fname=20-=20sequelpro://$SP=5FPROC?= =?UTF-8?q?ESS=5FID/passToDoc/SelectDatabase/a=5Fdb=5Fname/a=5Ftable=5Fnam?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPAppController.m | 9 ++++++ Source/SPArrayAdditions.h | 1 + Source/SPArrayAdditions.m | 15 ++++++++++ Source/SPDatabaseDocument.h | 3 ++ Source/SPDatabaseDocument.m | 43 ++++++++++++++++++++++++++++ Source/SPStringAdditions.m | 3 +- Source/SPTextView.m | 68 ++++++++++++++++++++++++++++++--------------- 7 files changed, 118 insertions(+), 24 deletions(-) (limited to 'Source') 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 @@ -4381,6 +4381,49 @@ [[self onMainThread] updateWindowTitle:self]; } +#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, -- cgit v1.2.3