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 setAPEBundle:apeBundle prefPaneBundle:prefPaneBundle];
|
---|
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 | [prefs release];
|
---|
50 | prefs = nil;
|
---|
51 | }
|
---|
52 |
|
---|
53 | // This method should return an NSView to be loaded into APE Manager preference
|
---|
54 | // area.
|
---|
55 | - (NSView *)mainView
|
---|
56 | {
|
---|
57 | return [window contentView];
|
---|
58 | }
|
---|
59 |
|
---|
60 | #define ICP(pref) (NSString *)kIC ## pref
|
---|
61 |
|
---|
62 | // This method is called once our nib file is loaded (we load it in the init method)
|
---|
63 | - (void)awakeFromNib
|
---|
64 | {
|
---|
65 | // load the preferences for our APE module
|
---|
66 | prefs = [[CFPreferencesWrapper_ICeCoffEE preferencesWithApplication: (NSString *)kICBundleIdentifier] retain];
|
---|
67 |
|
---|
68 | CFBundleRef apeBundle = CFBundleCreate(NULL, (CFURLRef)[NSURL fileURLWithPath: [_apeBundle bundlePath]]);
|
---|
69 | if ([prefs integerForKey: ICP(LastLoadedVersion)] != CFBundleGetVersionNumber(apeBundle)) {
|
---|
70 | [tabView selectTabViewItemWithIdentifier: @"noPrefs"];
|
---|
71 | CFRelease(apeBundle);
|
---|
72 | return;
|
---|
73 | }
|
---|
74 | CFRelease(apeBundle);
|
---|
75 | [tabView selectTabViewItemWithIdentifier: @"prefs"];
|
---|
76 |
|
---|
77 | [commandClickEnabled setState: [prefs boolForKey: ICP(CommandClickEnabled)]];
|
---|
78 | [self commandClickEnabled: nil];
|
---|
79 | [textBlinkEnabled setState: [prefs boolForKey: ICP(TextBlinkEnabled)]];
|
---|
80 | [self textBlinkEnabled: nil];
|
---|
81 | int blink = [prefs integerForKey: ICP(TextBlinkCount)];
|
---|
82 | if (blink != -1 && (blink = [textBlinkCount indexOfItemWithTag: blink]) != -1)
|
---|
83 | [textBlinkCount selectItemAtIndex: blink];
|
---|
84 | [servicesInContextualMenu setState: [prefs boolForKey: ICP(ServicesInContextualMenu)]];
|
---|
85 | [servicesInMenuBar setState: [prefs boolForKey: ICP(ServicesInMenuBar)]];
|
---|
86 | [errorSoundEnabled setState: [prefs boolForKey: ICP(ErrorSoundEnabled)]];
|
---|
87 | [errorDialogEnabled setState: [prefs boolForKey: ICP(ErrorDialogEnabled)]];
|
---|
88 | }
|
---|
89 |
|
---|
90 | - (void)setAPEBundle:(NSBundle*)apeBundle prefPaneBundle:(NSBundle *)aBundle;
|
---|
91 | {
|
---|
92 | [apeBundle retain];
|
---|
93 | [_apeBundle release];
|
---|
94 | _apeBundle = apeBundle;
|
---|
95 | [aBundle retain];
|
---|
96 | [_bundle release];
|
---|
97 | _bundle = aBundle;
|
---|
98 | }
|
---|
99 |
|
---|
100 | - (NSBundle *)bundle;
|
---|
101 | {
|
---|
102 | [_bundle autorelease];
|
---|
103 | return [_bundle retain];
|
---|
104 | }
|
---|
105 |
|
---|
106 | - (void)prefsChanged;
|
---|
107 | {
|
---|
108 | [prefs synchronize];
|
---|
109 | APEMessageBroadcast(kICBundleIdentifier, kICPreferencesChanged, NULL);
|
---|
110 | }
|
---|
111 |
|
---|
112 | - (IBAction)commandClickEnabled:(NSButton *)sender;
|
---|
113 | {
|
---|
114 | BOOL enabled = [commandClickEnabled state];
|
---|
115 | if (sender != nil) {
|
---|
116 | [prefs setBool: enabled forKey: ICP(CommandClickEnabled)];
|
---|
117 | [self prefsChanged];
|
---|
118 | }
|
---|
119 | [textBlinkEnabled setEnabled: enabled];
|
---|
120 | [textBlinkCount setEnabled: enabled ? [textBlinkEnabled state] : NO];
|
---|
121 | }
|
---|
122 | - (IBAction)textBlinkEnabled:(NSButton *)sender;
|
---|
123 | {
|
---|
124 | BOOL enabled = [textBlinkEnabled state];
|
---|
125 | if (sender != nil) {
|
---|
126 | [prefs setBool: enabled forKey: ICP(TextBlinkEnabled)];
|
---|
127 | [self prefsChanged];
|
---|
128 | }
|
---|
129 | [textBlinkCount setEnabled: enabled];
|
---|
130 | }
|
---|
131 | - (IBAction)textBlinkCount:(NSPopUpButton *)sender;
|
---|
132 | {
|
---|
133 | [prefs setInteger: [[textBlinkCount selectedItem] tag] forKey: ICP(TextBlinkCount)];
|
---|
134 | [self prefsChanged];
|
---|
135 | }
|
---|
136 | - (IBAction)servicesInContextualMenu:(NSButton *)sender;
|
---|
137 | {
|
---|
138 | [prefs setBool: [servicesInContextualMenu state] forKey: ICP(ServicesInContextualMenu)];
|
---|
139 | [self prefsChanged];
|
---|
140 | }
|
---|
141 | - (IBAction)servicesInMenuBar:(NSButton *)sender;
|
---|
142 | {
|
---|
143 | [prefs setBool: [servicesInMenuBar state] forKey: ICP(ServicesInMenuBar)];
|
---|
144 | [self prefsChanged];
|
---|
145 | }
|
---|
146 | - (IBAction)errorSoundEnabled:(NSButton *)sender;
|
---|
147 | {
|
---|
148 | [prefs setBool: [errorSoundEnabled state] forKey: ICP(ErrorSoundEnabled)];
|
---|
149 | [self prefsChanged];
|
---|
150 | }
|
---|
151 | - (IBAction)errorDialogEnabled:(NSButton *)sender;
|
---|
152 | {
|
---|
153 | [prefs setBool: [errorDialogEnabled state] forKey: ICP(ErrorDialogEnabled)];
|
---|
154 | [self prefsChanged];
|
---|
155 | }
|
---|
156 |
|
---|
157 | @end
|
---|