mirror of
https://github.com/gnustep/apps-projectcenter.git
synced 2025-02-15 16:11:25 +00:00
Direct preferences method for setting and getting colors
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/projectcenter/trunk@38424 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
56f365b1a0
commit
ea33c39542
3 changed files with 83 additions and 1 deletions
|
@ -1,3 +1,9 @@
|
|||
2015-03-22 Riccardo Mottola <rm@gnu.org>
|
||||
|
||||
* Headers/Protocols/Preferences.h
|
||||
* PCPrefController.m
|
||||
Direct preferences method for setting and getting colors.
|
||||
|
||||
2015-03-22 Riccardo Mottola <rm@gnu.org>
|
||||
|
||||
* Modules/Preferences/EditorFSC/PCEditorFSCPrefs.m
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
@protocol PCPreferences <NSObject>
|
||||
|
||||
- (NSColor *)colorFromString:(NSString *)colorString;
|
||||
- (NSString *)stringFromColor:(NSColor *)color;
|
||||
|
||||
- (NSString *)stringForKey:(NSString *)key;
|
||||
- (NSString *)stringForKey:(NSString *)key
|
||||
|
@ -47,6 +48,10 @@
|
|||
- (float)floatForKey:(NSString *)key
|
||||
defaultValue:(float)defaultValue;
|
||||
|
||||
- (NSColor *)colorForKey:(NSString *)key;
|
||||
- (NSColor *)colorForKey:(NSString *)key
|
||||
defaultValue:(NSColor *)defaultValue;
|
||||
|
||||
- (void)setString:(NSString *)stringValue
|
||||
forKey:(NSString *)aKey
|
||||
notify:(BOOL)notify;
|
||||
|
@ -56,7 +61,9 @@
|
|||
- (void)setFloat:(float)floatValue
|
||||
forKey:(NSString *)aKey
|
||||
notify:(BOOL)notify;
|
||||
|
||||
- (void)setColor:(NSColor *)color
|
||||
forKey:(NSString *)aKey
|
||||
notify:(BOOL)notify;
|
||||
@end
|
||||
|
||||
@protocol PCPrefsSection <NSObject>
|
||||
|
|
|
@ -103,6 +103,30 @@ static PCPrefController *_prefCtrllr = nil;
|
|||
return color;
|
||||
}
|
||||
|
||||
- (NSString *)stringFromColor:(NSColor *)color
|
||||
{
|
||||
NSString *colorString;
|
||||
|
||||
colorString = nil;
|
||||
if ([[color colorSpaceName] isEqualToString:NSCalibratedWhiteColorSpace])
|
||||
{
|
||||
colorString = [NSString stringWithFormat:@"White %0.1f",
|
||||
[color whiteComponent]];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (![[color colorSpaceName] isEqualToString:NSCalibratedRGBColorSpace])
|
||||
color = [color colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
|
||||
colorString = [NSString stringWithFormat:@"RGB %0.1f %0.1f %0.1f",
|
||||
[color redComponent],
|
||||
[color greenComponent],
|
||||
[color blueComponent]];
|
||||
}
|
||||
|
||||
NSLog(@"serialized color: '%@'", colorString);
|
||||
return colorString;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// --- Accessors
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -176,6 +200,33 @@ static PCPrefController *_prefCtrllr = nil;
|
|||
}
|
||||
}
|
||||
|
||||
- (NSColor *)colorForKey:(NSString *)key
|
||||
{
|
||||
return [self colorForKey:key defaultValue:nil];
|
||||
}
|
||||
|
||||
- (NSColor *)colorForKey:(NSString *)key
|
||||
defaultValue:(NSColor *)defaultValue
|
||||
{
|
||||
NSString *stringValue = [[NSUserDefaults standardUserDefaults]
|
||||
objectForKey:key];
|
||||
|
||||
if (stringValue)
|
||||
{
|
||||
NSColor *color;
|
||||
|
||||
color = [self colorFromString:stringValue];
|
||||
return color;
|
||||
}
|
||||
else if (defaultValue)
|
||||
{
|
||||
[self setColor:defaultValue forKey:key notify:NO];
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
return defaultValue; // returns nil
|
||||
}
|
||||
|
||||
- (void)setString:(NSString *)stringValue
|
||||
forKey:(NSString *)aKey
|
||||
notify:(BOOL)notify
|
||||
|
@ -225,6 +276,24 @@ static PCPrefController *_prefCtrllr = nil;
|
|||
}
|
||||
}
|
||||
|
||||
- (void)setColor:(NSColor *)color
|
||||
forKey:(NSString *)aKey
|
||||
notify:(BOOL)notify
|
||||
{
|
||||
NSString *stringValue;
|
||||
|
||||
stringValue = [self stringFromColor:color];
|
||||
[[NSUserDefaults standardUserDefaults] setObject:stringValue
|
||||
forKey:aKey];
|
||||
|
||||
if (notify)
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
postNotificationName:PCPreferencesDidChangeNotification
|
||||
object:self];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)loadPrefsSections
|
||||
{
|
||||
PCBundleManager *bundleManager = [[PCBundleManager alloc] init];
|
||||
|
|
Loading…
Reference in a new issue