aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/SPFavoriteColorSupport.h7
-rw-r--r--Source/SPFavoriteColorSupport.m26
2 files changed, 20 insertions, 13 deletions
diff --git a/Source/SPFavoriteColorSupport.h b/Source/SPFavoriteColorSupport.h
index ad35b80d..0d690922 100644
--- a/Source/SPFavoriteColorSupport.h
+++ b/Source/SPFavoriteColorSupport.h
@@ -32,7 +32,8 @@
#import <Foundation/Foundation.h>
-@interface SPFavoriteColorSupport : NSObject {
+@interface SPFavoriteColorSupport : NSObject
+{
NSUserDefaults *prefs;
}
@@ -43,19 +44,23 @@
/**
* Get the default list of colors supplied by Sequel Pro.
+ *
* @return An array with NSColor * items.
*/
+ (NSArray *)defaultColorList;
/**
* Get the current color for a specific index.
+ *
* @return The color or nil if colorIndex was < 0 or the index was not defined.
*/
- (NSColor *)colorForIndex:(NSInteger)colorIndex;
/**
* The current list of colors from user prefs.
+ *
* @return An array with NSColor * items.
*/
- (NSArray *)userColorList;
+
@end
diff --git a/Source/SPFavoriteColorSupport.m b/Source/SPFavoriteColorSupport.m
index 10519791..0c10ef28 100644
--- a/Source/SPFavoriteColorSupport.m
+++ b/Source/SPFavoriteColorSupport.m
@@ -34,23 +34,24 @@
@implementation SPFavoriteColorSupport
-static SPFavoriteColorSupport *ColorSupport = nil;
+static SPFavoriteColorSupport *_colorSupport = nil;
- (id)init
{
- self = [super init];
- if (self) {
+ if ((self = [super init])) {
prefs = [NSUserDefaults standardUserDefaults];
}
+
return self;
}
+ (SPFavoriteColorSupport *)sharedInstance
{
- if(!ColorSupport)
- ColorSupport = [[self allocWithZone:NULL] init];
+ if (!_colorSupport) {
+ _colorSupport = [[self allocWithZone:NULL] init];
+ }
- return ColorSupport;
+ return _colorSupport;
}
@@ -67,26 +68,27 @@ static SPFavoriteColorSupport *ColorSupport = nil;
nil];
}
-
- (NSColor *)colorForIndex:(NSInteger)colorIndex
{
NSArray *colorList = [self userColorList];
- //check bounds
- if(colorIndex < 0 || (NSUInteger)colorIndex >= [colorList count]) {
- NSLog(@"%s: Requesting color index %ld, but only have %lu items. Returning nil.",__PRETTY_FUNCTION__,(long)colorIndex,(unsigned long)[colorList count]);
+
+ // Check bounds
+ if (colorIndex < 0 || (NSUInteger)colorIndex >= [colorList count]) {
return nil;
}
return [colorList objectAtIndex:colorIndex];
}
-
- (NSArray *)userColorList
{
NSArray *archivedColors = [prefs objectForKey:SPFavoriteColorList];
NSMutableArray *colorList = [NSMutableArray arrayWithCapacity:[archivedColors count]];
- for (NSData *archivedColor in archivedColors) {
+
+ for (NSData *archivedColor in archivedColors)
+ {
NSColor *color = [NSUnarchiver unarchiveObjectWithData:archivedColor];
+
[colorList addObject:color];
}