diff options
Diffstat (limited to 'Source/CMTextView.m')
-rw-r--r-- | Source/CMTextView.m | 26 |
1 files changed, 19 insertions, 7 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; |