From 40dc576b30ec1da22ae58c1daaae86a6d1020b2c Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 30 Apr 2009 10:18:03 +0000 Subject: =?UTF-8?q?=E2=80=A2=20MySQL=20Help=20-=20updated=20autoHelp,=20no?= =?UTF-8?q?w=20it=20recognizes=20cursor=20movement=20via=20mouse=20?= =?UTF-8?q?=E2=80=A2=20if=20the=20chunk=20in=20CQ's=20textview=20is=20too?= =?UTF-8?q?=20large=20remove=20all=20attributes=20=E2=80=A2=20some=20minor?= =?UTF-8?q?=20code=20cosmetics?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CMTextView.h | 2 ++ Source/CMTextView.m | 38 +++++++++++++++++++++++++++----------- Source/CustomQuery.h | 2 +- Source/CustomQuery.m | 2 +- 4 files changed, 31 insertions(+), 13 deletions(-) (limited to 'Source') diff --git a/Source/CMTextView.h b/Source/CMTextView.h index 67a553b6..88b7a995 100644 --- a/Source/CMTextView.h +++ b/Source/CMTextView.h @@ -35,6 +35,8 @@ NSString *lookupInDocumentationTitle; + BOOL sqlStringIsTooLarge; + IBOutlet NSScrollView *scrollView; } diff --git a/Source/CMTextView.m b/Source/CMTextView.m index 89262a4b..272efc07 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -40,10 +40,10 @@ YY_BUFFER_STATE yy_scan_string (const char *); #define kAPlinked @"Linked" // attribute for a via auto-pair inserted char #define kAPval @"linked" #define kWQquoted @"Quoted" // set via lex to indicate a quoted string -#define kWquoted @"isQuoted" -#define kWQval @"aValue" #define kSQLkeyword @"SQLkw" // attribute for found SQL keywords #define kQuote @"Quote" +#define kValue @"dummy" + #define MYSQL_DOC_SEARCH_URL @"http://dev.mysql.com/doc/refman/%@/en/%@.html" @@ -241,7 +241,7 @@ YY_BUFFER_STATE yy_scan_string (const char *); */ - (void) keyDown:(NSEvent *)theEvent { - + if(autohelpEnabled) // cancel autoHelp request [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(autoHelp) @@ -412,6 +412,19 @@ YY_BUFFER_STATE yy_scan_string (const char *); } +- (void)mouseDown:(NSEvent *)theEvent +{ + + if(autohelpEnabled) // cancel autoHelp request + [NSObject cancelPreviousPerformRequestsWithTarget:self + selector:@selector(autoHelp) + object:nil]; + + [super mouseDown:theEvent]; + if(autohelpEnabled) + [self performSelector:@selector(autoHelp) withObject:nil afterDelay:1]; + +} - (void) deleteBackward:(id)sender { @@ -604,7 +617,7 @@ YY_BUFFER_STATE yy_scan_string (const char *); // Check if the caret is inside quotes "" or ''; if so // return the normal word suggestion due to the spelling's settings - if([[self textStorage] attribute:kQuote atIndex:charRange.location effectiveRange:nil]) + if(!sqlStringIsTooLarge && [[self textStorage] attribute:kQuote atIndex:charRange.location effectiveRange:nil]) return [[NSSpellChecker sharedSpellChecker] completionsForPartialWordRange:NSMakeRange(0,charRange.length) inString:[[self string] substringWithRange:charRange] language:nil inSpellDocumentWithTag:0]; NSCharacterSet *separators = [NSCharacterSet characterSetWithCharactersInString:@" \t\r\n,()\"'`-!;=+|?:~"]; @@ -1742,7 +1755,7 @@ SYNTAX HIGHLIGHTING! long cursorPosition = [self selectedRange].location; if (cursorPosition >= [[self string] length]) cursorPosition--; - if(cursorPosition > -1 && (![[[self textStorage] attribute:kQuote atIndex:cursorPosition effectiveRange:nil] isEqualToString:kWquoted]||[[self textStorage] attribute:kSQLkeyword atIndex:cursorPosition effectiveRange:nil])) + if(cursorPosition > -1 && (![[self textStorage] attribute:kQuote atIndex:cursorPosition effectiveRange:nil]||[[self textStorage] attribute:kSQLkeyword atIndex:cursorPosition effectiveRange:nil])) [[[[self window] delegate] valueForKeyPath:@"customQueryInstance"] performSelector:@selector(showHelpForCurrentWord:) withObject:self afterDelay:0.1]; } @@ -1779,11 +1792,14 @@ SYNTAX HIGHLIGHTING! textRange = NSMakeRange(0, [textStore length]); + //first remove the old colors and kQuote + [textStore removeAttribute:NSForegroundColorAttributeName range:textRange]; + [textStore removeAttribute:kQuote range:textRange]; + //don't color texts longer than about 20KB. would be too slow - if (textRange.length > 20000) return; + sqlStringIsTooLarge = (textRange.length > 20000); + if(sqlStringIsTooLarge) return; - //first remove the old colors - [textStore removeAttribute:NSForegroundColorAttributeName range:textRange]; //initialise flex yyuoffset = 0; yyuleng = 0; @@ -1856,7 +1872,7 @@ SYNTAX HIGHLIGHTING! // to disable auto-pairing if caret is inside of any token found by lex. // For discussion: maybe change it later (only for quotes not keywords?) [textStore addAttribute: kWQquoted - value: kWQval + value: kValue range: tokenRange ]; @@ -1864,13 +1880,13 @@ SYNTAX HIGHLIGHTING! // Performing it one token later allows words which start as reserved keywords to be entered. if(token == SPT_RESERVED_WORD) [textStore addAttribute: kSQLkeyword - value: kWQval + value: kValue range: tokenRange ]; // Add an attribute to be used to distinguish quotes from keywords etc. // used e.g. in completion suggestions if(token == SPT_DOUBLE_QUOTED_TEXT || token == SPT_SINGLE_QUOTED_TEXT || SPT_BACKTICK_QUOTED_TEXT) [textStore addAttribute: kQuote - value: kWquoted + value: kValue range: tokenRange ]; } diff --git a/Source/CustomQuery.h b/Source/CustomQuery.h index 8973804c..34c1ebff 100644 --- a/Source/CustomQuery.h +++ b/Source/CustomQuery.h @@ -60,7 +60,7 @@ IBOutlet NSMenuItem *autouppercaseKeywordsMenuItem; IBOutlet NSWindow *helpWebViewWindow; - IBOutlet id helpWebView; + IBOutlet WebView *helpWebView; IBOutlet NSSearchField *helpSearchField; IBOutlet NSSearchFieldCell *helpSearchFieldCell; IBOutlet NSSegmentedControl *helpNavigator; diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index 4af056b1..a7741792 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -1811,7 +1811,7 @@ traps enter key and } } - // Add two menu items for a selection + // Add two menu items for a selection if no link is given if(webViewMenuItems && [[element objectForKey:@"WebElementIsSelected"] boolValue] && ![[element objectForKey:@"WebElementLinkIsLive"] boolValue]) -- cgit v1.2.3