From 73ed762bceaf6244d00486c183f83639915dfe32 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 3 Dec 2009 16:21:50 +0000 Subject: =?UTF-8?q?=E2=80=A2=20fixed=20issue=20for=20"Update=20Help=20whil?= =?UTF-8?q?e=20typing"=20to=20suppress=20opening=20the=20MySQL=20documenta?= =?UTF-8?q?tion=20periodically=20=20if=20no=20internal=20help=20can=20be?= =?UTF-8?q?=20found?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CMTextView.m | 4 ++-- Source/CustomQuery.h | 5 +++-- Source/CustomQuery.m | 49 ++++++++++++++++++++++++++++++++++--------------- Source/TableDocument.m | 2 +- 4 files changed, 40 insertions(+), 20 deletions(-) (limited to 'Source') diff --git a/Source/CMTextView.m b/Source/CMTextView.m index ae526221..ed032400 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -2005,14 +2005,14 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) // If selection show Help for it if([self selectedRange].length) { - [[[[self window] delegate] valueForKeyPath:@"customQueryInstance"] performSelector:@selector(showHelpForCurrentWord:) withObject:self afterDelay:0.1]; + [[[[self window] delegate] valueForKeyPath:@"customQueryInstance"] performSelector:@selector(showAutoHelpForCurrentWord:) withObject:self afterDelay:0.1]; return; } // Otherwise show Help if caret is not inside quotes long cursorPosition = [self selectedRange].location; if (cursorPosition >= [[self string] length]) cursorPosition--; if(cursorPosition > -1 && (![[self textStorage] attribute:kQuote atIndex:cursorPosition effectiveRange:nil]||[[self textStorage] attribute:kSQLkeyword atIndex:cursorPosition effectiveRange:nil])) - [[[[self window] delegate] valueForKeyPath:@"customQueryInstance"] performSelector:@selector(showHelpForCurrentWord:) withObject:self afterDelay:0.1]; + [[[[self window] delegate] valueForKeyPath:@"customQueryInstance"] performSelector:@selector(showAutoHelpForCurrentWord:) withObject:self afterDelay:0.1]; } diff --git a/Source/CustomQuery.h b/Source/CustomQuery.h index 0cbb6c0c..ba0e456d 100644 --- a/Source/CustomQuery.h +++ b/Source/CustomQuery.h @@ -171,8 +171,9 @@ - (void)processResultIntoDataStorage:(MCPStreamingResult *)theResult; // MySQL Help -- (NSString *)getHTMLformattedMySQLHelpFor:(NSString *)aString; -- (void)showHelpFor:(NSString *)aString addToHistory:(BOOL)addToHistory; +- (void)showAutoHelpForCurrentWord:(id)sender; +- (NSString *)getHTMLformattedMySQLHelpFor:(NSString *)searchString calledByAutoHelp:(BOOL)autoHelp; +- (void)showHelpFor:(NSString *)aString addToHistory:(BOOL)addToHistory calledByAutoHelp:(BOOL)autoHelp; - (void)helpTargetValidation; - (void)openMySQLonlineDocumentationWithString:(NSString *)searchString; - (NSWindow *)helpWebViewWindow; diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index 522fb5d0..69f3beb7 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -2131,10 +2131,17 @@ /* * Show the data for "HELP 'searchString'". */ -- (void)showHelpFor:(NSString *)searchString addToHistory:(BOOL)addToHistory +- (void)showHelpFor:(NSString *)searchString addToHistory:(BOOL)addToHistory calledByAutoHelp:(BOOL)autoHelp { - - NSString * helpString = [self getHTMLformattedMySQLHelpFor:searchString]; + + if(![searchString length]) return; + + NSString *helpString = [self getHTMLformattedMySQLHelpFor:searchString calledByAutoHelp:autoHelp]; + + if(autoHelp && [helpString isEqualToString:SP_HELP_NOT_AVAILABLE]) { + [helpWebViewWindow orderOut:nil]; + return; + } // Order out resp. init the Help window if not visible if(![helpWebViewWindow isVisible]) @@ -2163,7 +2170,7 @@ } - // close Help window if no Help avaiable + // close Help window if no Help available if([helpString isEqualToString:SP_HELP_NOT_AVAILABLE]) [helpWebViewWindow close]; @@ -2205,7 +2212,7 @@ [self openMySQLonlineDocumentationWithString:searchString]; break; case SP_HELP_SEARCH_IN_MYSQL: - [self showHelpFor:searchString addToHistory:YES]; + [self showHelpFor:searchString addToHistory:YES calledByAutoHelp:NO]; break; } } @@ -2215,7 +2222,7 @@ */ - (IBAction)showHelpForWebViewSelection:(id)sender { - [self showHelpFor:[[helpWebView selectedDOMRange] text] addToHistory:YES]; + [self showHelpFor:[[helpWebView selectedDOMRange] text] addToHistory:YES calledByAutoHelp:NO]; } /* @@ -2239,7 +2246,7 @@ - (IBAction)showHelpForCurrentWord:(id)sender { NSString *searchString = [[sender string] substringWithRange:[sender getRangeForCurrentWord]]; - [self showHelpFor:searchString addToHistory:YES]; + [self showHelpFor:searchString addToHistory:YES calledByAutoHelp:NO]; } /* @@ -2269,7 +2276,7 @@ [helpWebView goBack]; break; case SP_HELP_SHOW_TOC_BUTTON: - [self showHelpFor:SP_HELP_TOC_SEARCH_STRING addToHistory:YES]; + [self showHelpFor:SP_HELP_TOC_SEARCH_STRING addToHistory:YES calledByAutoHelp:NO]; break; case SP_HELP_GOFORWARD_BUTTON: [helpWebView goForward]; @@ -2308,6 +2315,15 @@ [self helpTargetValidation]; } +/* + * Show the data for "HELP 'currentWord' invoked by autohelp" + */ +- (void)showAutoHelpForCurrentWord:(id)sender +{ + NSString *searchString = [[sender string] substringWithRange:[sender getRangeForCurrentWord]]; + [self showHelpFor:searchString addToHistory:YES calledByAutoHelp:YES]; +} + /* * Control the help search field behaviour. */ @@ -2339,7 +2355,7 @@ * Return the help string HTML formatted from executing "HELP 'searchString'". * If more than one help topic was found return a link list. */ -- (NSString *)getHTMLformattedMySQLHelpFor:(NSString *)searchString +- (NSString *)getHTMLformattedMySQLHelpFor:(NSString *)searchString calledByAutoHelp:(BOOL)autoHelp { if(![searchString length]) return @""; @@ -2353,11 +2369,14 @@ // search via: HELP 'searchString' theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"HELP '%@'", [searchString stringByReplacingOccurrencesOfString:@"'" withString:@"\\'"]]]; - if ( ![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) + if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) { - // if an error or HELP is not supported fall back to online search - NSLog(@"Error in HELP statement for '%@'", searchString); - [self openMySQLonlineDocumentationWithString:searchString]; + // if an error or HELP is not supported fall back to online search but + // don't open it if autoHelp is enabled + if(!autoHelp) + [self openMySQLonlineDocumentationWithString:searchString]; + + [helpWebViewWindow close]; return SP_HELP_NOT_AVAILABLE; } // nothing found? @@ -2487,7 +2506,7 @@ int navigationType = [[actionInformation objectForKey:WebActionNavigationTypeKey] intValue]; if([[[request URL] scheme] isEqualToString:@"applewebdata"] && navigationType == WebNavigationTypeLinkClicked){ - [self showHelpFor:[[[request URL] path] lastPathComponent] addToHistory:YES]; + [self showHelpFor:[[[request URL] path] lastPathComponent] addToHistory:YES calledByAutoHelp:NO]; [listener ignore]; } else { if (navigationType == WebNavigationTypeOther) { @@ -2502,7 +2521,7 @@ [listener ignore]; } else if (navigationType == WebNavigationTypeBackForward) { // catch back/forward events from contextual menu - [self showHelpFor:[[[[actionInformation objectForKey:WebActionOriginalURLKey] absoluteString] lastPathComponent] stringByReplacingPercentEscapesUsingEncoding:NSASCIIStringEncoding] addToHistory:NO]; + [self showHelpFor:[[[[actionInformation objectForKey:WebActionOriginalURLKey] absoluteString] lastPathComponent] stringByReplacingPercentEscapesUsingEncoding:NSASCIIStringEncoding] addToHistory:NO calledByAutoHelp:NO]; [listener ignore]; } else if (navigationType == WebNavigationTypeReload) { // just in case diff --git a/Source/TableDocument.m b/Source/TableDocument.m index 0269d1a6..ba98a3d7 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -2822,7 +2822,7 @@ */ - (IBAction)showMySQLHelp:(id)sender { - [customQueryInstance showHelpFor:SP_HELP_TOC_SEARCH_STRING addToHistory:YES]; + [customQueryInstance showHelpFor:SP_HELP_TOC_SEARCH_STRING addToHistory:YES calledByAutoHelp:NO]; [[customQueryInstance helpWebViewWindow] makeKeyWindow]; } -- cgit v1.2.3