2001-10-19 19:41:13 +00:00
|
|
|
|
#import "PrefsWindowController.h"
|
|
|
|
|
|
|
|
|
|
@implementation PrefsWindowController
|
|
|
|
|
|
|
|
|
|
- (id)init
|
|
|
|
|
{
|
2008-07-31 20:27:55 +00:00
|
|
|
|
return [self initWithWindowNibName:@"PrefsWindow"];
|
2001-10-19 19:41:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-02-11 01:22:17 +00:00
|
|
|
|
- (void)dealloc
|
|
|
|
|
{
|
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
|
|
|
[super dealloc];
|
|
|
|
|
}
|
|
|
|
|
|
2001-10-19 19:41:13 +00:00
|
|
|
|
- (void)awakeFromNib
|
2002-02-11 01:22:17 +00:00
|
|
|
|
{
|
|
|
|
|
// represent current prefs in window state
|
|
|
|
|
[self updatePrefs:nil];
|
2008-07-31 20:27:55 +00:00
|
|
|
|
[[self window] center];
|
2002-02-11 01:22:17 +00:00
|
|
|
|
|
|
|
|
|
// listen out for pref changes from elsewhere
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updatePrefs:) name:NSUserDefaultsDidChangeNotification object:nil];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)updatePrefs:(NSNotification *)notification
|
2001-10-19 19:41:13 +00:00
|
|
|
|
{
|
|
|
|
|
// load preferences<EFBFBD>
|
2002-02-23 03:40:24 +00:00
|
|
|
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
2001-10-19 19:41:13 +00:00
|
|
|
|
BOOL preserveBackups = [defaults boolForKey:@"PreserveBackups"];
|
|
|
|
|
BOOL autosave = [defaults boolForKey:@"Autosave"];
|
|
|
|
|
int autosaveInterval = [defaults integerForKey:@"AutosaveInterval"];
|
|
|
|
|
BOOL deleteResourceWarning = [defaults boolForKey:@"DeleteResourceWarning"];
|
2002-02-23 03:40:24 +00:00
|
|
|
|
BOOL createNewDocument = [[defaults stringForKey:@"LaunchAction"] isEqualToString:@"OpenUntitledFile"];
|
|
|
|
|
BOOL displayOpenPanel = [[defaults stringForKey:@"LaunchAction"] isEqualToString:@"DisplayOpenPanel"];
|
|
|
|
|
int launchAction = createNewDocument? 1:(displayOpenPanel? 2:0);
|
2001-10-19 19:41:13 +00:00
|
|
|
|
|
|
|
|
|
// <EFBFBD>and set widgets accordingly
|
|
|
|
|
[[dataProtectionMatrix cellAtRow:preserveBackupsBox column:0] setState:preserveBackups];
|
|
|
|
|
[[dataProtectionMatrix cellAtRow:autosaveBox column:0] setState:autosave];
|
|
|
|
|
[autosaveIntervalField setStringValue:[NSString stringWithFormat:@"%d", autosaveInterval]];
|
|
|
|
|
[[dataProtectionMatrix cellAtRow:deleteResourceWarningBox column:0] setState:deleteResourceWarning];
|
2002-02-23 03:40:24 +00:00
|
|
|
|
[launchActionMatrix selectCellAtRow:launchAction column:0];
|
2002-02-11 01:22:17 +00:00
|
|
|
|
}
|
2001-10-19 19:41:13 +00:00
|
|
|
|
|
|
|
|
|
- (IBAction)acceptPrefs:(id)sender
|
|
|
|
|
{
|
2002-02-02 11:31:28 +00:00
|
|
|
|
// bug: hey! where's NSValue's boolValue method? I have to use "intValue? YES:NO" :(
|
2002-02-23 03:40:24 +00:00
|
|
|
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
2001-10-19 19:41:13 +00:00
|
|
|
|
BOOL preserveBackups = [[dataProtectionMatrix cellAtRow:preserveBackupsBox column:0] intValue]? YES:NO;
|
|
|
|
|
BOOL autosave = [[dataProtectionMatrix cellAtRow:autosaveBox column:0] intValue]? YES:NO;
|
|
|
|
|
int autosaveInterval = [autosaveIntervalField intValue];
|
|
|
|
|
BOOL deleteResourceWarning = [[dataProtectionMatrix cellAtRow:deleteResourceWarningBox column:0] intValue]? YES:NO;
|
2002-02-12 04:01:47 +00:00
|
|
|
|
BOOL createNewDocument = ([launchActionMatrix selectedRow] == createNewDocumentBox)? YES:NO;
|
2002-02-23 03:40:24 +00:00
|
|
|
|
BOOL displayOpenPanel = ([launchActionMatrix selectedRow] == displayOpenPanelBox)? YES:NO;
|
2001-10-19 19:41:13 +00:00
|
|
|
|
|
|
|
|
|
// hide the window
|
|
|
|
|
[[self window] orderOut:nil];
|
|
|
|
|
|
|
|
|
|
// now save the data to the defaults file
|
2002-02-02 11:31:28 +00:00
|
|
|
|
[defaults setBool:preserveBackups forKey:@"PreserveBackups"]; // bug: this puts 1 or 0 into the defaults file rather than YES or NO
|
2001-10-19 19:41:13 +00:00
|
|
|
|
[defaults setBool:autosave forKey:@"Autosave"];
|
|
|
|
|
[defaults setInteger:autosaveInterval forKey:@"AutosaveInterval"];
|
|
|
|
|
[defaults setBool:deleteResourceWarning forKey:@"DeleteResourceWarning"];
|
2008-07-31 20:27:55 +00:00
|
|
|
|
if(createNewDocument) [defaults setObject:@"OpenUntitledFile" forKey:@"LaunchAction"];
|
|
|
|
|
else if(displayOpenPanel) [defaults setObject:@"DisplayOpenPanel" forKey:@"LaunchAction"];
|
2002-02-23 03:40:24 +00:00
|
|
|
|
else [defaults setObject:@"None" forKey:@"LaunchAction"];
|
2001-10-19 19:41:13 +00:00
|
|
|
|
[defaults synchronize];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (IBAction)cancelPrefs:(id)sender
|
|
|
|
|
{
|
|
|
|
|
// hide the window
|
|
|
|
|
[[self window] orderOut:nil];
|
|
|
|
|
|
2002-02-12 04:01:47 +00:00
|
|
|
|
// reset widgets to saved values
|
|
|
|
|
[self updatePrefs:nil];
|
2001-10-19 19:41:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (IBAction)resetToDefault:(id)sender
|
|
|
|
|
{
|
|
|
|
|
// reset prefs window widgets to values stored in defaults.plist file
|
|
|
|
|
NSDictionary *defaultsPlist = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"defaults" ofType:@"plist"]];
|
|
|
|
|
BOOL preserveBackups = [[defaultsPlist objectForKey:@"PreserveBackups"] intValue]? YES:NO; // bug: this always evaluates to NO, even if the object in the dictionary is YES
|
|
|
|
|
BOOL autosave = [[defaultsPlist objectForKey:@"Autosave"] intValue]? YES:NO;
|
|
|
|
|
int autosaveInterval = [[defaultsPlist objectForKey:@"AutosaveInterval"] intValue];
|
|
|
|
|
BOOL deleteResourceWarning = [[defaultsPlist objectForKey:@"DeleteResourceWarning"] intValue]? YES:NO;
|
2002-02-23 03:40:24 +00:00
|
|
|
|
BOOL createNewDocument = [[defaultsPlist objectForKey:@"LaunchAction"] isEqualToString:@"OpenUntitledFile"];
|
|
|
|
|
BOOL displayOpenPanel = [[defaultsPlist objectForKey:@"LaunchAction"] isEqualToString:@"DisplayOpenPanel"];
|
|
|
|
|
int launchAction = createNewDocument? 1:(displayOpenPanel? 2:0);
|
2001-10-19 19:41:13 +00:00
|
|
|
|
|
2002-02-02 11:31:28 +00:00
|
|
|
|
// note that this function does not modify the user defaults - the user still has to accept or cancel the panel
|
2001-10-19 19:41:13 +00:00
|
|
|
|
[[dataProtectionMatrix cellAtRow:preserveBackupsBox column:0] setState:preserveBackups];
|
|
|
|
|
[[dataProtectionMatrix cellAtRow:autosaveBox column:0] setState:autosave];
|
|
|
|
|
[autosaveIntervalField setStringValue:[NSString stringWithFormat:@"%d", autosaveInterval]];
|
|
|
|
|
[[dataProtectionMatrix cellAtRow:deleteResourceWarningBox column:0] setState:deleteResourceWarning];
|
2002-02-23 03:40:24 +00:00
|
|
|
|
[launchActionMatrix selectCellAtRow:launchAction column:0];
|
2001-10-19 19:41:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (id)sharedPrefsWindowController
|
|
|
|
|
{
|
|
|
|
|
static PrefsWindowController *sharedPrefsWindowController = nil;
|
|
|
|
|
if( !sharedPrefsWindowController )
|
|
|
|
|
sharedPrefsWindowController = [[PrefsWindowController allocWithZone:[self zone]] init];
|
|
|
|
|
return sharedPrefsWindowController;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|