From 1f938f1b54551a8418315301f7c5a2bca080e04d Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 5 Jun 2009 19:29:41 +0000 Subject: =?UTF-8?q?=E2=80=A2=20added=20to=20Editor=20Preferences:=20-=20"Q?= =?UTF-8?q?uery=20Background"=20color=20-=20checkbox=20"Highlight=20Curren?= =?UTF-8?q?t=20Query"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CustomQuery.h | 1 + Source/CustomQuery.m | 23 +++++++++++++++++++---- Source/SPPreferenceController.m | 1 + 3 files changed, 21 insertions(+), 4 deletions(-) (limited to 'Source') diff --git a/Source/CustomQuery.h b/Source/CustomQuery.h index 87f739ae..0be5dc0d 100644 --- a/Source/CustomQuery.h +++ b/Source/CustomQuery.h @@ -80,6 +80,7 @@ NSString *usedQuery; NSRange currentQueryRange; NSArray *currentQueryRanges; + BOOL hasBackgroundAttribute; NSString *mySQLversion; int queryStartPosition; diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index 099757a4..4d1d684d 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -906,6 +906,8 @@ queryFavorites = [[NSMutableArray array] retain]; } + hasBackgroundAttribute = NO; + // Set up the interface // Bind backgroundColor [textView setAllowsDocumentBackgroundColorChange:YES]; @@ -933,6 +935,7 @@ [autouppercaseKeywordsMenuItem setState:([prefs boolForKey:@"CustomQueryAutoUppercaseKeywords"]?NSOnState:NSOffState)]; [textView setAutouppercaseKeywords:[prefs boolForKey:@"CustomQueryAutoUppercaseKeywords"]]; [queryFavoritesView registerForDraggedTypes:[NSArray arrayWithObjects:@"SequelProPasteboard", nil]]; + while ( (column = [enumerator nextObject]) ) { if ( [prefs boolForKey:@"UseMonospacedFonts"] ) { @@ -1264,8 +1267,16 @@ // Ensure that the notification is from the custom query text view if ( [aNotification object] != textView ) return; - // Remove all background color attributes - [[textView textStorage] removeAttribute:NSBackgroundColorAttributeName range:NSMakeRange(0,[[textView string] length])]; + // Remove all background color attributes for highlighting the current query + if([prefs boolForKey:@"CustomQueryHighlightCurrentQuery"]) { + [[textView textStorage] removeAttribute:NSBackgroundColorAttributeName range:NSMakeRange(0,[[textView string] length])]; + } else { + // ensure that we do it only once + if(hasBackgroundAttribute) { + [[textView textStorage] removeAttribute:NSBackgroundColorAttributeName range:NSMakeRange(0,[[textView string] length])]; + hasBackgroundAttribute = NO; + } + } BOOL isLookBehind = YES; NSRange currentSelection = [textView selectedRange]; @@ -1275,10 +1286,14 @@ // Highlight by setting a background color the current query // if nothing is selected if(qRange.length && !currentSelection.length) { - [[textView textStorage] addAttribute: NSBackgroundColorAttributeName - value: [NSColor colorWithDeviceRed:0.95 green:0.95 blue:0.95 alpha:1] + if([prefs boolForKey:@"CustomQueryHighlightCurrentQuery"]) { + [[textView textStorage] addAttribute: NSBackgroundColorAttributeName + value: [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:@"CustomQueryEditorHighlightQueryColor"]] range: qRange ]; + hasBackgroundAttribute = YES; + } currentQueryRange = qRange; + } else { currentQueryRange = NSMakeRange(0, 0); } diff --git a/Source/SPPreferenceController.m b/Source/SPPreferenceController.m index b6395c3c..0d77a63f 100644 --- a/Source/SPPreferenceController.m +++ b/Source/SPPreferenceController.m @@ -820,6 +820,7 @@ [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithDeviceRed:0.000 green:0.000 blue:0.658 alpha:1.000]] forKey:@"CustomQueryEditorBacktickColor"]; [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithDeviceRed:0.506 green:0.263 blue:0.000 alpha:1.000]] forKey:@"CustomQueryEditorNumericColor"]; [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithDeviceRed:0.500 green:0.500 blue:0.500 alpha:1.000]] forKey:@"CustomQueryEditorVariableColor"]; + [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithDeviceRed:0.950 green:0.950 blue:0.950 alpha:1.000]] forKey:@"CustomQueryEditorHighlightQueryColor"]; [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor blackColor]] forKey:@"CustomQueryEditorTextColor"]; [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor blackColor]] forKey:@"CustomQueryEditorCaretColor"]; [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor whiteColor]] forKey:@"CustomQueryEditorBackgroundColor"]; -- cgit v1.2.3