aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/SPColorAdditions.h34
-rw-r--r--Source/SPColorAdditions.m93
-rw-r--r--Source/SPConstants.h2
-rw-r--r--Source/SPConstants.m2
-rw-r--r--Source/SPPreferenceController.h3
-rw-r--r--Source/SPPreferenceController.m261
-rw-r--r--Source/SPTextView.m15
7 files changed, 407 insertions, 3 deletions
diff --git a/Source/SPColorAdditions.h b/Source/SPColorAdditions.h
new file mode 100644
index 00000000..58508f62
--- /dev/null
+++ b/Source/SPColorAdditions.h
@@ -0,0 +1,34 @@
+//
+// $Id$
+//
+// SPColorAdditions.h
+// sequel-pro
+//
+// Created by Hans-Jörg Bibiko on August 16, 2010
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// More info at <http://code.google.com/p/sequel-pro/>
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface NSColor (SPColorAdditions)
+
++ (NSColor *)colorWithRGBHexString:(NSString *)hexString ignoreAlpha:(BOOL)ignoreAlpha;
++ (NSColor *)colorWithRGBHexString:(NSString *)hexString;
+- (NSString *)rgbHexString;
+
+@end
diff --git a/Source/SPColorAdditions.m b/Source/SPColorAdditions.m
new file mode 100644
index 00000000..e2e22c16
--- /dev/null
+++ b/Source/SPColorAdditions.m
@@ -0,0 +1,93 @@
+//
+// $Id$
+//
+// SPColorAdditions.m
+// sequel-pro
+//
+// Created by Hans-Jörg Bibiko on August 16, 2010
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// More info at <http://code.google.com/p/sequel-pro/>
+
+#import "SPColorAdditions.h"
+
+
+@implementation NSColor (SPColorAdditions)
+
+/*
+ * Convert self by using the NSCalibratedRGBColorSpace color space in a NSString
+ * #RRGGBBAA or if the alpha value is zero to #RRGGBB
+ */
+- (NSString *)rgbHexString
+{
+
+ CGFloat red, green, blue, alpha;
+ NSString *redHexValue, *greenHexValue, *blueHexValue, *alphaHexValue;
+ NSColor *aColor = [self colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
+
+ if(aColor) {
+ [aColor getRed:&red green:&green blue:&blue alpha:&alpha];
+ redHexValue = [NSString stringWithFormat:@"%02X", (NSInteger)(red * 255.0f)];
+ greenHexValue = [NSString stringWithFormat:@"%02X", (NSInteger)(green * 255.0f)];
+ blueHexValue = [NSString stringWithFormat:@"%02X", (NSInteger)(blue * 255.0f)];
+ alphaHexValue = [NSString stringWithFormat:@"%02X", (NSInteger)(alpha * 255.0f)];
+ if([alphaHexValue isEqualToString:@"FF"]) alphaHexValue = @"";
+ return [NSString stringWithFormat:@"#%@%@%@%@", redHexValue, greenHexValue, blueHexValue, alphaHexValue];
+ }
+
+ return @"";
+
+}
+
++ (NSColor *)colorWithRGBHexString:(NSString *)hexString
+{
+ return [self colorWithRGBHexString:hexString ignoreAlpha:NO];
+}
+
++ (NSColor *)colorWithRGBHexString:(NSString *)hexString ignoreAlpha:(BOOL)ignoreAlpha
+{
+ NSCharacterSet *hexCharSet = [NSCharacterSet characterSetWithCharactersInString:@"1234567890abcdefABCDEF"];
+ NSString *initHexString = ( [hexString hasPrefix:@"#"] ) ? [hexString substringFromIndex:1] : hexString;
+ if(ignoreAlpha && [initHexString length] == 8)
+ initHexString = [initHexString substringToIndex:6];
+ NSScanner *scanner = [NSScanner scannerWithString:initHexString];
+ NSString *code = nil;
+
+ [scanner scanCharactersFromSet:hexCharSet intoString:&code];
+
+ if( [code length] == 8 ) { // decode colors like #ffee33aa
+ NSUInteger color = 0;
+ scanner = [NSScanner scannerWithString:code];
+ if( ! [scanner scanHexInt:&color] ) return nil;
+ return [self colorWithCalibratedRed:( ( ( color >> 24 ) & 0xff ) / 255. ) green:( ( ( color >> 16 ) & 0xff ) / 255. ) blue:( ( ( color >> 8) & 0xff ) / 255. ) alpha:( ( color & 0xff ) / 255. )];
+ }
+ else if( [code length] == 6 ) { // decode colors like #ffee33
+ NSUInteger color = 0;
+ scanner = [NSScanner scannerWithString:code];
+ if( ! [scanner scanHexInt:&color] ) return nil;
+ return [self colorWithCalibratedRed:( ( ( color >> 16 ) & 0xff ) / 255. ) green:( ( ( color >> 8 ) & 0xff ) / 255. ) blue:( ( color & 0xff ) / 255. ) alpha:1.];
+ }
+ else if( [code length] == 3 ) { // decode short-hand colors like #fe3
+ NSUInteger color = 0;
+ scanner = [NSScanner scannerWithString:code];
+ if( ! [scanner scanHexInt:&color] ) return nil;
+ return [self colorWithCalibratedRed:( ( ( ( ( color >> 8 ) & 0xf ) << 4 ) | ( ( color >> 8 ) & 0xf ) ) / 255. ) green:( ( ( ( ( color >> 4 ) & 0xf ) << 4 ) | ( ( color >> 4 ) & 0xf ) ) / 255. ) blue:( ( ( ( color & 0xf ) << 4 ) | ( color & 0xf ) ) / 255. ) alpha:1.];
+ }
+
+ return nil;
+}
+
+@end
diff --git a/Source/SPConstants.h b/Source/SPConstants.h
index 89f35361..58630aa6 100644
--- a/Source/SPConstants.h
+++ b/Source/SPConstants.h
@@ -222,6 +222,7 @@ extern NSString *SPQueryFavortiesPasteboardDragType;
extern NSString *SPFileExtensionDefault;
extern NSString *SPFileExtensionSQL;
extern NSString *SPBundleFileExtension;
+extern NSString *SPColorThemeFileExtension;
// Filenames
extern NSString *SPHTMLPrintTemplate;
@@ -284,6 +285,7 @@ extern NSString *SPCustomQueryEditorQuoteColor;
extern NSString *SPCustomQueryEditorBacktickColor;
extern NSString *SPCustomQueryEditorVariableColor;
extern NSString *SPCustomQueryEditorHighlightQueryColor;
+extern NSString *SPCustomQueryEditorSelectionColor;
extern NSString *SPCustomQueryAutoIndent;
extern NSString *SPCustomQueryAutoPairCharacters;
extern NSString *SPCustomQueryAutoUppercaseKeywords;
diff --git a/Source/SPConstants.m b/Source/SPConstants.m
index cb5ea82f..f9865eb6 100644
--- a/Source/SPConstants.m
+++ b/Source/SPConstants.m
@@ -46,6 +46,7 @@ NSString *SPContentFilterPasteboardDragType = @"SPContentFilterPasteboard";
NSString *SPFileExtensionDefault = @"spf";
NSString *SPBundleFileExtension = @"spfs";
NSString *SPFileExtensionSQL = @"sql";
+NSString *SPColorThemeFileExtension = @"spTheme";
// Filenames
NSString *SPHTMLPrintTemplate = @"sequel-pro-print-template";
@@ -107,6 +108,7 @@ NSString *SPCustomQueryEditorQuoteColor = @"CustomQueryEditorQuoteColor
NSString *SPCustomQueryEditorBacktickColor = @"CustomQueryEditorBacktickColor";
NSString *SPCustomQueryEditorVariableColor = @"CustomQueryEditorVariableColor";
NSString *SPCustomQueryEditorHighlightQueryColor = @"CustomQueryEditorHighlightQueryColor";
+NSString *SPCustomQueryEditorSelectionColor = @"CustomQueryEditorSelectionColor";
NSString *SPCustomQueryAutoIndent = @"CustomQueryAutoIndent";
NSString *SPCustomQueryAutoPairCharacters = @"CustomQueryAutoPairCharacters";
NSString *SPCustomQueryAutoUppercaseKeywords = @"CustomQueryAutoUppercaseKeywords";
diff --git a/Source/SPPreferenceController.h b/Source/SPPreferenceController.h
index cf9d2cc1..d5e22fd5 100644
--- a/Source/SPPreferenceController.h
+++ b/Source/SPPreferenceController.h
@@ -102,6 +102,9 @@
- (IBAction)sortFavorites:(id)sender;
- (IBAction)reverseFavoritesSortOrder:(id)sender;
- (IBAction)makeSelectedFavoriteDefault:(id)sender;
+- (IBAction)exportColorScheme:(id)sender;
+- (IBAction)importColorScheme:(id)sender;
+
// Toolbar item IBAction methods
- (IBAction)displayGeneralPreferences:(id)sender;
diff --git a/Source/SPPreferenceController.m b/Source/SPPreferenceController.m
index 81fa4af8..e1c77c20 100644
--- a/Source/SPPreferenceController.m
+++ b/Source/SPPreferenceController.m
@@ -29,6 +29,7 @@
#import "SPKeychain.h"
#import "SPDatabaseDocument.h"
#import "SPConnectionController.h"
+#import "SPColorAdditions.h"
@interface SPPreferenceController (PrivateAPI)
@@ -500,6 +501,43 @@
[self updateDefaultFavoritePopup];
}
+- (IBAction)exportColorScheme:(id)sender
+{
+ NSSavePanel *panel = [NSSavePanel savePanel];
+
+ [panel setRequiredFileType:SPColorThemeFileExtension];
+
+ [panel setExtensionHidden:NO];
+ [panel setAllowsOtherFileTypes:NO];
+ [panel setCanSelectHiddenExtension:YES];
+ [panel setCanCreateDirectories:YES];
+
+ [panel beginSheetForDirectory:nil
+ file:[NSString stringWithFormat:@"myTheme.%@", SPColorThemeFileExtension]
+ modalForWindow:[self window]
+ modalDelegate:self
+ didEndSelector:@selector(panelDidEnd:returnCode:contextInfo:)
+ contextInfo:@"exportColorScheme"];
+}
+
+- (IBAction)importColorScheme:(id)sender
+{
+ NSOpenPanel *panel = [NSOpenPanel openPanel];
+ [panel setCanSelectHiddenExtension:YES];
+ [panel setDelegate:self];
+ [panel setCanChooseDirectories:NO];
+ [panel setAllowsMultipleSelection:NO];
+
+ [panel beginSheetForDirectory:nil
+ file:@""
+ types:[NSArray arrayWithObjects:SPColorThemeFileExtension, @"tmTheme", nil]
+ modalForWindow:[self window]
+ modalDelegate:self
+ didEndSelector:@selector(panelDidEnd:returnCode:contextInfo:)
+ contextInfo:@"importColorScheme"];
+
+}
+
#pragma mark -
#pragma mark Toolbar item IBAction methods
@@ -1220,6 +1258,7 @@
[prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithDeviceRed:0.506 green:0.263 blue:0.000 alpha:1.000]] forKey:SPCustomQueryEditorNumericColor];
[prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithDeviceRed:0.500 green:0.500 blue:0.500 alpha:1.000]] forKey:SPCustomQueryEditorVariableColor];
[prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithDeviceRed:0.950 green:0.950 blue:0.950 alpha:1.000]] forKey:SPCustomQueryEditorHighlightQueryColor];
+ [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithDeviceRed:0.7098 green:0.8352 blue:1.000 alpha:1.000]] forKey:SPCustomQueryEditorSelectionColor];
[prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor blackColor]] forKey:SPCustomQueryEditorTextColor];
[prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor blackColor]] forKey:SPCustomQueryEditorCaretColor];
[prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor whiteColor]] forKey:SPCustomQueryEditorBackgroundColor];
@@ -1285,7 +1324,229 @@
return YES;
}
+/**
+ * Save panel did end method.
+ */
+- (void)panelDidEnd:(NSSavePanel *)panel returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo
+{
+
+ if([contextInfo isEqualToString:@"exportColorScheme"]) {
+ if (returnCode == NSOKButton) {
+
+ // Build plist dictionary
+ NSMutableDictionary *scheme = [NSMutableDictionary dictionary];
+ NSMutableDictionary *mainsettings = [NSMutableDictionary dictionary];
+ NSMutableArray *settings = [NSMutableArray array];
+ CGFloat red, green, blue, alpha;
+ NSInteger redInt, greenInt, blueInt, alphaInt;
+ NSString *redHexValue, *greenHexValue, *blueHexValue, *alphaHexValue;
+
+ [prefs synchronize];
+
+ NSColor *aColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorBackgroundColor]];
+ [mainsettings setObject:[aColor rgbHexString] forKey:@"background"];
+
+ aColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorCaretColor]];
+ [mainsettings setObject:[aColor rgbHexString] forKey:@"caret"];
+
+ aColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorTextColor]];
+ [mainsettings setObject:[aColor rgbHexString] forKey:@"foreground"];
+
+ aColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorHighlightQueryColor]];
+ [mainsettings setObject:[aColor rgbHexString] forKey:@"lineHighlight"];
+
+ aColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorSelectionColor]];
+ [mainsettings setObject:[aColor rgbHexString] forKey:@"selection"];
+
+ [settings addObject:[NSDictionary dictionaryWithObjectsAndKeys:mainsettings, @"settings", nil]];
+
+ aColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorCommentColor]];
+ [settings addObject:[NSDictionary dictionaryWithObjectsAndKeys:
+ @"Comment", @"name",
+ [NSDictionary dictionaryWithObjectsAndKeys:
+ [aColor rgbHexString], @"foreground",
+ nil
+ ], @"settings",
+ nil
+ ]];
+
+ aColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorQuoteColor]];
+ [settings addObject:[NSDictionary dictionaryWithObjectsAndKeys:
+ @"String", @"name",
+ [NSDictionary dictionaryWithObjectsAndKeys:
+ [aColor rgbHexString], @"foreground",
+ nil
+ ], @"settings",
+ nil
+ ]];
+
+ aColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorSQLKeywordColor]];
+ [settings addObject:[NSDictionary dictionaryWithObjectsAndKeys:
+ @"Keyword", @"name",
+ [NSDictionary dictionaryWithObjectsAndKeys:
+ [aColor rgbHexString], @"foreground",
+ nil
+ ], @"settings",
+ nil
+ ]];
+
+ aColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorBacktickColor]];
+ [settings addObject:[NSDictionary dictionaryWithObjectsAndKeys:
+ @"User-defined constant", @"name",
+ [NSDictionary dictionaryWithObjectsAndKeys:
+ [aColor rgbHexString], @"foreground",
+ nil
+ ], @"settings",
+ nil
+ ]];
+
+ aColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorNumericColor]];
+ [settings addObject:[NSDictionary dictionaryWithObjectsAndKeys:
+ @"Number", @"name",
+ [NSDictionary dictionaryWithObjectsAndKeys:
+ [aColor rgbHexString], @"foreground",
+ nil
+ ], @"settings",
+ nil
+ ]];
+
+ aColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorVariableColor]];
+ [settings addObject:[NSDictionary dictionaryWithObjectsAndKeys:
+ @"Variable", @"name",
+ [NSDictionary dictionaryWithObjectsAndKeys:
+ [aColor rgbHexString], @"foreground",
+ nil
+ ], @"settings",
+ nil
+ ]];
+
+ [scheme setObject:settings forKey:@"settings"];
+
+ NSString *err = nil;
+ NSData *plist = [NSPropertyListSerialization dataFromPropertyList:scheme
+ format:NSPropertyListXMLFormat_v1_0
+ errorDescription:&err];
+
+ if(err != nil) {
+ NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while converting color scheme data", @"error while converting color scheme data")]
+ defaultButton:NSLocalizedString(@"OK", @"OK button")
+ alternateButton:nil
+ otherButton:nil
+ informativeTextWithFormat:err];
+
+ [alert setAlertStyle:NSCriticalAlertStyle];
+ [alert runModal];
+ return;
+ }
+
+ NSError *error = nil;
+ [plist writeToFile:[panel filename] options:NSAtomicWrite error:&error];
+ if (error) [[NSAlert alertWithError:error] runModal];
+
+ }
+ }
+ else if([contextInfo isEqualToString:@"importColorScheme"]) {
+ if (returnCode == NSOKButton) {
+ NSString *filename = [[panel filenames] objectAtIndex:0];
+ NSError *readError = nil;
+ NSString *convError = nil;
+ NSPropertyListFormat format;
+
+ NSDictionary *theme = nil;
+
+ NSData *pData = [NSData dataWithContentsOfFile:filename options:NSUncachedRead error:&readError];
+
+ theme = [[NSPropertyListSerialization propertyListFromData:pData
+ mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError] retain];
+
+ if(!theme || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) {
+ NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while reading data file", @"error while reading data file")]
+ defaultButton:NSLocalizedString(@"OK", @"OK button")
+ alternateButton:nil
+ otherButton:nil
+ informativeTextWithFormat:NSLocalizedString(@"File couldn't be read.", @"error while reading data file")];
+
+ [alert setAlertStyle:NSCriticalAlertStyle];
+ [alert runModal];
+ if (theme) [theme release];
+ return;
+ }
+
+ if([theme objectForKey:@"settings"]
+ && [[theme objectForKey:@"settings"] isKindOfClass:[NSArray class]]
+ && [[theme objectForKey:@"settings"] count]
+ && [[[theme objectForKey:@"settings"] objectAtIndex:0] isKindOfClass:[NSDictionary class]]
+ && [[[theme objectForKey:@"settings"] objectAtIndex:0] objectForKey:@"settings"]) {
+
+ NSInteger counter = 0;
+ for(NSDictionary *dict in [theme objectForKey:@"settings"]) {
+ if(counter == 0) {
+ if([dict objectForKey:@"settings"]) {
+ NSDictionary *dic = [dict objectForKey:@"settings"];
+ if([dic objectForKey:@"background"])
+ [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithRGBHexString:[dic objectForKey:@"background"]]] forKey:SPCustomQueryEditorBackgroundColor];
+ if([dic objectForKey:@"caret"])
+ [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithRGBHexString:[dic objectForKey:@"caret"]]] forKey:SPCustomQueryEditorCaretColor];
+ if([dic objectForKey:@"foreground"])
+ [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithRGBHexString:[dic objectForKey:@"foreground"]]] forKey:SPCustomQueryEditorTextColor];
+ if([dic objectForKey:@"lineHighlight"])
+ [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithRGBHexString:[dic objectForKey:@"lineHighlight"]]] forKey:SPCustomQueryEditorHighlightQueryColor];
+ if([dic objectForKey:@"selection"])
+ [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithRGBHexString:[dic objectForKey:@"selection"]]] forKey:SPCustomQueryEditorSelectionColor];
+ } else {
+ continue;
+ }
+ } else {
+ if([dict objectForKey:@"name"] && [dict objectForKey:@"settings"] && [[dict objectForKey:@"settings"] isKindOfClass:[NSDictionary class]] && [[dict objectForKey:@"settings"] objectForKey:@"foreground"]) {
+ if([[dict objectForKey:@"name"] isEqualToString:@"Comment"])
+ [prefs setObject:[NSArchiver archivedDataWithRootObject:
+ [NSColor colorWithRGBHexString:[[dict objectForKey:@"settings"] objectForKey:@"foreground"]]]
+ forKey:SPCustomQueryEditorCommentColor];
+ else if([[dict objectForKey:@"name"] isEqualToString:@"String"])
+ [prefs setObject:[NSArchiver archivedDataWithRootObject:
+ [NSColor colorWithRGBHexString:[[dict objectForKey:@"settings"] objectForKey:@"foreground"]]]
+ forKey:SPCustomQueryEditorQuoteColor];
+ else if([[dict objectForKey:@"name"] isEqualToString:@"Keyword"])
+ [prefs setObject:[NSArchiver archivedDataWithRootObject:
+ [NSColor colorWithRGBHexString:[[dict objectForKey:@"settings"] objectForKey:@"foreground"]]]
+ forKey:SPCustomQueryEditorSQLKeywordColor];
+ else if([[dict objectForKey:@"name"] isEqualToString:@"User-defined constant"])
+ [prefs setObject:[NSArchiver archivedDataWithRootObject:
+ [NSColor colorWithRGBHexString:[[dict objectForKey:@"settings"] objectForKey:@"foreground"]]]
+ forKey:SPCustomQueryEditorBacktickColor];
+ else if([[dict objectForKey:@"name"] isEqualToString:@"Number"])
+ [prefs setObject:[NSArchiver archivedDataWithRootObject:
+ [NSColor colorWithRGBHexString:[[dict objectForKey:@"settings"] objectForKey:@"foreground"]]]
+ forKey:SPCustomQueryEditorNumericColor];
+ else if([[dict objectForKey:@"name"] isEqualToString:@"Variable"])
+ [prefs setObject:[NSArchiver archivedDataWithRootObject:
+ [NSColor colorWithRGBHexString:[[dict objectForKey:@"settings"] objectForKey:@"foreground"]]]
+ forKey:SPCustomQueryEditorVariableColor];
+ }
+ }
+ counter++;
+ }
+
+ [theme release];
+
+ } else {
+
+ NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while reading data file", @"error while reading data file")]
+ defaultButton:NSLocalizedString(@"OK", @"OK button")
+ alternateButton:nil
+ otherButton:nil
+ informativeTextWithFormat:NSLocalizedString(@"No color theme data found.", @"error that no color theme found")];
+
+ [alert setAlertStyle:NSInformationalAlertStyle];
+ [alert runModal];
+ [theme release];
+ return;
+
+ }
+ }
+ }
+}
#pragma mark -
/**
diff --git a/Source/SPTextView.m b/Source/SPTextView.m
index a8ba29c8..9501992a 100644
--- a/Source/SPTextView.m
+++ b/Source/SPTextView.m
@@ -168,11 +168,14 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
[self setNumericColor:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorNumericColor]]];
[self setVariableColor:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorVariableColor]]];
[self setOtherTextColor:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorTextColor]]];
- [self setTextColor:[self otherTextColor]];
- [self setInsertionPointColor:[self otherTextColor]];
+ [self setTextColor:otherTextColor];
+ [self setInsertionPointColor:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorCaretColor]]];
[self setShouldHiliteQuery:[prefs boolForKey:SPCustomQueryHighlightCurrentQuery]];
+ [self setSelectedTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorSelectionColor]], NSBackgroundColorAttributeName, nil]];
// Register observers for the when editor background colors preference changes
+ [prefs addObserver:self forKeyPath:SPCustomQueryEditorSelectionColor options:NSKeyValueObservingOptionNew context:NULL];
+ [prefs addObserver:self forKeyPath:SPCustomQueryEditorCaretColor options:NSKeyValueObservingOptionNew context:NULL];
[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];
@@ -209,6 +212,12 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
} else if ([keyPath isEqualToString:SPCustomQueryEditorHighlightQueryColor]) {
[self setQueryHiliteColor:[NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]]];
[self setNeedsDisplay:YES];
+ } else if ([keyPath isEqualToString:SPCustomQueryEditorCaretColor]) {
+ [self setInsertionPointColor:[NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]]];
+ [self setNeedsDisplay:YES];
+ } else if ([keyPath isEqualToString:SPCustomQueryEditorSelectionColor]) {
+ [self setSelectedTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]], NSBackgroundColorAttributeName, nil]];
+ [self setNeedsDisplay:YES];
} else if ([keyPath isEqualToString:SPCustomQueryHighlightCurrentQuery]) {
[self setShouldHiliteQuery:[[change objectForKey:NSKeyValueChangeNewKey] boolValue]];
[self setNeedsDisplay:YES];
@@ -2743,7 +2752,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
inTextContainer: [self textContainer]
rectCount: &rectCount ];
[[self queryHiliteColor] setFill];
- NSRectFillList(queryRects, rectCount);
+ NSRectFillListUsingOperation(queryRects, rectCount, NSCompositeSourceOver);
}
// Highlight snippets coming from the Query Favorite text macro