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 | |
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')
-rw-r--r-- | Source/CMTextView.m | 9 | ||||
-rw-r--r-- | Source/CustomQuery.h | 5 | ||||
-rw-r--r-- | Source/CustomQuery.m | 74 |
3 files changed, 86 insertions, 2 deletions
diff --git a/Source/CMTextView.m b/Source/CMTextView.m index dcb5f2b6..4ccbe16e 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -22,6 +22,7 @@ // Or mail to <lorenz@textor.ch> #import "CMTextView.h" +#import "CustomQuery.h" #import "TableDocument.h" #import "SPStringAdditions.h" #import "SPTextViewAdditions.h" @@ -265,6 +266,13 @@ YY_BUFFER_STATE yy_scan_string (const char *); [self copyAsRTF]; return; } + if([charactersIgnMod isEqualToString:@"h"]) // ^C copy as RTF + if(curFlags==(NSControlKeyMask)) + { + + [[[[self window] delegate] valueForKeyPath:@"customQueryInstance"] getHelpForCurrentWord:self]; + return; + } // Only process for character autopairing if autopairing is enabled and a single character is being added. if (autopairEnabled && characters && [characters length] == 1) { @@ -1692,6 +1700,7 @@ SYNTAX HIGHLIGHTING! [scrollView setHasHorizontalRuler:NO]; [scrollView setHasVerticalRuler:YES]; [scrollView setRulersVisible:YES]; + } - (void)textStorageDidProcessEditing:(NSNotification *)notification diff --git a/Source/CustomQuery.h b/Source/CustomQuery.h index 42803215..e1906fd1 100644 --- a/Source/CustomQuery.h +++ b/Source/CustomQuery.h @@ -23,6 +23,7 @@ // Or mail to <lorenz@textor.ch> #import <Cocoa/Cocoa.h> +#import <WebKit/WebKit.h> #import <MCPKit_bundled/MCPKit_bundled.h> #import "CMCopyTable.h" #import "CMTextView.h" @@ -57,6 +58,9 @@ IBOutlet NSMenuItem *autopairMenuItem; IBOutlet NSMenuItem *autouppercaseKeywordsMenuItem; + IBOutlet NSWindow *helpWebViewWindow; + IBOutlet id helpWebView; + NSArray *queryResult; NSUserDefaults *prefs; NSMutableArray *queryFavorites; @@ -75,6 +79,7 @@ - (IBAction)chooseQueryHistory:(id)sender; - (IBAction)closeSheet:(id)sender; - (IBAction)gearMenuItemSelected:(id)sender; +- (IBAction)getHelpForCurrentWord:(id)sender; // queryFavoritesSheet methods - (IBAction)addQueryFavorite:(id)sender; 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 |