From 8fe53cf1cdfdc3939b5aea81eda4227d04da2dea Mon Sep 17 00:00:00 2001 From: Bibiko Date: Wed, 15 Dec 2010 12:59:33 +0000 Subject: =?UTF-8?q?=E2=80=A2=20sequelpro=20URL=20scheme=20support=20-=20ad?= =?UTF-8?q?ded=20command=20"SyntaxHighlighting/format"=20which=20returns?= =?UTF-8?q?=20the=20syntax=20highlighted=20string=20due=20to=20the=20forma?= =?UTF-8?q?t=20settings=20(up=20to=20now=20html=20and=20htmlcss)=20-=20add?= =?UTF-8?q?ed=20command=20"CreateSyntaxForTables/item1/item2/=E2=80=A6/{fo?= =?UTF-8?q?rmat}"=20which=20returns=20all=20CREATE=20SYNTAX=20statements?= =?UTF-8?q?=20of=20the=20passed=20items=20and=20if=20passed=20syntax=20hig?= =?UTF-8?q?hlighted=20due=20to=20format=20(optional)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPDatabaseDocument.h | 1 + Source/SPDatabaseDocument.m | 286 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 282 insertions(+), 5 deletions(-) (limited to 'Source') diff --git a/Source/SPDatabaseDocument.h b/Source/SPDatabaseDocument.h index e7fac8bf..fd716668 100644 --- a/Source/SPDatabaseDocument.h +++ b/Source/SPDatabaseDocument.h @@ -357,6 +357,7 @@ - (NSWindow *)parentWindow; // Scripting +- (NSString*)doSQLSyntaxHighlightForString:(NSString*)sqlText cssLike:(BOOL)cssLike; - (void)handleSchemeCommand:(NSDictionary*)commandDict; - (void)registerActivity:(NSDictionary*)commandDict; - (void)removeRegisteredActivity:(NSInteger)pid; diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index 4717ccbe..d6bdd768 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -56,6 +56,19 @@ #import "SPDatabaseRename.h" #import "SPServerSupport.h" #import "SPTooltip.h" +#import "SPEditorTokens.h" + +#pragma mark lex init + +/* +* Include all the extern variables and prototypes required for flex (used for syntax highlighting) +*/ +extern NSUInteger yylex(); +extern NSUInteger yyuoffset, yyuleng; +typedef struct yy_buffer_state *YY_BUFFER_STATE; +void yy_switch_to_buffer(YY_BUFFER_STATE); +YY_BUFFER_STATE yy_scan_string (const char *); + @interface SPDatabaseDocument (PrivateAPI) @@ -4543,6 +4556,83 @@ #pragma mark - #pragma mark Scheme scripting methods +- (NSString*)doSQLSyntaxHighlightForString:(NSString*)sqlText cssLike:(BOOL)cssLike +{ + + NSMutableString *sqlHTML = [[[NSMutableString alloc] initWithCapacity:[sqlText length]] autorelease]; + + NSRange textRange = NSMakeRange(0, [sqlText length]); + NSString *tokenColor; + NSString *cssId; + size_t token; + NSRange tokenRange; + + // initialise flex + yyuoffset = 0; yyuleng = 0; + yy_switch_to_buffer(yy_scan_string([sqlText UTF8String])); + BOOL skipFontTag; + + while (token=yylex()){ + skipFontTag = NO; + switch (token) { + case SPT_SINGLE_QUOTED_TEXT: + case SPT_DOUBLE_QUOTED_TEXT: + tokenColor = @"#A7221C"; + cssId = @"sp_sql_quoted"; + break; + case SPT_BACKTICK_QUOTED_TEXT: + tokenColor = @"#001892"; + cssId = @"sp_sql_backtick"; + break; + case SPT_RESERVED_WORD: + tokenColor = @"#0041F6"; + cssId = @"sp_sql_keyword"; + break; + case SPT_NUMERIC: + tokenColor = @"#67350F"; + cssId = @"sp_sql_numeric"; + break; + case SPT_COMMENT: + tokenColor = @"#265C10"; + cssId = @"sp_sql_comment"; + break; + case SPT_VARIABLE: + tokenColor = @"#6C6C6C"; + cssId = @"sp_sql_variable"; + break; + case SPT_WHITESPACE: + skipFontTag = YES; + cssId = @""; + break; + default: + skipFontTag = YES; + cssId = @""; + } + + tokenRange = NSMakeRange(yyuoffset, yyuleng); + + if(skipFontTag) + [sqlHTML appendString:[[sqlText substringWithRange:tokenRange] HTMLEscapeString]]; + else { + if(cssLike) + [sqlHTML appendFormat:@"%@", cssId, [[sqlText substringWithRange:tokenRange] HTMLEscapeString]]; + else + [sqlHTML appendFormat:@"%@", tokenColor, [[sqlText substringWithRange:tokenRange] HTMLEscapeString]]; + } + + } + + // Wrap lines, and replace tabs with spaces + [sqlHTML replaceOccurrencesOfString:@"\n" withString:@"
" options:NSLiteralSearch range:NSMakeRange(0, [sqlHTML length])]; + [sqlHTML replaceOccurrencesOfString:@"\t" withString:@"    " options:NSLiteralSearch range:NSMakeRange(0, [sqlHTML length])]; + + if(sqlHTML) + return sqlHTML; + else + return @""; + +} + - (void)handleSchemeCommand:(NSDictionary*)commandDict { @@ -4553,6 +4643,12 @@ NSString *docProcessID = [self processID]; if(!docProcessID) docProcessID = @""; + // 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]]; @@ -4617,7 +4713,6 @@ } if([command isEqualToString:@"SelectDatabase"]) { - if (_isWorkingLevel) return; if([params count] > 1) { NSString *dbName = [params objectAtIndex:1]; NSString *tableName = nil; @@ -4646,11 +4741,192 @@ return; } - if([command isEqualToString:@"ExecuteQuery"]) { + if([command isEqualToString:@"SyntaxHighlighting"]) { + + NSFileManager *fm = [NSFileManager defaultManager]; + BOOL isDir; + + NSString *queryFileName = [NSString stringWithFormat:@"%@%@", SPURLSchemeQueryInputPathHeader, docProcessID]; + NSString *resultFileName = [NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultPathHeader, docProcessID]; + NSString *metaFileName = [NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultMetaPathHeader, docProcessID]; + NSString *statusFileName = [NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultStatusPathHeader, docProcessID]; + + NSError *inError = nil; + NSString *query = [NSString stringWithContentsOfFile:queryFileName encoding:NSUTF8StringEncoding error:inError]; + NSString *result = @""; + NSString *status = @"0"; + + if([fm fileExistsAtPath:queryFileName isDirectory:&isDir] && !isDir) { - // 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]]; + if(inError == nil && query && [query length]) { + if([params count] > 1) { + if([[params lastObject] isEqualToString:@"html"]) + result = [NSString stringWithString:[self doSQLSyntaxHighlightForString:query cssLike:NO]]; + else if([[params lastObject] isEqualToString:@"htmlcss"]) + result = [NSString stringWithString:[self doSQLSyntaxHighlightForString:query cssLike:YES]]; + } + } + } + + [fm removeItemAtPath:queryFileName error:nil]; + [fm removeItemAtPath:resultFileName error:nil]; + [fm removeItemAtPath:metaFileName error:nil]; + [fm removeItemAtPath:statusFileName error:nil]; + + if(![result writeToFile:resultFileName atomically:YES encoding:NSUTF8StringEncoding error:nil]) + status = @"1"; + + // write status file as notification that query was finished + 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, + 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; + } + + if([command isEqualToString:@"CreateSyntaxForTables"]) { + + if([params count] > 1) { + + NSString *queryFileName = [NSString stringWithFormat:@"%@%@", SPURLSchemeQueryInputPathHeader, docProcessID]; + NSString *resultFileName = [NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultPathHeader, docProcessID]; + NSString *metaFileName = [NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultMetaPathHeader, docProcessID]; + NSString *statusFileName = [NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultStatusPathHeader, docProcessID]; + NSFileManager *fm = [NSFileManager defaultManager]; + NSString *status = @"0"; + BOOL isDir; + BOOL userTerminated = NO; + BOOL doSyntaxHighlighting = NO; + BOOL doSyntaxHighlightingViaCSS = NO; + + if([[params lastObject] hasPrefix:@"html"]) { + doSyntaxHighlighting = YES; + if([[params lastObject] hasSuffix:@"css"]) { + doSyntaxHighlightingViaCSS = YES; + } + } + + if(doSyntaxHighlighting && [params count] < 3) return; + + BOOL changeEncoding = ![[mySQLConnection encoding] isEqualToString:@"utf8"]; + + NSArray *items = [params subarrayWithRange:NSMakeRange(1, [params count]-( (doSyntaxHighlighting) ? 2 : 1) )]; + NSArray *availableItems = [tablesListInstance tables]; + NSArray *availableItemTypes = [tablesListInstance tableTypes]; + NSMutableString *result = [NSMutableString string]; + + for(NSString* item in items) { + + 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; + } + } + + NSInteger itemType = SPTableTypeNone; + NSString *itemTypeStr = @"TABLE"; + NSInteger i; + NSInteger queryCol = 1; + + // Loop through the unfiltered tables/views to find the desired item + for (i = 0; i < [availableItems count]; i++) { + itemType = [[availableItemTypes objectAtIndex:i] integerValue]; + if (itemType == SPTableTypeNone) continue; + if ([[availableItems objectAtIndex:i] isEqualToString:item]) { + break; + } + } + // If no match found, continue + if (itemType == SPTableTypeNone) continue; + + switch(itemType) { + case SPTableTypeTable: + case SPTableTypeView: + itemTypeStr = @"TABLE"; + break; + case SPTableTypeProc: + itemTypeStr = @"PROCEDURE"; + queryCol = 2; + break; + case SPTableTypeFunc: + itemTypeStr = @"FUNCTION"; + queryCol = 2; + break; + } + + // Ensure that queries are made in UTF8 + if (changeEncoding) { + [mySQLConnection storeEncodingForRestoration]; + [mySQLConnection setEncoding:@"utf8"]; + } + + // Get create syntax + MCPResult *queryResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW CREATE %@ %@", + itemTypeStr, + [item backtickQuotedString] + ]]; + [queryResult setReturnDataAsStrings:YES]; + + if (changeEncoding) [mySQLConnection restoreStoredEncoding]; + + if ( ![queryResult numOfRows] ) { + //error while getting table structure + SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self parentWindow], self, nil, nil, + [NSString stringWithFormat:NSLocalizedString(@"Couldn't get create syntax.\nMySQL said: %@", @"message of panel when table information cannot be retrieved"), [mySQLConnection getLastErrorMessage]]); + + status = @"1"; + + } else { + NSString *syntaxString = [[queryResult fetchRowAsArray] objectAtIndex:queryCol]; + + // A NULL value indicates that the user does not have permission to view the syntax + if ([syntaxString isNSNull]) { + [[NSAlert alertWithMessageText:NSLocalizedString(@"Permission Denied", @"Permission Denied") + defaultButton:NSLocalizedString(@"OK", @"OK button") + alternateButton:nil otherButton:nil + informativeTextWithFormat:NSLocalizedString(@"The creation syntax could not be retrieved due to a permissions error.\n\nPlease check your user permissions with an administrator.", @"Create syntax permission denied detail")] + beginSheetModalForWindow:[NSApp mainWindow] + modalDelegate:self didEndSelector:NULL contextInfo:NULL]; + + return; + } + if(doSyntaxHighlighting) { + [result appendFormat:@"%@
", [self doSQLSyntaxHighlightForString:[syntaxString createViewSyntaxPrettifier] cssLike:doSyntaxHighlightingViaCSS]]; + } else { + [result appendFormat:@"%@\n", [syntaxString createViewSyntaxPrettifier]]; + } + } + } + + [fm removeItemAtPath:queryFileName error:nil]; + [fm removeItemAtPath:resultFileName error:nil]; + [fm removeItemAtPath:metaFileName error:nil]; + [fm removeItemAtPath:statusFileName error:nil]; + + if(userTerminated) + status = @"1"; + + if(![result writeToFile:resultFileName atomically:YES encoding:NSUTF8StringEncoding error:nil]) + status = @"1"; + + // write status file as notification that query was finished + 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, + 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; + } + + if([command isEqualToString:@"ExecuteQuery"]) { NSString *outputFormat = @"tab"; if([params count] == 2) -- cgit v1.2.3 From 418ab5876c0a278ed0e2b86d5215739f95bc6add Mon Sep 17 00:00:00 2001 From: Bibiko Date: Wed, 15 Dec 2010 21:14:41 +0000 Subject: =?UTF-8?q?=E2=80=A2=20fixed=20issue=20to=20be=20able=20to=20cance?= =?UTF-8?q?l=20via=20ESC=20the=20in-cell=20editing=20of=20the=20tablesList?= =?UTF-8?q?View=20(and=20avoiding=20to=20call=20completion=20for=20Query?= =?UTF-8?q?=20Editor)=20and=20Bundle=20Editor's=20outlineView;=20in=20addi?= =?UTF-8?q?tion=20the=20focus=20remains=20at=20the=20view?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPBundleEditorController.m | 2 +- Source/SPTablesList.m | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'Source') diff --git a/Source/SPBundleEditorController.m b/Source/SPBundleEditorController.m index dffcb20c..32f5b581 100644 --- a/Source/SPBundleEditorController.m +++ b/Source/SPBundleEditorController.m @@ -1257,7 +1257,7 @@ */ - (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)command { - if ( [[control window] methodForSelector:command] == [[control window] methodForSelector:@selector(_cancelKey:)] || + if ( [[control window] methodForSelector:command] == [[control window] methodForSelector:@selector(cancelOperation:)] || [textView methodForSelector:command] == [textView methodForSelector:@selector(complete:)] ) { //abort editing diff --git a/Source/SPTablesList.m b/Source/SPTablesList.m index 54e0f400..da787a6d 100644 --- a/Source/SPTablesList.m +++ b/Source/SPTablesList.m @@ -1358,11 +1358,12 @@ [[control window] makeFirstResponder:control]; return TRUE; - } else if ( [[control window] methodForSelector:command] == [[control window] methodForSelector:@selector(_cancelKey:)] || + } else if ( [[control window] methodForSelector:command] == [[control window] methodForSelector:@selector(cancelOperation:)] || [textView methodForSelector:command] == [textView methodForSelector:@selector(complete:)] ) { //abort editing [control abortEditing]; + [[NSApp mainWindow] makeFirstResponder:tablesListView]; return TRUE; } else{ -- cgit v1.2.3 From add2eb659aae82a187e8b51e19af9a201f08a1ca Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 16 Dec 2010 12:58:44 +0000 Subject: =?UTF-8?q?=E2=80=A2=20in=20HTML=20output=20window=20hyperlink=20r?= =?UTF-8?q?eferences=20which=20begin=20with=20file://=20will=20reveal=20th?= =?UTF-8?q?at=20file=20in=20Finder=20=E2=80=A2=20in=20SPCopyTable=20for=20?= =?UTF-8?q?tab-delimited=20row=20data=20replace=20\t=20by=20=E2=87=A5=20an?= =?UTF-8?q?d=20\n=20by=20=E2=86=B5=20if=20they=20occur=20in=20data=20cells?= =?UTF-8?q?=20for=20convenience?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPBundleHTMLOutputController.m | 8 +++++++- Source/SPCopyTable.m | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'Source') diff --git a/Source/SPBundleHTMLOutputController.m b/Source/SPBundleHTMLOutputController.m index 7cad079b..7bcff455 100644 --- a/Source/SPBundleHTMLOutputController.m +++ b/Source/SPBundleHTMLOutputController.m @@ -267,7 +267,13 @@ if([[[request URL] scheme] isEqualToString:@"sequelpro"] && navigationType == WebNavigationTypeLinkClicked) { [[NSApp delegate] handleEventWithURL:[request URL]]; [listener ignore]; - } else { + } + // file://a_file_path opens the reveal the file in Finder + else if([[[request URL] scheme] isEqualToString:@"file"] && navigationType == WebNavigationTypeLinkClicked) { + [[NSWorkspace sharedWorkspace] selectFile:[[[request mainDocumentURL] absoluteString] substringFromIndex:6] inFileViewerRootedAtPath:nil]; + [listener ignore]; + } + else { switch(navigationType) { case WebNavigationTypeLinkClicked: diff --git a/Source/SPCopyTable.m b/Source/SPCopyTable.m index 6b9383ab..fad9332e 100644 --- a/Source/SPCopyTable.m +++ b/Source/SPCopyTable.m @@ -228,7 +228,7 @@ NSInteger kBlobAsImageFile = 4; } } else - [result appendFormat:@"%@\t", [cellData description]]; + [result appendFormat:@"%@\t", [[[cellData description] stringByReplacingOccurrencesOfString:@"\n" withString:@"↵"] stringByReplacingOccurrencesOfString:@"\t" withString:@"⇥"]]; } else { [result appendString:@"\t"]; } -- cgit v1.2.3 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(-) (limited to 'Source') 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 From 521c78fc8e87734c8bdf7a30024ba51c3ec1a306 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 17 Dec 2010 12:33:21 +0000 Subject: =?UTF-8?q?=E2=80=A2=20improved=20timing=20behaviour=20for=20a=20S?= =?UTF-8?q?PDatabaseDocument=20if=20it=20receives=20a=20sequence=20of=20UR?= =?UTF-8?q?L=20scheme=20commands?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPDatabaseDocument.h | 2 ++ Source/SPDatabaseDocument.m | 23 ++++++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) (limited to 'Source') diff --git a/Source/SPDatabaseDocument.h b/Source/SPDatabaseDocument.h index fd716668..bcd92d59 100644 --- a/Source/SPDatabaseDocument.h +++ b/Source/SPDatabaseDocument.h @@ -163,6 +163,8 @@ NSInteger _queryMode; BOOL _isSavedInBundle; + BOOL _workingTimeout; + NSWindow *taskProgressWindow; BOOL taskDisplayIsIndeterminate; CGFloat taskProgressValue; diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index a66d0f42..0c2b7de7 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -4633,6 +4633,11 @@ YY_BUFFER_STATE yy_scan_string (const char *); } +- (void)setTimeout +{ + _workingTimeout = YES; +} + - (void)handleSchemeCommand:(NSDictionary*)commandDict { @@ -4643,11 +4648,19 @@ YY_BUFFER_STATE yy_scan_string (const char *); NSString *docProcessID = [self processID]; if(!docProcessID) docProcessID = @""; - // 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]]; - NSBeep(); - return; + // Wait for self + _workingTimeout = NO; + // the following while loop waits maximal 5secs + [self performSelector:@selector(setTimeout) withObject:nil afterDelay:5.0]; + while (_isWorkingLevel || !_isConnected) { + if(_workingTimeout) break; + // Do not block self + NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask + untilDate:[NSDate distantPast] + inMode:NSDefaultRunLoopMode + dequeue:YES]; + if(event) [NSApp sendEvent:event]; + } if([command isEqualToString:@"SelectDocumentView"]) { -- cgit v1.2.3 From 072a730f22e3c06fed48acf31ac5708259c93a32 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 17 Dec 2010 15:20:01 +0000 Subject: =?UTF-8?q?=E2=80=A2=C2=A0minor=20improvements,=20commenting,=20cl?= =?UTF-8?q?eaning=20for=20URL=20scheme=20commands?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPAppController.m | 30 +++--------------------------- Source/SPDatabaseDocument.m | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 28 deletions(-) (limited to 'Source') diff --git a/Source/SPAppController.m b/Source/SPAppController.m index a90876fa..046628b3 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -659,35 +659,11 @@ } } - if(!processDocument) + // if no processDoc found and no passedProcessID was passed execute + // command at front most doc + if(!processDocument && !passedProcessID) processDocument = [[[self frontDocumentWindow] delegate] selectedTableDocument]; - - BOOL userTerminated = NO; - - // while(1) { - // NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask - // untilDate:[NSDate distantPast] - // inMode:NSDefaultRunLoopMode - // dequeue:YES]; - // - // if ([event type] == NSKeyDown) { - // unichar key = [[event characters] length] == 1 ? [[event characters] characterAtIndex:0] : 0; - // if (([event modifierFlags] & NSCommandKeyMask) && key == '.') { - // userTerminated = YES; - // break; - // } - // } - // [NSApp sendEvent:event]; - // if(![processDocument isWorking]) break; - // usleep(1000); - // } - // - // if(userTerminated) { - // NSBeep(); - // return; - // } - if(processDocument && command) { if([command isEqualToString:@"passToDoc"]) { NSMutableDictionary *cmdDict = [NSMutableDictionary dictionary]; diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index 0c2b7de7..8557eeba 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -4556,6 +4556,9 @@ YY_BUFFER_STATE yy_scan_string (const char *); #pragma mark - #pragma mark Scheme scripting methods +/** + * Return an HTML formatted string representing the passed SQL string syntax highlighted + */ - (NSString*)doSQLSyntaxHighlightForString:(NSString*)sqlText cssLike:(BOOL)cssLike { @@ -4633,16 +4636,28 @@ YY_BUFFER_STATE yy_scan_string (const char *); } +/** + * Called by handleSchemeCommand: to break a while loop + */ - (void)setTimeout { _workingTimeout = YES; } +/** + * Process passed URL scheme command and wait (timeouted) for the document if it's busy or not yet connected + */ - (void)handleSchemeCommand:(NSDictionary*)commandDict { + if(!commandDict) return; + NSArray *params = [commandDict objectForKey:@"parameter"]; - if(![params count]) return; + if(![params count]) { + NSLog(@"No URL scheme command passed"); + NSBeep(); + return; + } NSString *command = [params objectAtIndex:0]; NSString *docProcessID = [self processID]; -- cgit v1.2.3