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 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 7 deletions(-) (limited to 'Source/CMTextView.m') 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]; -- cgit v1.2.3