1#import "Preferences.h"
2
3@implementation Preferences
4
5NSString *DefaultDriverKey = @"DefaultDriver";
6
7static NSString *nibName = @"Preferences";
8
9- (IBAction)update:(id)sender {
10    // provide a single update action method for all defaults
11    // it's a lot easier than setting each indvidually...
12    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
13    [defaults setObject: [defaultDriverField stringValue] forKey: DefaultDriverKey];
14 }
15
16- (void)windowDidResignKey:(NSNotification *)n {
17    // make sure defaults are saved automatically after edits
18    [self update: self];
19}
20
21- (void)windowDidClose:(NSNotification *)n {
22    // make sure defaults are saved automatically when window closed
23    [self update: self];
24}
25
26- (IBAction)show:(id)sender
27{
28    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
29    if (!panel) {
30        if (![NSBundle loadNibNamed: nibName owner: self])
31            NSLog(@"Unable to load nib \"%@\"",nibName);
32    }
33    [defaultDriverField setStringValue: [defaults objectForKey: DefaultDriverKey]];
34    [panel makeKeyAndOrderFront: self];
35}
36
37@end
38