From 52b6a2b07abf9dbcf375431188fcd09aec44b60e Mon Sep 17 00:00:00 2001 From: Bibiko Date: Tue, 2 Feb 2010 10:25:54 +0000 Subject: =?UTF-8?q?=E2=80=A2=20added=20key-shortcut=20=E2=8C=98=3D=20to=20?= =?UTF-8?q?make=20the=20textview=20size=20larger=20=E2=80=A2=20=E2=8C=98-,?= =?UTF-8?q?=20=E2=8C=98+,=20=E2=8C=98=3D=20changes=20the=20font=20size=20t?= =?UTF-8?q?emporarily=20(Mac=20app=20conform)=20=E2=80=A2=20added=20key-sh?= =?UTF-8?q?ortcut=20=E2=8C=980=20to=20reset=20the=20font=20to=20pref=20def?= =?UTF-8?q?ault=20=E2=80=A2=20fixed=20search=20field=20background=20for=20?= =?UTF-8?q?Tables=20List=20=E2=80=A2=20fixed=20NSUInteger=20for=20completi?= =?UTF-8?q?on=20parsing;=20interrupt=20completion=20if=20parsed=20string?= =?UTF-8?q?=20length=20is=20larger=20than=20100000=20since=20it=20doesn't?= =?UTF-8?q?=20make=20sense=20and=20leads=20to=20warnings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CMTextView.m | 53 +++++++++++++++++++++++++++++++++++++++++++++------- Source/CustomQuery.m | 20 -------------------- 2 files changed, 46 insertions(+), 27 deletions(-) (limited to 'Source') diff --git a/Source/CMTextView.m b/Source/CMTextView.m index 97fceb37..2601a314 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -106,6 +106,10 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) - (void) awakeFromNib { + + prefs = [[NSUserDefaults standardUserDefaults] retain]; + [self setFont:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorFont]]]; + // Set self as delegate for the textView's textStorage to enable syntax highlighting, [[self textStorage] setDelegate:self]; @@ -125,6 +129,13 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) [scrollView setHasHorizontalRuler:NO]; [scrollView setHasVerticalRuler:YES]; [scrollView setRulersVisible:YES]; + [self setAllowsDocumentBackgroundColorChange:YES]; + [self setContinuousSpellCheckingEnabled:NO]; + [self setAutoindent:[prefs boolForKey:SPCustomQueryAutoIndent]]; + [self setAutoindentIgnoresEnter:YES]; + [self setAutopair:[prefs boolForKey:SPCustomQueryAutoPairCharacters]]; + [self setAutohelp:[prefs boolForKey:SPCustomQueryUpdateAutoHelp]]; + [self setAutouppercaseKeywords:[prefs boolForKey:SPCustomQueryAutoUppercaseKeywords]]; // Re-define 64 tab stops for a better editing NSFont *tvFont = [self font]; @@ -168,8 +179,6 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) NSNotificationCenter *aNotificationCenter = [NSNotificationCenter defaultCenter]; [aNotificationCenter addObserver:self selector:@selector(boundsDidChangeNotification:) name:@"NSViewBoundsDidChangeNotification" object:[scrollView contentView]]; - prefs = [[NSUserDefaults standardUserDefaults] retain]; - [self setQueryHiliteColor:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorHighlightQueryColor]]]; [self setQueryEditorBackgroundColor:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorBackgroundColor]]]; [self setCommentColor:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorCommentColor]]]; @@ -184,6 +193,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) [self setShouldHiliteQuery:[prefs boolForKey:SPCustomQueryHighlightCurrentQuery]]; // Register observers for the when editor background colors preference changes + [prefs addObserver:self forKeyPath:SPCustomQueryEditorFont options:NSKeyValueObservingOptionNew context:NULL]; [prefs addObserver:self forKeyPath:SPCustomQueryEditorBackgroundColor options:NSKeyValueObservingOptionNew context:NULL]; [prefs addObserver:self forKeyPath:SPCustomQueryEditorHighlightQueryColor options:NSKeyValueObservingOptionNew context:NULL]; [prefs addObserver:self forKeyPath:SPCustomQueryHighlightCurrentQuery options:NSKeyValueObservingOptionNew context:NULL]; @@ -211,6 +221,9 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) if ([keyPath isEqualToString:SPCustomQueryEditorBackgroundColor]) { [self setQueryEditorBackgroundColor:[NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]]]; [self setNeedsDisplay:YES]; + } else if ([keyPath isEqualToString:SPCustomQueryEditorFont]) { + [self setFont:[NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]]]; + [self setNeedsDisplay:YES]; } else if ([keyPath isEqualToString:SPCustomQueryEditorHighlightQueryColor]) { [self setQueryHiliteColor:[NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]]]; [self setNeedsDisplay:YES]; @@ -510,6 +523,10 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) NSString* prefix = @""; NSString *currentDb = nil; + // Break for long stuff + if(completionRange.length>100000) return; + + NSString* allow; // additional chars which not close the popup if(isDictMode) allow= @"_"; @@ -549,9 +566,9 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) NSCharacterSet *whiteSpaceCharSet = [NSCharacterSet whitespaceAndNewlineCharacterSet]; NSUInteger start = caretPos; NSInteger backticksCounter = (caretIsInsideBackticks) ? 1 : 0; - NSUInteger pointCounter = 0; - NSUInteger firstPoint = 0; - NSUInteger secondPoint = 0; + NSInteger pointCounter = 0; + NSInteger firstPoint = 0; + NSInteger secondPoint = 0; BOOL rightBacktick = NO; BOOL leftBacktick = NO; BOOL doParsing = YES; @@ -592,9 +609,13 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) } dbBrowseMode = (pointCounter || backticksCounter); - + if(dbBrowseMode) { parseRange = NSMakeRange(start, caretPos-start); + + // Break for long stuff + if(parseRange.length>100000) return; + NSString *parsedString = [[self string] substringWithRange:parseRange]; // Check if parsed string is wrapped by `` @@ -1449,7 +1470,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) return; } if(curFlags & NSCommandKeyMask) { - if([charactersIgnMod isEqualToString:@"+"]) // increase text size by 1; ⌘+ and numpad + + if([charactersIgnMod isEqualToString:@"+"] || [charactersIgnMod isEqualToString:@"="]) // increase text size by 1; ⌘+, ⌘=, and ⌘ numpad + { [self makeTextSizeLarger]; return; @@ -1459,6 +1480,10 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) [self makeTextSizeSmaller]; return; } + if([charactersIgnMod isEqualToString:@"0"]) { // reset font to default + [self setFont:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorFont]]]; + return; + } } // Only process for character autopairing if autopairing is enabled and a single character is being added. @@ -3452,6 +3477,20 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) NSLog(@"%@ ‘%@’.", NSLocalizedString(@"Couldn't read the file content of", @"Couldn't read the file content of"), aPath); } +- (void)changeFont:(id)sender +{ + if (prefs && [self font] != nil) { + [prefs setObject:[NSArchiver archivedDataWithRootObject:[self font]] forKey:SPCustomQueryEditorFont]; + NSFont *nf = [[NSFontPanel sharedFontPanel] panelConvertFont:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorFont]]]; + BOOL oldEditable = [self isEditable]; + [self setEditable:YES]; + [self setFont:nf]; + [self setEditable:oldEditable]; + [self setNeedsDisplay:YES]; + [prefs setObject:[NSArchiver archivedDataWithRootObject:nf] forKey:SPCustomQueryEditorFont]; + } +} + - (void) dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index d977d7de..75bbb894 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -1278,19 +1278,11 @@ // Set up the interface - [textView setAllowsDocumentBackgroundColorChange:YES]; - [customQueryView setVerticalMotionCanBeginDrag:NO]; - [textView setContinuousSpellCheckingEnabled:NO]; [autoindentMenuItem setState:([prefs boolForKey:SPCustomQueryAutoIndent]?NSOnState:NSOffState)]; - [textView setAutoindent:[prefs boolForKey:SPCustomQueryAutoIndent]]; - [textView setAutoindentIgnoresEnter:YES]; [autopairMenuItem setState:([prefs boolForKey:SPCustomQueryAutoPairCharacters]?NSOnState:NSOffState)]; - [textView setAutopair:[prefs boolForKey:SPCustomQueryAutoPairCharacters]]; [autohelpMenuItem setState:([prefs boolForKey:SPCustomQueryUpdateAutoHelp]?NSOnState:NSOffState)]; - [textView setAutohelp:[prefs boolForKey:SPCustomQueryUpdateAutoHelp]]; [autouppercaseKeywordsMenuItem setState:([prefs boolForKey:SPCustomQueryAutoUppercaseKeywords]?NSOnState:NSOffState)]; - [textView setAutouppercaseKeywords:[prefs boolForKey:SPCustomQueryAutoUppercaseKeywords]]; if ( [[SPQueryController sharedQueryController] historyForFileURL:[tableDocumentInstance fileURL]] ) { @@ -2107,18 +2099,6 @@ } } -/* - * Save the custom query editor font if it is changed. - */ -- (void)textViewDidChangeTypingAttributes:(NSNotification *)aNotification -{ - // Only save the font if prefs have been loaded, ensuring the saved font has been applied once. - // And check for [textView font] != nil which occurs while awaking from nib. - if (prefs && [textView font] != nil) - [prefs setObject:[NSArchiver archivedDataWithRootObject:[textView font]] forKey:SPCustomQueryEditorFont]; - -} - #pragma mark - #pragma mark TextField delegate methods -- cgit v1.2.3