1/* All Rights reserved */ 2 3#include <AppKit/AppKit.h> 4#include "GeneralView.h" 5 6 7static GeneralView *singleInstance = nil; 8 9@interface GeneralView (Private) 10 11- (void) initializeFromDefaults; 12 13@end 14 15 16@implementation GeneralView(Private) 17 18- (void) initializeFromDefaults 19{ 20 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 21 NSString *device; 22 int onExit; 23 24 device = [defaults stringForKey: @"Device"]; 25 [deviceField setStringValue: device]; 26 27 onExit = [defaults integerForKey: @"OnExit"]; 28 [exitMatrix selectCellAtRow: onExit column: 0]; 29} 30 31@end 32 33 34@implementation GeneralView 35 36- (id) init 37{ 38 return [self initWithNibName: @"General"]; 39} 40 41- (id) initWithNibName: (NSString *) nibName 42{ 43 if (singleInstance) { 44 [self dealloc]; 45 } else { 46 self = [super init]; 47 48 // We link our view 49 if (![NSBundle loadNibNamed: nibName owner: self]) { 50 NSLog (@"General: Could not load nib \"%@\".", nibName); 51 [self dealloc]; 52 } else { 53 view = [window contentView]; 54 [view retain]; 55 56 // We get our defaults for this panel 57 [self initializeFromDefaults]; 58 59 singleInstance = self; 60 } 61 } 62 return singleInstance; 63} 64 65- (void) dealloc 66{ 67 singleInstance = nil; 68 TEST_RELEASE(view); 69 [super dealloc]; 70} 71 72// access methods 73 74- (NSString *) name 75{ 76 return _(@"General"); 77} 78 79- (NSView *) view 80{ 81 return view; 82} 83 84- (void) saveChanges 85{ 86 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 87 NSString *device = [deviceField stringValue]; 88 [defaults setObject: device?device:@"" forKey: @"Device"]; 89 [defaults setInteger: [exitMatrix selectedRow] forKey: @"OnExit"]; 90} 91 92 93// 94// class methods 95// 96+ (id) singleInstance 97{ 98 if (singleInstance == nil) { 99 singleInstance = [[GeneralView alloc] initWithNibName: @"General"]; 100 } 101 102 return singleInstance; 103} 104 105@end 106