diff options
author | Bibiko <bibiko@eva.mpg.de> | 2009-04-24 15:20:54 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2009-04-24 15:20:54 +0000 |
commit | bd58198b9b166f1abfa3bbbc84acd46676b68d89 (patch) | |
tree | 54d8af0222777c9052d7e32c19c625ac8bf8794e /Source/CustomQuery.m | |
parent | 180579d026ffae575a25e698c279c465dbd1bd6b (diff) | |
download | sequelpro-bd58198b9b166f1abfa3bbbc84acd46676b68d89.tar.gz sequelpro-bd58198b9b166f1abfa3bbbc84acd46676b68d89.tar.bz2 sequelpro-bd58198b9b166f1abfa3bbbc84acd46676b68d89.zip |
• added a prototype to support an Help view for the current word in the Custom Query text view
- work in progress!
Diffstat (limited to 'Source/CustomQuery.m')
-rw-r--r-- | Source/CustomQuery.m | 74 |
1 files changed, 72 insertions, 2 deletions
diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index a5c7e8db..51880119 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -26,7 +26,7 @@ #import "SPSQLParser.h" #import "SPGrowlController.h" #import "SPStringAdditions.h" - +#import "SPTextViewAdditions.h" @implementation CustomQuery @@ -113,6 +113,75 @@ [self performQueries:queries]; } +/* + * Return the help string formatted from executing "HELP 'aString'" + */ +- (IBAction)getHelpForCurrentWord:(id)sender +{ + NSString *aString = [[textView string] substringWithRange:[textView getRangeForCurrentWord]]; + + if(![aString length]) return; + + CMMCPResult *theResult = nil; + NSDictionary *tableDetails; + NSMutableString *theHelp = [NSMutableString string]; + [theHelp setString: + @"<html>" + @"<head>" + @" <style type='text/css' media='screen'>" + @" body {" + @" margin: 0px;" + @" padding: 20px;" + @" overflow: hidden;" + @" display: table-cell;" + @" }" + @" .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; + + tableDetails = [[NSDictionary alloc] initWithDictionary:[theResult fetchRowAsDictionary]]; + + if ([tableDetails objectForKey:@"description"]) { // help found + if ([tableDetails objectForKey:@"name"]) { + [theHelp appendString:@"<h2 class='header'>"]; + [theHelp appendString:[[[tableDetails objectForKey:@"name"] copy] autorelease]]; + [theHelp appendString:@"</h2>"]; + + } + if ([tableDetails objectForKey:@"description"]) { + [theHelp appendString:@"<pre class='code'>"]; + [theHelp appendString:[[[tableDetails objectForKey:@"description"] copy] autorelease]]; + [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:examples]; + [theHelp appendString:@"</pre>"]; + } + } + [theHelp appendString:@"</body></html>"]; + + } + + [tableDetails release]; + [[helpWebView mainFrame] loadHTMLString:theHelp baseURL:nil]; + [helpWebViewWindow orderFront:self]; + +} + - (IBAction)chooseQueryFavorite:(id)sender /* @@ -1226,6 +1295,7 @@ traps enter key and } else { return NO; } + } else if ( aTextView == valueTextField ) { if ( [aTextView methodForSelector:aSelector] == [aTextView methodForSelector:@selector(insertNewline:)] ) { @@ -1374,8 +1444,8 @@ traps enter key and [prefs release]; [queryFavorites release]; [usedQuery release]; - [super dealloc]; + } @end |