From bd58198b9b166f1abfa3bbbc84acd46676b68d89 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 24 Apr 2009 15:20:54 +0000 Subject: =?UTF-8?q?=E2=80=A2=20added=20a=20prototype=20to=20support=20an?= =?UTF-8?q?=20Help=20view=20for=20the=20current=20word=20in=20the=20Custom?= =?UTF-8?q?=20Query=20text=20view=20-=20work=20in=20progress!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CMTextView.m | 9 +++++++ Source/CustomQuery.h | 5 ++++ Source/CustomQuery.m | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 86 insertions(+), 2 deletions(-) (limited to 'Source') 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 #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 #import +#import #import #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: + @"" + @"" + @" " + @"" + @"" + ]; + + 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:@"

"]; + [theHelp appendString:[[[tableDetails objectForKey:@"name"] copy] autorelease]]; + [theHelp appendString:@"

"]; + + } + if ([tableDetails objectForKey:@"description"]) { + [theHelp appendString:@"
"];
+			[theHelp appendString:[[[tableDetails objectForKey:@"description"] copy] autorelease]];
+			[theHelp appendString:@"
"]; + } + if([tableDetails objectForKey:@"example"]){ + NSString *examples = [[[tableDetails objectForKey:@"example"] copy] autorelease]; + if([examples length]){ + [theHelp appendString:@"

Example:
"];
+				[theHelp appendString:examples];
+				[theHelp appendString:@"
"]; + } + } + [theHelp appendString:@""]; + + } + + [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 -- cgit v1.2.3