-
Notifications
You must be signed in to change notification settings - Fork 1
/
PreferenceController.m
222 lines (193 loc) · 8.99 KB
/
PreferenceController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/* Copyright © 2003, Leaky Puppy Software, Net Monkey Inc.
This file is part of Fob.
Fob is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
Fob is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Fob; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
// PreferenceController.m
// Fob
//
// Created by Thomas Finley on Sat Jan 18 2003.
// Copyright (c) 2003 Leaky Puppy Software, for Net Monkey Inc. All rights reserved.
// This program is distributed under the terms of the GNU General Public License.
#import "PreferenceController.h"
#import "FobController.h"
#import "StatusItemKeeper.h"
#import "ZoomSwitcher.h"
#import "prefs.h"
@implementation PreferenceController
- (id)init {
if (self = [super init]) {
savedValues = nil;
}
return self;
}
- (void)awakeFromNib {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[mainWindow setHidesOnDeactivate:![defaults boolForKey:FobKeepWindowOpenKey]];
// Status item nonsense.
if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_1) {
// Status items can't be used in "OS X".
[statusItemVisibleCheckbox setEnabled:NO];
[bounceSlider setEnabled:NO];
}
[[NSNotificationCenter defaultCenter]
postNotificationName:@"FobStatusItemVisibilityChanged"
object:self];
[quitItem setKeyEquivalent:
([defaults boolForKey:FobDisableCommandQKey] ? @"" : @"q")];
}
- (void)changeFeedbackLabel {
switch ([feedbackSlider intValue]) {
case flash:
[feedbackLabel setStringValue:NSLocalizedString(@"FeedbackLevelFlashOnly", nil)];
break;
case beep:
[feedbackLabel setStringValue:NSLocalizedString(@"FeedbackLevelBeepOnce", nil)];
break;
case alwaysBeep:
[feedbackLabel setStringValue:NSLocalizedString(@"FeedbackLevelBeepAlways", nil)];
break;
default:
NSLog(@"Warning, bad feedback level!");
break;
}
}
- (void)changeBounceLabel {
switch ([bounceSlider intValue]) {
case flash:
[bounceLabel setStringValue:NSLocalizedString(@"BounceLevelNone", nil)];
break;
case beep:
[bounceLabel setStringValue:NSLocalizedString(@"BounceLevelOnce", nil)];
break;
case alwaysBeep:
[bounceLabel setStringValue:NSLocalizedString(@"BounceLevelAlways", nil)];
break;
default:
NSLog(@"Warning, bad bounce level!");
break;
}
}
// This will display the preferences sheet.
- (void)displayPreferences {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
// Store values in case of cancel.
savedValues = [[defaults dictionaryRepresentation] retain];
// Change the view to reflect current preferences.
[confirmDeleteCheckbox setState:[defaults boolForKey:FobConfirmDeleteKey] ? NSOnState : NSOffState];
[keepWindowOpenCheckbox setState:[defaults boolForKey:FobKeepWindowOpenKey] ? NSOnState : NSOffState];
[statusItemVisibleCheckbox setState:[defaults boolForKey:FobStatusItemVisibleKey] ? NSOnState : NSOffState];
[statusItemTitleVisibleCheckbox setState:
[defaults boolForKey:FobStatusItemTitleVisibleKey] ? NSOnState : NSOffState];
[statusItemTitleVisibleCheckbox setEnabled:[defaults boolForKey:FobStatusItemVisibleKey]];
[scaleDockTimeCheckbox setState:[defaults boolForKey:FobScaleDockTimeKey] ? NSOnState : NSOffState];
[disableCommandQCheckbox setState:[defaults boolForKey:FobDisableCommandQKey] ? NSOnState : NSOffState];
[dockMenuSubmenusCheckbox setState:[defaults boolForKey:FobDockMenuSubmenusKey] ? NSOnState : NSOffState];
[clearDueOnQuitCheckbox setState:[defaults boolForKey:FobClearDueOnQuitKey] ? NSOnState : NSOffState];
[feedbackSlider setIntValue:[defaults integerForKey:FobFeedbackLevelKey]];
[bounceSlider setIntValue:[defaults integerForKey:FobBounceLevelKey]];
[self changeFeedbackLabel];
[self changeBounceLabel];
// Show the sheet.
[NSApp beginSheet:preferenceWindow
modalForWindow:[[FobController defaultController] currentWindow]
modalDelegate:self
didEndSelector:@selector(preferenceEnded:returnCode:contextInfo:)
contextInfo:nil];
}
- (IBAction)changeConfirmDeletions:(id)sender {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setBool:[confirmDeleteCheckbox state] == NSOnState
forKey:FobConfirmDeleteKey];
}
- (IBAction)changeKeepOpen:(id)sender {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
BOOL keepWindowOpen = [keepWindowOpenCheckbox state] == NSOnState;
[defaults setBool:keepWindowOpen
forKey:FobKeepWindowOpenKey];
[mainWindow setHidesOnDeactivate:!keepWindowOpen];
}
- (IBAction)changeFeedback:(id)sender {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setInteger:[feedbackSlider intValue]
forKey:FobFeedbackLevelKey];
[self changeFeedbackLabel];
}
- (IBAction)changeBounce:(id)sender {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setInteger:[bounceSlider intValue]
forKey:FobBounceLevelKey];
[self changeBounceLabel];
}
- (IBAction)changeStatusVisible:(id)sender {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
BOOL statusVisible = [statusItemVisibleCheckbox state] == NSOnState;
[defaults setBool:statusVisible
forKey:FobStatusItemVisibleKey];
[statusItemTitleVisibleCheckbox setEnabled:statusVisible];
[[NSNotificationCenter defaultCenter] postNotificationName:@"FobStatusItemVisibilityChanged"
object:self];
}
- (IBAction)changeStatusTitleVisible:(id)sender {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
BOOL statusTitleVisible = [statusItemTitleVisibleCheckbox state] == NSOnState;
[defaults setBool:statusTitleVisible
forKey:FobStatusItemTitleVisibleKey];
}
- (IBAction)changeScaleDockTime:(id)sender {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
BOOL scaleDockTime = [scaleDockTimeCheckbox state] == NSOnState;
[defaults setBool:scaleDockTime
forKey:FobScaleDockTimeKey];
}
- (IBAction)changeCommandQ:(id)sender {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
BOOL disableQ = [disableCommandQCheckbox state] == NSOnState;
[defaults setBool:disableQ
forKey:FobDisableCommandQKey];
[quitItem setKeyEquivalent:(disableQ ? @"" : @"q")];
}
- (IBAction)changeDockMenuSubmenus:(id)sender {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
BOOL dms = [dockMenuSubmenusCheckbox state] == NSOnState;
[defaults setBool:dms
forKey:FobDockMenuSubmenusKey];
}
- (IBAction)changeClearDueOnQuit:(id)sender {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
BOOL cdoq = [clearDueOnQuitCheckbox state] == NSOnState;
[defaults setBool:cdoq
forKey:FobClearDueOnQuitKey];
}
- (IBAction)endSheet:(id)sender {
// Hide the sheet.
[preferenceWindow orderOut:sender];
// Return to normal event handling.
[NSApp endSheet:preferenceWindow returnCode:[sender tag]];
}
- (void)preferenceEnded:(NSWindow *)sheet
returnCode:(int)returnCode
contextInfo:(id)contextInfo {
if (returnCode == 1) {
// Notice my comparison test. I am a bad coder.
// Cancel was selected!
// Setting things back as they were.
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSMutableDictionary *factoryValues = factoryDefaults();
[factoryValues removeObjectForKey:FobPresetAlarmsKey];
[factoryValues removeObjectForKey:FobActiveAlarmsKey];
NSEnumerator *keyEnum = [factoryValues keyEnumerator];
id key;
while (key = [keyEnum nextObject]) {
[defaults setObject:[savedValues objectForKey:key]
forKey:key];
}
// Some preferences require some action beyond merely setting the default.
[[NSNotificationCenter defaultCenter] postNotificationName:@"FobStatusItemVisibilityChanged"
object:self];
[mainWindow setHidesOnDeactivate:![defaults boolForKey:FobKeepWindowOpenKey]];
[quitItem setKeyEquivalent:([defaults boolForKey:FobDisableCommandQKey] ? @"" : @"q")];
}
[savedValues release];
}
@end