aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2009-04-19 17:16:04 +0000
committerrowanbeentje <rowan@beent.je>2009-04-19 17:16:04 +0000
commit289a2e83a0827179db74ff95cee33dc01e19ae4b (patch)
tree953236e53e5fe1ae9323a6447f3c671d728f66f3
parentd4dd7e79ce8373fe94521da2294a076887758ee2 (diff)
downloadsequelpro-289a2e83a0827179db74ff95cee33dc01e19ae4b.tar.gz
sequelpro-289a2e83a0827179db74ff95cee33dc01e19ae4b.tar.bz2
sequelpro-289a2e83a0827179db74ff95cee33dc01e19ae4b.zip
- Merge in r594 from 10.5 trunk
-rw-r--r--Source/CMTextView.h2
-rw-r--r--Source/CMTextView.m55
2 files changed, 51 insertions, 6 deletions
diff --git a/Source/CMTextView.h b/Source/CMTextView.h
index 8f32ff8e..d4f0135a 100644
--- a/Source/CMTextView.h
+++ b/Source/CMTextView.h
@@ -32,6 +32,8 @@
BOOL delBackwardsWasPressed;
NoodleLineNumberView *lineNumberView;
+ NSString *lookupInDocumentationTitle;
+
IBOutlet NSScrollView *scrollView;
}
diff --git a/Source/CMTextView.m b/Source/CMTextView.m
index 427c66d1..62f84629 100644
--- a/Source/CMTextView.m
+++ b/Source/CMTextView.m
@@ -41,10 +41,59 @@ 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=%@"
@implementation CMTextView
/*
+ * Add a menu item to context menu for looking up mysql documentation.
+ */
+- (NSMenu *)menuForEvent:(NSEvent *)event
+{
+ // Set title of the menu item
+ lookupInDocumentationTitle = NSLocalizedString(@"Lookup In MySQL Documentation", @"Lookup In MySQL Documentation");
+
+ // Add the menu item if it doesn't yet exist
+ NSMenu *menu = [[self class] defaultMenu];
+
+ if ([[[self class] defaultMenu] itemWithTitle:lookupInDocumentationTitle] == nil) {
+
+ [menu insertItem:[NSMenuItem separatorItem] atIndex:3];
+ [menu insertItemWithTitle:lookupInDocumentationTitle action:@selector(lookupSelectionInDocumentation) keyEquivalent:@"" atIndex:4];
+ }
+
+ return menu;
+}
+
+/*
+ * Open a search for the current selection on mysql.com
+ */
+- (void)lookupSelectionInDocumentation
+{
+ // 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];
+
+ // Open MySQL Documentation search in browser using the terms
+ NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:MYSQL_DOC_SEARCH_URL, keyword]];
+
+ [[NSWorkspace sharedWorkspace] openURL:url];
+}
+
+/*
+ * Disable the lookup in documentation function when there is no selection.
+ */
+- (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 YES;
+}
+
+/*
* Checks if the char after the current caret position/selection matches a supplied attribute
*/
- (BOOL) isNextCharMarkedBy:(id)attribute
@@ -61,7 +110,6 @@ YY_BUFFER_STATE yy_scan_string (const char *);
return NO;
}
-
/*
* Checks if the caret is wrapped by auto-paired characters.
* e.g. [| := caret]: "|"
@@ -94,7 +142,6 @@ YY_BUFFER_STATE yy_scan_string (const char *);
return NO;
}
-
/*
* If the textview has a selection, wrap it with the supplied prefix and suffix strings;
* return whether or not any wrap was performed.
@@ -133,10 +180,8 @@ YY_BUFFER_STATE yy_scan_string (const char *);
[pb declareTypes:[NSArray arrayWithObject:NSRTFPboardType] owner:self];
[pb setData:rtf forType:NSRTFPboardType];
}
-
}
-
/*
* Handle some keyDown events in order to provide autopairing functionality (if enabled).
*/
@@ -1260,7 +1305,6 @@ YY_BUFFER_STATE yy_scan_string (const char *);
return autouppercaseKeywordsEnabled;
}
-
/*******************
SYNTAX HIGHLIGHTING!
*******************/
@@ -1411,7 +1455,6 @@ SYNTAX HIGHLIGHTING!
value: kWQval
range: tokenRange ];
}
-
}
@end