aboutsummaryrefslogtreecommitdiffstats
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
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")
-rw-r--r--Resources/PreferenceDefaults.plist2
-rw-r--r--Source/CMTextView.h5
-rw-r--r--Source/CMTextView.m61
-rw-r--r--Source/CustomQuery.h1
-rw-r--r--Source/CustomQuery.m11
-rw-r--r--Source/SPTextViewAdditions.m15
6 files changed, 58 insertions, 37 deletions
diff --git a/Resources/PreferenceDefaults.plist b/Resources/PreferenceDefaults.plist
index 72e924f6..bc41f299 100644
--- a/Resources/PreferenceDefaults.plist
+++ b/Resources/PreferenceDefaults.plist
@@ -42,6 +42,8 @@
<true/>
<key>CustomQueryAutouppercaseKeywords</key>
<false/>
+ <key>CustomQueryAutohelp</key>
+ <false/>
<key>SelectLastFavoriteUsed</key>
<true/>
<key>LastFavoriteIndex</key>
diff --git a/Source/CMTextView.h b/Source/CMTextView.h
index 88b7a995..7abc2ef1 100644
--- a/Source/CMTextView.h
+++ b/Source/CMTextView.h
@@ -33,13 +33,16 @@
BOOL autohelpEnabled;
NoodleLineNumberView *lineNumberView;
- NSString *lookupInDocumentationTitle;
+ NSString *showMySQLHelpFor;
BOOL sqlStringIsTooLarge;
IBOutlet NSScrollView *scrollView;
+
}
+- (IBAction)showMySQLHelpForCurrentWord:(id)sender;
+
- (BOOL) isNextCharMarkedBy:(id)attribute;
- (BOOL) areAdjacentCharsLinked;
- (BOOL) wrapSelectionWithPrefix:(NSString *)prefix suffix:(NSString *)suffix;
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];
diff --git a/Source/CustomQuery.h b/Source/CustomQuery.h
index 34c1ebff..1fae3b5d 100644
--- a/Source/CustomQuery.h
+++ b/Source/CustomQuery.h
@@ -57,6 +57,7 @@
IBOutlet NSMenuItem *editorFontMenuItem;
IBOutlet NSMenuItem *autoindentMenuItem;
IBOutlet NSMenuItem *autopairMenuItem;
+ IBOutlet NSMenuItem *autohelpMenuItem;
IBOutlet NSMenuItem *autouppercaseKeywordsMenuItem;
IBOutlet NSWindow *helpWebViewWindow;
diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m
index a7741792..10cf95f7 100644
--- a/Source/CustomQuery.m
+++ b/Source/CustomQuery.m
@@ -245,6 +245,15 @@ closes the sheet
[textView setAutopair:enableAutopair];
}
+ // "Auto-help" toggle
+ if (sender == autohelpMenuItem) {
+ BOOL enableAutohelp = ([autohelpMenuItem state] == NSOffState);
+ [prefs setBool:enableAutohelp forKey:@"CustomQueryAutohelp"];
+ [prefs synchronize];
+ [autohelpMenuItem setState:enableAutohelp?NSOnState:NSOffState];
+ [textView setAutohelp:enableAutohelp];
+ }
+
// "Auto-uppercase keywords" toggle
if (sender == autouppercaseKeywordsMenuItem) {
BOOL enableAutouppercaseKeywords = ([autouppercaseKeywordsMenuItem state] == NSOffState);
@@ -910,6 +919,8 @@ sets the connection (received from TableDocument) and makes things that have to
[textView setAutoindentIgnoresEnter:YES];
[autopairMenuItem setState:([prefs boolForKey:@"CustomQueryAutopair"]?NSOnState:NSOffState)];
[textView setAutopair:[prefs boolForKey:@"CustomQueryAutopair"]];
+ [autohelpMenuItem setState:([prefs boolForKey:@"CustomQueryAutohelp"]?NSOnState:NSOffState)];
+ [textView setAutohelp:[prefs boolForKey:@"CustomQueryAutohelp"]];
[autouppercaseKeywordsMenuItem setState:([prefs boolForKey:@"CustomQueryAutouppercaseKeywords"]?NSOnState:NSOffState)];
[textView setAutouppercaseKeywords:[prefs boolForKey:@"CustomQueryAutouppercaseKeywords"]];
[queryFavoritesView registerForDraggedTypes:[NSArray arrayWithObjects:@"SequelProPasteboard", nil]];
diff --git a/Source/SPTextViewAdditions.m b/Source/SPTextViewAdditions.m
index 38560b31..dc3d4c16 100644
--- a/Source/SPTextViewAdditions.m
+++ b/Source/SPTextViewAdditions.m
@@ -49,10 +49,21 @@
if(curLocation < newStartRange || curLocation > newEndRange)
{
[self setSelectedRange:curRange];
- [self moveWordRightAndModifySelection:self];
+ [self moveWordRight:self];
+ [self moveWordLeftAndModifySelection:self];
+ newStartRange = [self selectedRange].location;
+ newEndRange = newStartRange + [self selectedRange].length;
}
- if([[[self string] substringWithRange:[self selectedRange]] rangeOfCharacterFromSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]].location != NSNotFound)
+ // how many space in front of the selection
+ int bias = [self selectedRange].length - [[[[self string] substringWithRange:[self selectedRange]] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length];
+ [self setSelectedRange:NSMakeRange([self selectedRange].location+bias, [self selectedRange].length-bias)];
+ newStartRange += bias;
+ newEndRange -= bias;
+
+ // is caret inside the selection still?
+ if(curLocation < newStartRange || curLocation > newEndRange
+ || [[[self string] substringWithRange:[self selectedRange]] rangeOfCharacterFromSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]].location != NSNotFound)
[self setSelectedRange:curRange];
NSRange wordRange = [self selectedRange];