apps-gorm/GormPrefs/GormGuidelinePref.m
Gregory John Casamento 17ec30efb2 Fixes bug#13753: User should now be able to change the color of the guideline from the guideline preferences.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@38356 72102866-910b-0410-8b05-ffd578937521
2015-02-23 02:23:29 +00:00

82 lines
1.8 KiB
Objective-C

#include "GormGuidelinePref.h"
#include <GormCore/GormFunctions.h>
#include <Foundation/NSUserDefaults.h>
#include <AppKit/NSWindow.h>
#include <AppKit/NSNibLoading.h>
#include <AppKit/NSColorWell.h>
#include <AppKit/NSColor.h>
@implementation GormGuidelinePref
- (id) init
{
if((self = [super init]) != nil)
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
int spacing = [defaults integerForKey: @"GuideSpacing"];
NSColor *aColor = colorFromDict([defaults objectForKey: @"GuideColor"]);
// default the color to something, if nothing is returned.
if(aColor == nil)
{
aColor = [NSColor redColor];
}
if ( [NSBundle loadNibNamed:@"GormPrefGuideline" owner:self] == NO )
{
NSLog(@"Can not load bundle GormPrefGuideline");
return nil;
}
[colorWell setColor: aColor];
[spacingSlider setIntValue: spacing];
[currentSpacing setIntValue: spacing];
[halfSpacing setIntValue: spacing/2];
_view = [[window contentView] retain];
}
return self;
}
- (void) dealloc
{
TEST_RELEASE(_view);
[super dealloc];
}
-(NSView *) view
{
return _view;
}
- (void) ok: (id)sender
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if(sender == spacingSlider)
{
int spacing = [spacingSlider intValue];
[currentSpacing setIntValue: spacing];
[halfSpacing setIntValue: spacing/2];
[defaults setInteger: spacing
forKey: @"GuideSpacing"];
}
else if(sender == colorWell)
{
NSColor *color = [colorWell color];
[defaults setObject: colorToDict(color)
forKey: @"GuideColor"];
}
}
- (void) reset: (id)sender
{
[spacingSlider setIntValue: 10];
[colorWell setColor: [NSColor redColor]];
[self ok: spacingSlider];
[self ok: colorWell];
}
@end