diff options
author | Bibiko <bibiko@eva.mpg.de> | 2009-04-27 13:31:44 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2009-04-27 13:31:44 +0000 |
commit | 494226553237e2e19d882339180f8be26153eea4 (patch) | |
tree | 2c24fcc2fb46707864616989c3e876e94f67d117 /Source | |
parent | 88c964159c602ea2562a7a70451f1cf7667ad06f (diff) | |
download | sequelpro-494226553237e2e19d882339180f8be26153eea4.tar.gz sequelpro-494226553237e2e19d882339180f8be26153eea4.tar.bz2 sequelpro-494226553237e2e19d882339180f8be26153eea4.zip |
• MySQL Help improved
- better HTML view, list topics for multi-matching keywords
- for test cases invoke it by CTRL+H in the Custom Query textView
- GUI is really tentative!
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CustomQuery.h | 11 | ||||
-rw-r--r-- | Source/CustomQuery.m | 180 |
2 files changed, 174 insertions, 17 deletions
diff --git a/Source/CustomQuery.h b/Source/CustomQuery.h index e1906fd1..4f8fd468 100644 --- a/Source/CustomQuery.h +++ b/Source/CustomQuery.h @@ -60,6 +60,8 @@ IBOutlet NSWindow *helpWebViewWindow; IBOutlet id helpWebView; + IBOutlet NSSearchField *helpSearchField; + NSString *lastHelpString; NSArray *queryResult; NSUserDefaults *prefs; @@ -80,6 +82,10 @@ - (IBAction)closeSheet:(id)sender; - (IBAction)gearMenuItemSelected:(id)sender; - (IBAction)getHelpForCurrentWord:(id)sender; +- (IBAction)showHelpForSearchString:(id)sender; +- (IBAction)showHelpContent:(id)sender; +- (IBAction)showLastHelp:(id)sender; + // queryFavoritesSheet methods - (IBAction)addQueryFavorite:(id)sender; @@ -96,10 +102,15 @@ // Accessors - (NSArray *)currentResult; +// MySQL Help +- (void)showHelpFor:(NSString *)aString; +- (NSString *)getHTMLHelpFor:(NSString *)aString; + // Other - (void)setConnection:(CMMCPConnection *)theConnection; - (void)setFavorites; - (void)doPerformQueryService:(NSString *)query; - (NSString *)usedQuery; + @end diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index 51880119..d0f0f606 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -114,72 +114,218 @@ } /* - * Return the help string formatted from executing "HELP 'aString'" + * Retrieve and show the data for "HELP 'search word'" + */ + +- (IBAction)showHelpForSearchString:(id)sender +{ + [self showHelpFor:[[helpSearchField stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]]; +} + +/* + * Retrieve and show the data for "HELP 'currentWord'" */ - (IBAction)getHelpForCurrentWord:(id)sender { NSString *aString = [[textView string] substringWithRange:[textView getRangeForCurrentWord]]; - if(![aString length]) return; + // if(![aString length]) return; + + [self showHelpFor:aString]; + +} + +/* + * Retrieve and show the data for "HELP 'contents' (MySQL help root)". + */ + +- (IBAction)showHelpContent:(id)sender +{ + [self showHelpFor:@"contents"]; +} + +- (IBAction)showLastHelp:(id)sender +{ + NSLog(@"%@", lastHelpString); + if([lastHelpString length]) + [self showHelpFor:lastHelpString]; +} + + +/* + * Retrieve and show the data for "HELP 'aString'". + */ +- (void)showHelpFor:(NSString *)aString +{ + NSString * helpString = [self getHTMLHelpFor:aString]; + lastHelpString = [[NSString stringWithString:aString] retain]; + // Order out the Help window + if(![helpWebViewWindow isVisible]) + { + + // Get the major MySQL server version in the form of x.x, which is basically the first 3 characters of the returned version string + //get mysql version + CMMCPResult *theResult = nil; + NSString *mySQLVersion; + theResult = [mySQLConnection queryString:@"SHOW VARIABLES LIKE 'version'"]; + NSString *version = [[theResult fetchRowAsArray] objectAtIndex:1]; + if ( [version isKindOfClass:[NSData class]] ) { + // starting with MySQL 4.1.14 the mysql variables are returned as nsdata + mySQLVersion = [[NSString alloc] initWithData:version encoding:[mySQLConnection encoding]]; + } else { + mySQLVersion = [[NSString stringWithString:version] retain]; + } + + [helpWebViewWindow setTitle:[NSString stringWithFormat:@"%@ (%@ %@)", NSLocalizedString(@"MySQL Help", @"mysql help"), NSLocalizedString(@"version", @"version"), [mySQLVersion substringToIndex:3]]]; + [helpWebViewWindow orderFront:helpWebView]; + } + + if(![helpString length]) return; + + [[helpWebView mainFrame] loadHTMLString:helpString baseURL:nil]; + +} + + +/* + * Return the help string HTML formatted from executing "HELP 'aString'". + * If more than one help topic was found return a link list. + */ +- (NSString *)getHTMLHelpFor:(NSString *)aString +{ + + if(![aString length]) return(@""); CMMCPResult *theResult = nil; NSDictionary *tableDetails; + NSRange aRange; NSMutableString *theHelp = [NSMutableString string]; [theHelp setString: @"<html>" @"<head>" @" <style type='text/css' media='screen'>" @" body {" - @" margin: 0px;" - @" padding: 20px;" - @" overflow: hidden;" - @" display: table-cell;" + @" margin: 2px;" + @" padding: 10px;" + @" font-family:'Helvetica';" + @" font-size:9pt;" + @" }" + @" .internallink {" + @" color:#6A81DD;" + @" text-decoration:none;" @" }" @" .code {" @" font-family:Monaco;" @" }" @" .header {" - @" background-color:#eeeeee;" @" padding:5mm;" @" }" @" </style>" @"</head>" @"<body>" + ]; theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"HELP '%@'", aString]]; - if ( ![[mySQLConnection getLastErrorMessage] isEqualToString:@""] || ![theResult numOfRows]) return; + if ( ![[mySQLConnection getLastErrorMessage] isEqualToString:@""] || ![theResult numOfRows]) return @""; tableDetails = [[NSDictionary alloc] initWithDictionary:[theResult fetchRowAsDictionary]]; - if ([tableDetails objectForKey:@"description"]) { // help found + if ([tableDetails objectForKey:@"description"]) { // one single help topic found if ([tableDetails objectForKey:@"name"]) { - [theHelp appendString:@"<h2 class='header'>"]; + [theHelp appendString:@"<h2 class='header'> "]; [theHelp appendString:[[[tableDetails objectForKey:@"name"] copy] autorelease]]; [theHelp appendString:@"</h2>"]; } if ([tableDetails objectForKey:@"description"]) { + NSMutableString *desc = [NSMutableString string]; + NSError *err1 = NULL; + NSString *aUrl; + + [desc setString:[[[tableDetails objectForKey:@"description"] copy] autorelease]]; + + // Look for an URL and create an HTML link out of it + aRange = [desc rangeOfRegex:@"URL: +(.*)" options:RKLNoOptions inRange:NSMakeRange(0, [desc length]) capture:1 error:&err1]; + if(aRange.location != NSNotFound) { + aUrl = [desc substringWithRange:aRange]; + [desc replaceCharactersInRange:aRange withString:[NSString stringWithFormat:@"<a href='%@'>%@</a>", aUrl, aUrl]]; + } + // aRange = NSMakeRange(0,0); + // int safeCnt = 0; + // while(1){ + // aRange = [desc rangeOfRegex:@"(http.*?)\\s" options:RKLNoOptions inRange:NSMakeRange(aRange.location+aRange.length, [desc length]-aRange.location-aRange.length) capture:1 error:&err1]; + // if(aRange.location != NSNotFound) { + // aUrl = [desc substringWithRange:aRange]; + // [desc replaceCharactersInRange:aRange withString:[NSString stringWithFormat:@"<a href='%@'>%@</a>", aUrl, aUrl]]; + // } + // else + // break; + // safeCnt++; + // if(safeCnt > 20) + // break; + // } + [theHelp appendString:@"<pre class='code'>"]; - [theHelp appendString:[[[tableDetails objectForKey:@"description"] copy] autorelease]]; + [theHelp appendString:desc]; [theHelp appendString:@"</pre>"]; } if([tableDetails objectForKey:@"example"]){ NSString *examples = [[[tableDetails objectForKey:@"example"] copy] autorelease]; if([examples length]){ - [theHelp appendString:@"<br><br><i><b>Example:</b></i><br><pre class='code'>"]; + [theHelp appendString:@"<br><br><i><b>Example:</b></i><br><br><pre class='code'>"]; [theHelp appendString:examples]; [theHelp appendString:@"</pre>"]; } } - [theHelp appendString:@"</body></html>"]; - + } else { // list all found topics + int i; + int r = [theResult numOfRows]; + if (r) [theResult dataSeek:0]; + + if(![aString isEqualToString:@"contents"]) + [theHelp appendString:[NSString stringWithFormat:@"<br><i>%@ “%@”</i><br>", NSLocalizedString(@"Help topics for", @"help topics for"), aString]]; + else + [theHelp appendString:[NSString stringWithFormat:@"<br><b>%@:</b><br>", NSLocalizedString(@"MySQL Help – Categories", @"mysql help categories"), aString]]; + + [theHelp appendString:@"<ul>"]; + for ( i = 0 ; i < r ; i++ ) { + NSArray *anArray = [theResult fetchRowAsArray]; + NSString *topic = [anArray objectAtIndex:[anArray count]-2]; + [theHelp appendString: + [NSString stringWithFormat:@"<li><a title='%@ “%@”' href='%@' class='internallink'>%@</a></li>", NSLocalizedString(@"Show MySQL help for", @"show mysql help for"), topic, topic, topic]]; + } + [theHelp appendString:@"</ul>"]; } - + [theHelp appendString:@"</body></html>"]; + [tableDetails release]; - [[helpWebView mainFrame] loadHTMLString:theHelp baseURL:nil]; - [helpWebViewWindow orderFront:self]; + return theHelp; + +} +/* + * Link detector: If user clicked at an http link open it in the default browser, + * otherwise search for it in the MySQL help. + */ +- (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener +{ + int navigationType = [[actionInformation objectForKey:WebActionNavigationTypeKey] intValue]; + if([[[request URL] scheme] isEqualToString:@"applewebdata"]){ + [self showHelpFor:[[[request URL] path] substringWithRange:NSMakeRange(1,[[[request URL] path] length]-1)]]; + [listener ignore]; + } else { + if (navigationType == WebNavigationTypeOther) { + [listener use]; + } else if (navigationType == WebNavigationTypeLinkClicked) { + [[NSWorkspace sharedWorkspace] openURL:[actionInformation objectForKey:WebActionOriginalURLKey]]; + [listener ignore]; + } else { + // Ignore WebNavigationTypeFormSubmitted, WebNavigationTypeBackForward, + // WebNavigationTypeReload and WebNavigationTypeFormResubmitted. + [listener ignore]; + } + } } |