1 | // |
---|
2 | // File: ICeCoffEEController.m |
---|
3 | // |
---|
4 | // Contains: ICeCoffEE APE preference pane controller |
---|
5 | // |
---|
6 | // Copyright: Copyright (c) 2003, Nicholas Riley |
---|
7 | // All Rights Reserved. |
---|
8 | // |
---|
9 | // Author(s): Nicholas Riley (Sun Jan 19 2003) |
---|
10 | // |
---|
11 | // =========================================================================== |
---|
12 | |
---|
13 | #import <ApplicationEnhancer/ApplicationEnhancer.h> |
---|
14 | #import "ICeCoffEEController.h" |
---|
15 | #import "ICeCoffEEShared.h" |
---|
16 | |
---|
17 | // Just a handy macro for localized strings from our bundle; unused in this project. |
---|
18 | #define NSLocalizedString_(key, comment) [[self bundle] localizedStringForKey:(key) value:@"" table:nil] |
---|
19 | |
---|
20 | @implementation ICeCoffEEController |
---|
21 | |
---|
22 | // This method should return an id of a class that implements the protocol |
---|
23 | // required by APE Manager. |
---|
24 | |
---|
25 | + (id)prefPaneHandlerForAPE:(NSBundle*)apeBundle andBundle:(NSBundle*)prefPaneBundle |
---|
26 | { |
---|
27 | return [[self alloc] initWithAPE:apeBundle andBundle:prefPaneBundle]; |
---|
28 | } |
---|
29 | |
---|
30 | // Init the instance of our class |
---|
31 | - (id)initWithAPE:(NSBundle*)apeBundle andBundle:(NSBundle*)prefPaneBundle |
---|
32 | { |
---|
33 | [self setBundle:prefPaneBundle]; // save our bundle for future use |
---|
34 | |
---|
35 | [NSBundle loadNibNamed:@"APE Manager plugin" owner:self]; // load our nib file; it will call our awakeFromNib method |
---|
36 | |
---|
37 | return self; |
---|
38 | } |
---|
39 | |
---|
40 | // This method is called when the preference pane is about to be shown. |
---|
41 | - (void)willLoad |
---|
42 | { |
---|
43 | // we do nothing here |
---|
44 | } |
---|
45 | |
---|
46 | // This method is called when the preference pane will be dismissed. |
---|
47 | - (void)willUnload |
---|
48 | { |
---|
49 | // we do nothing here, as well |
---|
50 | } |
---|
51 | |
---|
52 | // This method should return an NSView to be loaded into APE Manager preference |
---|
53 | // area. |
---|
54 | - (NSView *)mainView |
---|
55 | { |
---|
56 | return [window contentView]; |
---|
57 | } |
---|
58 | |
---|
59 | #define ICP(pref) (NSString *)kIC ## pref |
---|
60 | |
---|
61 | // This method is called once our nib file is loaded (we load it in the init method) |
---|
62 | - (void)awakeFromNib |
---|
63 | { |
---|
64 | // load the preferences for our APE module |
---|
65 | prefs = [[CFPreferencesWrapper_ICeCoffEE preferencesWithApplication: (NSString *)kICBundleIdentifier] retain]; |
---|
66 | |
---|
67 | [commandClickEnabled setState: [prefs boolForKey: ICP(CommandClickEnabled)]]; |
---|
68 | [self commandClickEnabled: nil]; |
---|
69 | [textBlinkEnabled setState: [prefs boolForKey: ICP(TextBlinkEnabled)]]; |
---|
70 | [self textBlinkEnabled: nil]; |
---|
71 | int blink = [prefs integerForKey: ICP(TextBlinkCount)]; |
---|
72 | if (blink != -1 && (blink = [textBlinkCount indexOfItemWithTag: blink]) != -1) |
---|
73 | [textBlinkCount selectItemAtIndex: blink]; |
---|
74 | [servicesInContextualMenu setState: [prefs boolForKey: ICP(ServicesInContextualMenu)]]; |
---|
75 | [servicesInMenuBar setState: [prefs boolForKey: ICP(ServicesInMenuBar)]]; |
---|
76 | [errorSoundEnabled setState: [prefs boolForKey: ICP(ErrorSoundEnabled)]]; |
---|
77 | [errorDialogEnabled setState: [prefs boolForKey: ICP(ErrorDialogEnabled)]]; |
---|
78 | } |
---|
79 | |
---|
80 | - (void)setBundle:(NSBundle *)aBundle; |
---|
81 | { |
---|
82 | [aBundle retain]; |
---|
83 | [_bundle release]; |
---|
84 | _bundle = aBundle; |
---|
85 | } |
---|
86 | |
---|
87 | - (NSBundle *)bundle; |
---|
88 | { |
---|
89 | [_bundle autorelease]; |
---|
90 | return [_bundle retain]; |
---|
91 | } |
---|
92 | |
---|
93 | - (void)prefsChanged; |
---|
94 | { |
---|
95 | [prefs synchronize]; |
---|
96 | APEMessageBroadcast(kICBundleIdentifier, kICPreferencesChanged, NULL); |
---|
97 | } |
---|
98 | |
---|
99 | - (IBAction)commandClickEnabled:(NSButton *)sender; |
---|
100 | { |
---|
101 | BOOL enabled = [commandClickEnabled state]; |
---|
102 | if (sender != nil) { |
---|
103 | [prefs setBool: enabled forKey: ICP(CommandClickEnabled)]; |
---|
104 | [self prefsChanged]; |
---|
105 | } |
---|
106 | [textBlinkEnabled setEnabled: enabled]; |
---|
107 | [textBlinkCount setEnabled: enabled ? [textBlinkEnabled state] : NO]; |
---|
108 | } |
---|
109 | - (IBAction)textBlinkEnabled:(NSButton *)sender; |
---|
110 | { |
---|
111 | BOOL enabled = [textBlinkEnabled state]; |
---|
112 | if (sender != nil) { |
---|
113 | [prefs setBool: enabled forKey: ICP(TextBlinkEnabled)]; |
---|
114 | [self prefsChanged]; |
---|
115 | } |
---|
116 | [textBlinkCount setEnabled: enabled]; |
---|
117 | } |
---|
118 | - (IBAction)textBlinkCount:(NSPopUpButton *)sender; |
---|
119 | { |
---|
120 | [prefs setInteger: [[textBlinkCount selectedItem] tag] forKey: ICP(TextBlinkCount)]; |
---|
121 | [self prefsChanged]; |
---|
122 | } |
---|
123 | - (IBAction)servicesInContextualMenu:(NSButton *)sender; |
---|
124 | { |
---|
125 | [prefs setBool: [servicesInContextualMenu state] forKey: ICP(ServicesInContextualMenu)]; |
---|
126 | [self prefsChanged]; |
---|
127 | } |
---|
128 | - (IBAction)servicesInMenuBar:(NSButton *)sender; |
---|
129 | { |
---|
130 | [prefs setBool: [servicesInMenuBar state] forKey: ICP(ServicesInMenuBar)]; |
---|
131 | [self prefsChanged]; |
---|
132 | } |
---|
133 | - (IBAction)errorSoundEnabled:(NSButton *)sender; |
---|
134 | { |
---|
135 | [prefs setBool: [errorSoundEnabled state] forKey: ICP(ErrorSoundEnabled)]; |
---|
136 | [self prefsChanged]; |
---|
137 | } |
---|
138 | - (IBAction)errorDialogEnabled:(NSButton *)sender; |
---|
139 | { |
---|
140 | [prefs setBool: [errorDialogEnabled state] forKey: ICP(ErrorDialogEnabled)]; |
---|
141 | [self prefsChanged]; |
---|
142 | } |
---|
143 | |
---|
144 | @end |
---|