Re: NSColorWell and bindings
Re: NSColorWell and bindings
- Subject: Re: NSColorWell and bindings
- From: Lorenzo Thurman <email@hidden>
- Date: Sun, 14 Jun 2009 00:16:37 -0500
The link to storing NSColor in defaults was helpful. It reinforced what I
thought I already knew, but it appears that real problem was storing a
system color, [NSColor selectedMenuItemColor], instead of a color constant
such as [NSColor blueColor]. I created a simple project just to help
troubleshoot the issue. Here is the code if anyone wants to take a look.
you'll need window with an NSColorWell bound to NSUserDefaults
"values.textColor". If anyone can provide some insight as to why I can't use
[NSColor selectedMenuItemColor] as it should just return an NSColor which
should be suitable for the colorwell, I'd appreciate it. One thing I did
notice in gdb is that when I print the color's description, I get this for
selectedMenuItemColor:
*NSNamedColorSpace System selectedMenuItemColor*
*But for blueColor, I get this:*
**
*
NSCalibratedRGBColorSpace 0 0 1 1
But I would think that any NSColor should work just fine.
*
Thanks
@implementation ColorBindings
+(void)initialize{
NSMutableDictionary *defaults = [NSMutableDictionary dictionary];
NSColor * color = [NSColor selectedMenuItemColor];
[defaults setObject:[NSArchiver archivedDataWithRootObject:color] forKey:
@"textColor"];
[[NSUserDefaultsController sharedUserDefaultsController] setInitialValues
:defaults];
[[NSUserDefaultsController sharedUserDefaultsController]
setAppliesImmediately:YES];
}
-(id)init{
return (self = [super init]);
}
-(IBAction)changeTextColor:(id)sender{
[self setTextColor:[sender color]];
NSData * colorData = [NSArchiver archivedDataWithRootObject:[self textColor
]];
[[[NSUserDefaultsController sharedUserDefaultsController] values]
setValue:colorData
forKey:@"textColor"];
[[[NSUserDefaultsController sharedUserDefaultsController] defaults]
synchronize];
}
-(void)setTextColor:(NSColor *)newColor{
if(textColor != newColor){
[textColor release];
textColor = [newColor retain];
}
}
-(NSColor *) textColor{
return textColor;
}
@end
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden