1//
2//  PXGridSettingsPrompter.m
3//  Pixen-XCode
4//
5//  Created by Andy Matuschak on Thu Mar 18 2004.
6//  Copyright (c) 2004 Open Sword Group. All rights reserved.
7//
8
9#import "PXGridSettingsPrompter.h"
10
11
12@implementation PXGridSettingsPrompter
13
14- initWithSize:(NSSize)aSize color:aColor shouldDraw:(BOOL)newShouldDraw;
15{
16    [super initWithWindowNibName:@"PXGridSettingsPrompter"];
17	unitSize = aSize;
18	color = aColor;
19	shouldDraw = newShouldDraw;
20	return self;
21}
22
23- (void)setDelegate:newDelegate
24{
25    delegate = newDelegate;
26}
27
28- (void)prompt
29{
30	[self showWindow:self];
31	[[sizeForm cellAtIndex:0] setIntValue:unitSize.width];
32	[[sizeForm cellAtIndex:1] setIntValue:unitSize.height];
33	[colorWell setColor:color];
34	[shouldDrawCheckBox setState:(shouldDraw) ? NSOnState : NSOffState];
35	[self update:self];
36}
37
38- (IBAction)update:sender
39{
40	if ([shouldDrawCheckBox state] == NSOnState) {
41		[sizeForm setEnabled:YES];
42		[colorWell setEnabled:YES];
43		[sizeLabel setEnabled:YES];
44		[colorLabel setEnabled:YES];
45	} else {
46		[sizeForm setEnabled:NO];
47		[colorWell setEnabled:NO];
48		[sizeLabel setEnabled:NO];
49		[colorLabel setEnabled:NO];
50	}
51    [delegate gridSettingsPrompter:self updatedWithSize:NSMakeSize([[sizeForm cellAtIndex:0] intValue], [[sizeForm cellAtIndex:1] intValue]) color:[colorWell color] shouldDraw:([shouldDrawCheckBox state] == NSOnState) ? YES : NO];
52}
53
54- (IBAction)useAsDefaults:sender
55{
56	id defaults = [NSUserDefaults standardUserDefaults];
57	[defaults setBool:([shouldDrawCheckBox state] == NSOnState) forKey:@"PXGridShouldDraw"];
58	[defaults setFloat:[[sizeForm cellAtIndex:0] intValue] forKey:@"PXGridUnitWidth"];
59	[defaults setFloat:[[sizeForm cellAtIndex:1] intValue] forKey:@"PXGridUnitHeight"];
60	[defaults setObject:[NSKeyedArchiver archivedDataWithRootObject:[colorWell color]] forKey:@"PXGridColorData"];
61	[self update:self];
62}
63
64@end
65