aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/CMTextView.m26
-rw-r--r--Source/SPTextViewAdditions.h2
-rw-r--r--Source/SPTextViewAdditions.m6
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);
-
}
/*