diff options
author | stuconnolly <stuart02@gmail.com> | 2009-04-19 23:06:58 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2009-04-19 23:06:58 +0000 |
commit | 51b50e943dea3cfd00eb8d49c67044ec7862f405 (patch) | |
tree | 01c295a1f23d0ae57955423ed40a97a242b5de13 /Source | |
parent | 729a8ba1c4d8ffe72d9f43addb5afac78b1df599 (diff) | |
download | sequelpro-51b50e943dea3cfd00eb8d49c67044ec7862f405.tar.gz sequelpro-51b50e943dea3cfd00eb8d49c67044ec7862f405.tar.bz2 sequelpro-51b50e943dea3cfd00eb8d49c67044ec7862f405.zip |
- Build upon documentation lookup by looking up exact manual pages that correspond to the current MySQL server version as well as allowing the lookup to be performed without actually having the keyword highlighted. Thanks to Hans-Jörg for suggesting these.
- Credit Alex King for providing the original documentation lookup code.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CMTextView.m | 26 | ||||
-rw-r--r-- | Source/SPTextViewAdditions.h | 2 | ||||
-rw-r--r-- | Source/SPTextViewAdditions.m | 6 |
3 files changed, 25 insertions, 9 deletions
diff --git a/Source/CMTextView.m b/Source/CMTextView.m index c66fa134..a19edb25 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -22,7 +22,9 @@ // Or mail to <lorenz@textor.ch> #import "CMTextView.h" +#import "TableDocument.h" #import "SPStringAdditions.h" +#import "SPTextViewAdditions.h" /* * Include all the extern variables and prototypes required for flex (used for syntax highlighting) @@ -41,7 +43,7 @@ YY_BUFFER_STATE yy_scan_string (const char *); #define kSQLkeyword @"SQLkw" // attribute for found SQL keywords #define kQuote @"Quote" -#define MYSQL_DOC_SEARCH_URL @"http://search.mysql.com/search?q=%@" +#define MYSQL_DOC_SEARCH_URL @"http://dev.mysql.com/doc/refman/%@/en/%@.html" @implementation CMTextView @@ -66,28 +68,38 @@ YY_BUFFER_STATE yy_scan_string (const char *); } /* - * Open a search for the current selection on mysql.com + * pen the refman if available or a search for the current selection or current word on mysql.com */ - (void)lookupSelectionInDocumentation { + // Get the major MySQL server version in the form of x.x, which is basically the first 3 characters of the returned version string + NSString *version = [[(TableDocument *)[[self window] delegate] mySQLVersion] substringToIndex:3]; + // Get the current selection and encode it to be used in a URL - NSString *keyword = [[[[self string] substringWithRange:[self selectedRange]] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]; - + NSString *keyword = [[[self string] substringWithRange:[self getRangeForCurrentWord]] lowercaseString]; + + // Remove whitespace and newlines + keyword = [keyword stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + + // Remove whitespace and newlines within the keyword + keyword = [keyword stringByReplacingOccurrencesOfString:@" " withString:@""]; + keyword = [keyword stringByReplacingOccurrencesOfString:@"\n" withString:@""]; + // Open MySQL Documentation search in browser using the terms - NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:MYSQL_DOC_SEARCH_URL, keyword]]; + NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:MYSQL_DOC_SEARCH_URL, version, [keyword stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]]]; [[NSWorkspace sharedWorkspace] openURL:url]; } /* - * Disable the lookup in documentation function when there is no selection. + * Disable the lookup in documentation function when getRangeForCurrentWord returns zero length. */ - (BOOL)validateMenuItem:(NSMenuItem *)menuItem { // Enable or disable the lookup in documentation menu item depending on whether there is a // selection and whether it is a reasonable length. if ([menuItem action] == @selector(lookupSelectionInDocumentation)) { - return (([self selectedRange].length) || ([self selectedRange].length > 256)); + return (([self getRangeForCurrentWord].length) || ([self getRangeForCurrentWord].length > 256)); } return YES; diff --git a/Source/SPTextViewAdditions.h b/Source/SPTextViewAdditions.h index 95075165..2fcbeeee 100644 --- a/Source/SPTextViewAdditions.h +++ b/Source/SPTextViewAdditions.h @@ -24,6 +24,8 @@ @interface NSTextView (SPTextViewAdditions) +- (NSRange)getRangeForCurrentWord; + - (IBAction)selectCurrentWord:(id)sender; - (IBAction)selectCurrentLine:(id)sender; - (IBAction)doSelectionUpperCase:(id)sender; diff --git a/Source/SPTextViewAdditions.m b/Source/SPTextViewAdditions.m index 885e51df..38560b31 100644 --- a/Source/SPTextViewAdditions.m +++ b/Source/SPTextViewAdditions.m @@ -31,8 +31,11 @@ */ - (NSRange)getRangeForCurrentWord { - NSRange curRange = [self selectedRange]; + + if (curRange.length) + return curRange; + unsigned long curLocation = curRange.location; [self moveWordLeft:self]; @@ -57,7 +60,6 @@ [self setSelectedRange:curRange]; return(wordRange); - } /* |