1#import "AppController.h"
2
3@implementation AppController
4
5+ (void)initialize {
6    /*
7    Initalize executes before the first message to the class is
8    serviced therefore, we get our factory settings registered.
9    Note that we do this here rather than in the Preferences as the
10    Preferences instance is loaded lazily, so the Prefernces class
11    may not be initialized before we need our first default
12    (see applicationShouldOpenUntitledFile).
13    */
14    NSString		*path			= [[NSBundle mainBundle] pathForResource:@"Defaults" ofType:@"plist"];
15    NSDictionary	*defaultValues	= [NSDictionary dictionaryWithContentsOfFile: path];
16   [[NSUserDefaults standardUserDefaults] registerDefaults: defaultValues];
17}
18
19
20- (IBAction)showPreferences:(id)sender {
21    [[self preferences] show:self];
22}
23
24- (Preferences *)preferences {
25    // load preferences lazily
26    if (preferences == nil) {
27        Preferences *p = [[Preferences alloc] init];
28        [self setPreferences:p];
29        [p release];
30    }
31    return preferences;
32}
33- (void)setPreferences:(Preferences *)newPreferences {
34    [newPreferences retain];
35    [preferences release];
36    preferences = newPreferences;
37}
38
39- (void)dealloc {
40    [self setPreferences:nil];
41    [super dealloc];
42}
43
44
45@end
46