aboutsummaryrefslogtreecommitdiffstats
path: root/Source/CMTextView.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-04-30 12:47:01 +0000
committerBibiko <bibiko@eva.mpg.de>2009-04-30 12:47:01 +0000
commit373af7d28f55328a0d004ddd106ccbaafdd782d4 (patch)
treeb3aba55c6bfd4ac45a56ec0bfb7dca5c167653fa /Source/CMTextView.m
parent40dc576b30ec1da22ae58c1daaae86a6d1020b2c (diff)
downloadsequelpro-373af7d28f55328a0d004ddd106ccbaafdd782d4.tar.gz
sequelpro-373af7d28f55328a0d004ddd106ccbaafdd782d4.tar.bz2
sequelpro-373af7d28f55328a0d004ddd106ccbaafdd782d4.zip
• changed context menu item in CQ's textview to support "MySQL Help"
• prepared code to work with autoHelp • improved getRangeForCurrentWord (fix for " |a")
Diffstat (limited to 'Source/CMTextView.m')
-rw-r--r--Source/CMTextView.m61
1 files changed, 27 insertions, 34 deletions
diff --git a/Source/CMTextView.m b/Source/CMTextView.m
index 272efc07..0c35c4c3 100644
--- a/Source/CMTextView.m
+++ b/Source/CMTextView.m
@@ -44,6 +44,8 @@ YY_BUFFER_STATE yy_scan_string (const char *);
#define kQuote @"Quote"
#define kValue @"dummy"
+#define SP_CQ_SEARCH_IN_MYSQL_HELP_MENU_ITEM_TAG 1000
+
#define MYSQL_DOC_SEARCH_URL @"http://dev.mysql.com/doc/refman/%@/en/%@.html"
@@ -63,56 +65,48 @@ YY_BUFFER_STATE yy_scan_string (const char *);
- (NSMenu *)menuForEvent:(NSEvent *)event
{
// Set title of the menu item
- lookupInDocumentationTitle = NSLocalizedString(@"Lookup In MySQL Documentation", @"Lookup In MySQL Documentation");
+ if([self selectedRange].length)
+ showMySQLHelpFor = NSLocalizedString(@"MySQL Help for Selection", @"MySQL Help for Selection");
+ else
+ showMySQLHelpFor = NSLocalizedString(@"MySQL Help for Word", @"MySQL Help for Word");
// Add the menu item if it doesn't yet exist
NSMenu *menu = [[self class] defaultMenu];
- if ([[[self class] defaultMenu] itemWithTitle:lookupInDocumentationTitle] == nil) {
-
+ if ([[[self class] defaultMenu] itemWithTag:SP_CQ_SEARCH_IN_MYSQL_HELP_MENU_ITEM_TAG] == nil)
+ {
[menu insertItem:[NSMenuItem separatorItem] atIndex:3];
- [menu insertItemWithTitle:lookupInDocumentationTitle action:@selector(lookupSelectionInDocumentation) keyEquivalent:@"" atIndex:4];
+ NSMenuItem *showMySQLHelpForMenuItem = [[NSMenuItem alloc] initWithTitle:showMySQLHelpFor action:@selector(showMySQLHelpForCurrentWord:) keyEquivalent:@"h"];
+ [showMySQLHelpForMenuItem setTag:SP_CQ_SEARCH_IN_MYSQL_HELP_MENU_ITEM_TAG];
+ [showMySQLHelpForMenuItem setKeyEquivalentModifierMask:NSControlKeyMask];
+ [menu insertItem:showMySQLHelpForMenuItem atIndex:4];
+ } else {
+ [[menu itemWithTag:SP_CQ_SEARCH_IN_MYSQL_HELP_MENU_ITEM_TAG] setTitle:showMySQLHelpFor];
}
-
return menu;
}
/*
- * pen the refman if available or a search for the current selection or current word on mysql.com
+ * Disable the search in the MySQL help function when getRangeForCurrentWord returns zero length.
*/
-- (void)lookupSelectionInDocumentation
+- (BOOL)validateMenuItem:(NSMenuItem *)menuItem
{
- // 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 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, version, [keyword stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]]];
+ // Enable or disable the search in the MySQL help menu item depending on whether there is a
+ // selection and whether it is a reasonable length.
+ if ([menuItem action] == @selector(showMySQLHelpForCurrentWord:)) {
+ long stringSize = [self getRangeForCurrentWord].length;
+ return (stringSize || stringSize > 64);
+ }
- [[NSWorkspace sharedWorkspace] openURL:url];
+ return YES;
}
/*
- * Disable the lookup in documentation function when getRangeForCurrentWord returns zero length.
+ * Search for the current selection or current word in the MySQL Help
*/
-- (BOOL)validateMenuItem:(NSMenuItem *)menuItem
+- (IBAction)showMySQLHelpForCurrentWord:(id)sender
{
- // 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 getRangeForCurrentWord].length) || ([self getRangeForCurrentWord].length > 256));
- }
-
- return YES;
+ [[[[self window] delegate] valueForKeyPath:@"customQueryInstance"] showHelpForCurrentWord:self];
}
/*
@@ -276,7 +270,7 @@ YY_BUFFER_STATE yy_scan_string (const char *);
if(curFlags==(NSControlKeyMask))
{
- [[[[self window] delegate] valueForKeyPath:@"customQueryInstance"] showHelpForCurrentWord:self];
+ [self showMySQLHelpForCurrentWord:self];
return;
}
@@ -1733,7 +1727,6 @@ SYNTAX HIGHLIGHTING!
autohelpEnabled = NO;
delBackwardsWasPressed = NO;
-
lineNumberView = [[NoodleLineNumberView alloc] initWithScrollView:scrollView];
[scrollView setVerticalRulerView:lineNumberView];
[scrollView setHasHorizontalRuler:NO];