From 263c981e4905595ebcb3e5d57609ddf75bdf40a2 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Tue, 14 Dec 2010 20:33:08 +0000 Subject: =?UTF-8?q?=E2=80=A2=20URL=20scheme=20commands:=20-=20display=20so?= =?UTF-8?q?me=20error=20tooltips=20and=20improved=20the=20cancellation=20v?= =?UTF-8?q?ia=20=E2=8C=98.=20of=20the=20sequelpro://SP=5FPROCESS=5FID@pass?= =?UTF-8?q?ToDoc/ExecuteQuery=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPDatabaseDocument.m | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'Source/SPDatabaseDocument.m') diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index 7cea8eab..4717ccbe 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -55,6 +55,7 @@ #import "SPTableCopy.h" #import "SPDatabaseRename.h" #import "SPServerSupport.h" +#import "SPTooltip.h" @interface SPDatabaseDocument (PrivateAPI) @@ -4553,7 +4554,10 @@ if(!docProcessID) docProcessID = @""; // Authenticate command - if(![docProcessID isEqualToString:[commandDict objectForKey:@"id"]]) return; + if(![docProcessID isEqualToString:[commandDict objectForKey:@"id"]]) { + [SPTooltip showWithObject:NSLocalizedString(@"URL scheme command couldn't authenticated", @"URL scheme command couldn't authenticated") atLocation:[NSApp mouseLocation]]; + return; + } if([command isEqualToString:@"SelectDocumentView"]) { if([params count] == 2) { @@ -4645,7 +4649,8 @@ if([command isEqualToString:@"ExecuteQuery"]) { // Bail if document is busy - if (_isWorkingLevel) return; + if (_isWorkingLevel) + [SPTooltip showWithObject:NSLocalizedString(@"Connection window is busy. URL scheme command bailed", @"Connection window is busy. URL scheme command bailed") atLocation:[NSApp mouseLocation]]; NSString *outputFormat = @"tab"; if([params count] == 2) @@ -4660,6 +4665,7 @@ NSFileManager *fm = [NSFileManager defaultManager]; NSString *status = @"0"; BOOL isDir; + BOOL userTerminated = NO; if([fm fileExistsAtPath:queryFileName isDirectory:&isDir] && !isDir) { NSError *inError = nil; @@ -4717,12 +4723,21 @@ NSInteger i, j; NSArray *theRow; NSMutableString *result = [NSMutableString string]; - if(writeAsCsv) { for ( i = 0 ; i < [theResult numOfRows] ; i++ ) { [result setString:@""]; theRow = [theResult fetchNextRowAsArray]; for( j = 0 ; j < [theRow count] ; j++ ) { + + NSEvent* event = [NSApp currentEvent]; + if ([event type] == NSKeyDown) { + unichar key = [[event characters] length] == 1 ? [[event characters] characterAtIndex:0] : 0; + if (([event modifierFlags] & NSCommandKeyMask) && key == '.') { + userTerminated = YES; + break; + } + } + if([result length]) [result appendString:@","]; id cell = NSArrayObjectAtIndex(theRow, j); if([cell isKindOfClass:[NSNull class]]) @@ -4742,6 +4757,7 @@ else [result appendFormat:@"\"%@\"", [[cell description] stringByReplacingOccurrencesOfString:@"\"" withString:@"\"\""]]; } + if(userTerminated) break; [result appendString:@"\n"]; [fh writeData:[result dataUsingEncoding:NSUTF8StringEncoding]]; } @@ -4751,6 +4767,16 @@ [result setString:@""]; theRow = [theResult fetchNextRowAsArray]; for( j = 0 ; j < [theRow count] ; j++ ) { + + NSEvent* event = [NSApp currentEvent]; + if ([event type] == NSKeyDown) { + unichar key = [[event characters] length] == 1 ? [[event characters] characterAtIndex:0] : 0; + if (([event modifierFlags] & NSCommandKeyMask) && key == '.') { + userTerminated = YES; + break; + } + } + if([result length]) [result appendString:@"\t"]; id cell = NSArrayObjectAtIndex(theRow, j); if([cell isKindOfClass:[NSNull class]]) @@ -4770,6 +4796,7 @@ else [result appendString:[[[cell description] stringByReplacingOccurrencesOfString:@"\n" withString:@"↵"] stringByReplacingOccurrencesOfString:@"\t" withString:@"⇥"]]; } + if(userTerminated) break; [result appendString:@"\n"]; [fh writeData:[result dataUsingEncoding:NSUTF8StringEncoding]]; } @@ -4779,6 +4806,11 @@ } } + if(userTerminated) { + [SPTooltip showWithObject:NSLocalizedString(@"URL scheme command was terminated by user", @"URL scheme command was terminated by user") atLocation:[NSApp mouseLocation]]; + status = @"1"; + } + // write status file as notification that query was finished BOOL succeed = [status writeToFile:statusFileName atomically:YES encoding:NSUTF8StringEncoding error:nil]; if(!succeed) { -- cgit v1.2.3