From d5168baf1cec01f5d45f27c47a1b9746d8838afc Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 17 Dec 2010 10:50:35 +0000 Subject: =?UTF-8?q?=E2=80=A2=20allow=20to=20some=20sequelpro=20URL=20schem?= =?UTF-8?q?e=20commands=20like=20select=20a=20table/db=20the=20usage=20wit?= =?UTF-8?q?hout=20a=20specific=20SP=5FPROCESS=5FID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPAppController.m | 6 ++- Source/SPDatabaseDocument.m | 92 ++++++++++++++++++++++++--------------------- 2 files changed, 55 insertions(+), 43 deletions(-) diff --git a/Source/SPAppController.m b/Source/SPAppController.m index 175df14c..a90876fa 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -659,6 +659,10 @@ } } + if(!processDocument) + processDocument = [[[self frontDocumentWindow] delegate] selectedTableDocument]; + + BOOL userTerminated = NO; // while(1) { @@ -688,7 +692,7 @@ if([command isEqualToString:@"passToDoc"]) { NSMutableDictionary *cmdDict = [NSMutableDictionary dictionary]; [cmdDict setObject:parameter forKey:@"parameter"]; - [cmdDict setObject:passedProcessID forKey:@"id"]; + [cmdDict setObject:(passedProcessID)?:@"" forKey:@"id"]; [processDocument handleSchemeCommand:cmdDict]; return; } diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index d6bdd768..a66d0f42 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -4646,12 +4646,7 @@ YY_BUFFER_STATE yy_scan_string (const char *); // Bail if document is busy if (_isWorkingLevel) { [SPTooltip showWithObject:NSLocalizedString(@"Connection window is busy. URL scheme command bailed", @"Connection window is busy. URL scheme command bailed") atLocation:[NSApp mouseLocation]]; - return; - } - - // Authenticate command - if(![docProcessID isEqualToString:[commandDict objectForKey:@"id"]]) { - [SPTooltip showWithObject:NSLocalizedString(@"URL scheme command couldn't authenticated", @"URL scheme command couldn't authenticated") atLocation:[NSApp mouseLocation]]; + NSBeep(); return; } @@ -4695,23 +4690,6 @@ YY_BUFFER_STATE yy_scan_string (const char *); return; } - if([command isEqualToString:@"SelectTableRows"]) { - if([params count] > 1 && [[[NSApp mainWindow] firstResponder] respondsToSelector:@selector(selectTableRows:)]) { - [[[NSApp mainWindow] firstResponder] selectTableRows:[params subarrayWithRange:NSMakeRange(1, [params count]-1)]]; - } - return; - } - - if([command isEqualToString:@"ReloadContentTable"]) { - [tableContentInstance reloadTable:self]; - return; - } - - if([command isEqualToString:@"ReloadTablesList"]) { - [tablesListInstance updateTables:self]; - return; - } - if([command isEqualToString:@"SelectDatabase"]) { if([params count] > 1) { NSString *dbName = [params objectAtIndex:1]; @@ -4726,21 +4704,6 @@ YY_BUFFER_STATE yy_scan_string (const char *); return; } - if([command isEqualToString:@"ReloadContentTableWithWHEREClause"]) { - NSString *queryFileName = [NSString stringWithFormat:@"%@%@", SPURLSchemeQueryInputPathHeader, docProcessID]; - NSFileManager *fm = [NSFileManager defaultManager]; - BOOL isDir; - if([fm fileExistsAtPath:queryFileName isDirectory:&isDir] && !isDir) { - NSError *inError = nil; - NSString *query = [NSString stringWithContentsOfFile:queryFileName encoding:NSUTF8StringEncoding error:inError]; - [fm removeItemAtPath:queryFileName error:nil]; - if(inError == nil && query && [query length]) { - [tableContentInstance filterTable:query]; - } - } - return; - } - if([command isEqualToString:@"SyntaxHighlighting"]) { NSFileManager *fm = [NSFileManager defaultManager]; @@ -4780,12 +4743,54 @@ YY_BUFFER_STATE yy_scan_string (const char *); BOOL succeed = [status writeToFile:statusFileName atomically:YES encoding:NSUTF8StringEncoding error:nil]; if(!succeed) { NSBeep(); - SPBeginAlertSheet(NSLocalizedString(@"BASH Error", @"bash error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self window], self, nil, nil, + SPBeginAlertSheet(NSLocalizedString(@"BASH Error", @"bash error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self parentWindow], self, nil, nil, NSLocalizedString(@"Status file for sequelpro url scheme command couldn't be written!", @"status file for sequelpro url scheme command couldn't be written error message")); } return; } + // ==== the following commands need an authentication for safety reasons + + // Authenticate command + if(![docProcessID isEqualToString:[commandDict objectForKey:@"id"]]) { + SPBeginAlertSheet(NSLocalizedString(@"Remote Error", @"remote error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self parentWindow], self, nil, nil, + NSLocalizedString(@"URL scheme command couldn't authenticated", @"URL scheme command couldn't authenticated")); + return; + } + + if([command isEqualToString:@"SelectTableRows"]) { + if([params count] > 1 && [[[NSApp mainWindow] firstResponder] respondsToSelector:@selector(selectTableRows:)]) { + [[[NSApp mainWindow] firstResponder] selectTableRows:[params subarrayWithRange:NSMakeRange(1, [params count]-1)]]; + } + return; + } + + if([command isEqualToString:@"ReloadContentTable"]) { + [tableContentInstance reloadTable:self]; + return; + } + + if([command isEqualToString:@"ReloadTablesList"]) { + [tablesListInstance updateTables:self]; + return; + } + + if([command isEqualToString:@"ReloadContentTableWithWHEREClause"]) { + NSString *queryFileName = [NSString stringWithFormat:@"%@%@", SPURLSchemeQueryInputPathHeader, docProcessID]; + NSFileManager *fm = [NSFileManager defaultManager]; + BOOL isDir; + if([fm fileExistsAtPath:queryFileName isDirectory:&isDir] && !isDir) { + NSError *inError = nil; + NSString *query = [NSString stringWithContentsOfFile:queryFileName encoding:NSUTF8StringEncoding error:inError]; + [fm removeItemAtPath:queryFileName error:nil]; + if(inError == nil && query && [query length]) { + [tableContentInstance filterTable:query]; + } + } + return; + } + + if([command isEqualToString:@"CreateSyntaxForTables"]) { if([params count] > 1) { @@ -4918,7 +4923,7 @@ YY_BUFFER_STATE yy_scan_string (const char *); BOOL succeed = [status writeToFile:statusFileName atomically:YES encoding:NSUTF8StringEncoding error:nil]; if(!succeed) { NSBeep(); - SPBeginAlertSheet(NSLocalizedString(@"BASH Error", @"bash error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self window], self, nil, nil, + SPBeginAlertSheet(NSLocalizedString(@"BASH Error", @"bash error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self parentWindow], self, nil, nil, NSLocalizedString(@"Status file for sequelpro url scheme command couldn't be written!", @"status file for sequelpro url scheme command couldn't be written error message")); } @@ -5091,13 +5096,16 @@ YY_BUFFER_STATE yy_scan_string (const char *); BOOL succeed = [status writeToFile:statusFileName atomically:YES encoding:NSUTF8StringEncoding error:nil]; if(!succeed) { NSBeep(); - SPBeginAlertSheet(NSLocalizedString(@"BASH Error", @"bash error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self window], self, nil, nil, + SPBeginAlertSheet(NSLocalizedString(@"BASH Error", @"bash error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self parentWindow], self, nil, nil, NSLocalizedString(@"Status file for sequelpro url scheme command couldn't be written!", @"status file for sequelpro url scheme command couldn't be written error message")); } return; } - NSLog(@"received: %@", commandDict); + SPBeginAlertSheet(NSLocalizedString(@"Remote Error", @"remote error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self parentWindow], self, nil, nil, + [NSString stringWithFormat:NSLocalizedString(@"URL scheme command “%@” unsupported", @"URL scheme command “%@” unsupported"), command]); + + } - (void)registerActivity:(NSDictionary*)commandDict -- cgit v1.2.3