root/lang/objective-c/TerminalColoreopard/TCLPreferences.m

Revision 29289, 1.3 kB (checked in by niw, 3 years ago)
  • FIX: memory bugs
Line 
1#import "TCLPreferences.h"
2#import "NSUserDefaults.h"
3
4@implementation TCLPreferences
5+(TCLPreferences*) sharedInstance
6{
7        static TCLPreferences* pref = nil;
8        if (pref == nil) {
9                pref = [[TCLPreferences alloc] init];
10        }
11        return pref;
12}
13
14-(void)dealloc
15{
16        [super dealloc];
17}
18
19-(id) init
20{
21        self = [super init];
22
23        // We should create the ansiColors BEFORE load the NIB
24        NSDictionary *dict = [[NSUserDefaults standardUserDefaults] colorsDictionaryForKey:USER_DEFAULTS_KEY];
25        if(dict != nil) {
26                ansiColors = [TCLANSIColors fromDictionary:dict];
27        } else {
28                ansiColors = [TCLANSIColors defaultANSIColors];
29                [[NSUserDefaults standardUserDefaults] setColorsWithDictionary:[ansiColors ansiColorsAsDictionary] forKey:USER_DEFAULTS_KEY];
30        }
31
32        [NSBundle loadNibNamed:@"TCLPreferences.nib" owner:self];
33        return self;
34}
35
36-(void) awakeFromNib
37{
38        NSMenu* applicationMenu = [[[[NSApplication sharedApplication] mainMenu] itemAtIndex: 0] submenu];
39        for (NSMenuItem* menuItem in [terminalMenuAdditions itemArray]) {
40                [terminalMenuAdditions removeItem:menuItem];
41                [applicationMenu insertItem:menuItem atIndex:3];
42        }
43}
44
45-(TCLANSIColors*) ansiColors
46{
47        return ansiColors;
48}
49
50-(IBAction) apply:(id)sender
51{
52        [[NSUserDefaults standardUserDefaults] setColorsWithDictionary:[ansiColors ansiColorsAsDictionary] forKey:USER_DEFAULTS_KEY];
53}
54@end
Note: See TracBrowser for help on using the browser.