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 | #import "ICeCoffEEServicePrefController.h"
|
---|
17 |
|
---|
18 | // Just a handy macro for localized strings from our bundle; unused in this project.
|
---|
19 | #define NSLocalizedString_(key, comment) [[self bundle] localizedStringForKey:(key) value:@"" table:nil]
|
---|
20 |
|
---|
21 | @implementation ICeCoffEEController
|
---|
22 |
|
---|
23 | // This method should return an id of a class that implements the protocol
|
---|
24 | // required by APE Manager.
|
---|
25 |
|
---|
26 | + (id)prefPaneHandlerForAPE:(NSBundle*)apeBundle andBundle:(NSBundle*)prefPaneBundle
|
---|
27 | {
|
---|
28 | return [[self alloc] initWithAPE: apeBundle andBundle: prefPaneBundle];
|
---|
29 | }
|
---|
30 |
|
---|
31 | // Init the instance of our class
|
---|
32 | - (id)initWithAPE:(NSBundle*)apeBundle andBundle:(NSBundle*)prefPaneBundle
|
---|
33 | {
|
---|
34 | [self setAPEBundle: apeBundle prefPaneBundle: prefPaneBundle];
|
---|
35 |
|
---|
36 | [NSBundle loadNibNamed:@"APE Manager plugin" owner:self]; // load our nib file; it will call our awakeFromNib method
|
---|
37 |
|
---|
38 | return self;
|
---|
39 | }
|
---|
40 |
|
---|
41 | // This method is called when the preference pane is about to be shown.
|
---|
42 | - (void)willLoad
|
---|
43 | {
|
---|
44 | // we do nothing here
|
---|
45 | }
|
---|
46 |
|
---|
47 | // This method is called when the preference pane will be dismissed.
|
---|
48 | - (void)willUnload
|
---|
49 | {
|
---|
50 | [prefs release];
|
---|
51 | prefs = nil;
|
---|
52 | }
|
---|
53 |
|
---|
54 | // This method should return an NSView to be loaded into APE Manager preference
|
---|
55 | // area.
|
---|
56 | - (NSView *)mainView
|
---|
57 | {
|
---|
58 | return [window contentView];
|
---|
59 | }
|
---|
60 |
|
---|
61 | #define ICP(pref) (NSString *)kIC ## pref
|
---|
62 |
|
---|
63 | // This method is called once our nib file is loaded (we load it in the init method)
|
---|
64 | - (void)awakeFromNib
|
---|
65 | {
|
---|
66 | // load the preferences for our APE module
|
---|
67 | prefs = [[CFPreferencesWrapper_ICeCoffEE preferencesWithApplication: (NSString *)kICBundleIdentifier] retain];
|
---|
68 |
|
---|
69 | CFBundleRef apeBundle = CFBundleCreate(NULL, (CFURLRef)[NSURL fileURLWithPath: [_apeBundle bundlePath]]);
|
---|
70 | if ([prefs integerForKey: ICP(LastLoadedVersion)] != CFBundleGetVersionNumber(apeBundle)) {
|
---|
71 | [tabView selectTabViewItemWithIdentifier: @"noPrefs"];
|
---|
72 | CFRelease(apeBundle);
|
---|
73 | return;
|
---|
74 | }
|
---|
75 | CFRelease(apeBundle);
|
---|
76 | [tabView selectTabViewItemWithIdentifier: @"prefs"];
|
---|
77 |
|
---|
78 | [commandClickEnabled setState: [prefs boolForKey: ICP(CommandClickEnabled)]];
|
---|
79 | [self commandClickEnabled: nil];
|
---|
80 | [textBlinkEnabled setState: [prefs boolForKey: ICP(TextBlinkEnabled)]];
|
---|
81 | [self textBlinkEnabled: nil];
|
---|
82 | int blink = [prefs integerForKey: ICP(TextBlinkCount)];
|
---|
83 | if (blink != -1 && (blink = [textBlinkCount indexOfItemWithTag: blink]) != -1)
|
---|
84 | [textBlinkCount selectItemAtIndex: blink];
|
---|
85 | [servicesInContextualMenu setState: [prefs boolForKey: ICP(ServicesInContextualMenu)]];
|
---|
86 | [servicesInMenuBar setState: [prefs boolForKey: ICP(ServicesInMenuBar)]];
|
---|
87 | [errorSoundEnabled setState: [prefs boolForKey: ICP(ErrorSoundEnabled)]];
|
---|
88 | [errorDialogEnabled setState: [prefs boolForKey: ICP(ErrorDialogEnabled)]];
|
---|
89 | }
|
---|
90 |
|
---|
91 | - (void)setAPEBundle:(NSBundle*)apeBundle prefPaneBundle:(NSBundle *)aBundle;
|
---|
92 | {
|
---|
93 | [apeBundle retain];
|
---|
94 | [_apeBundle release];
|
---|
95 | _apeBundle = apeBundle;
|
---|
96 | [aBundle retain];
|
---|
97 | [_bundle release];
|
---|
98 | _bundle = aBundle;
|
---|
99 | }
|
---|
100 |
|
---|
101 | - (NSBundle *)bundle;
|
---|
102 | {
|
---|
103 | [_bundle autorelease];
|
---|
104 | return [_bundle retain];
|
---|
105 | }
|
---|
106 |
|
---|
107 | - (void)prefsChanged;
|
---|
108 | {
|
---|
109 | [prefs synchronize];
|
---|
110 | APEMessageBroadcast(kICBundleIdentifier, kICPreferencesChanged, NULL);
|
---|
111 | }
|
---|
112 |
|
---|
113 | - (IBAction)commandClickEnabled:(NSButton *)sender;
|
---|
114 | {
|
---|
115 | BOOL enabled = [commandClickEnabled state];
|
---|
116 | if (sender != nil) {
|
---|
117 | [prefs setBool: enabled forKey: ICP(CommandClickEnabled)];
|
---|
118 | [self prefsChanged];
|
---|
119 | }
|
---|
120 | [textBlinkEnabled setEnabled: enabled];
|
---|
121 | [textBlinkCount setEnabled: enabled ? [textBlinkEnabled state] : NO];
|
---|
122 | }
|
---|
123 | - (IBAction)textBlinkEnabled:(NSButton *)sender;
|
---|
124 | {
|
---|
125 | BOOL enabled = [textBlinkEnabled state];
|
---|
126 | if (sender != nil) {
|
---|
127 | [prefs setBool: enabled forKey: ICP(TextBlinkEnabled)];
|
---|
128 | [self prefsChanged];
|
---|
129 | }
|
---|
130 | [textBlinkCount setEnabled: enabled];
|
---|
131 | }
|
---|
132 | - (IBAction)textBlinkCount:(NSPopUpButton *)sender;
|
---|
133 | {
|
---|
134 | [prefs setInteger: [[textBlinkCount selectedItem] tag] forKey: ICP(TextBlinkCount)];
|
---|
135 | [self prefsChanged];
|
---|
136 | }
|
---|
137 | - (IBAction)servicesInContextualMenu:(NSButton *)sender;
|
---|
138 | {
|
---|
139 | [prefs setBool: [servicesInContextualMenu state] forKey: ICP(ServicesInContextualMenu)];
|
---|
140 | [self prefsChanged];
|
---|
141 | }
|
---|
142 | - (IBAction)servicesInMenuBar:(NSButton *)sender;
|
---|
143 | {
|
---|
144 | [prefs setBool: [servicesInMenuBar state] forKey: ICP(ServicesInMenuBar)];
|
---|
145 | [self prefsChanged];
|
---|
146 | }
|
---|
147 | - (IBAction)editContextualServices:(NSButton *)sender;
|
---|
148 | {
|
---|
149 | [[ICeCoffEEServicePrefController alloc] performSelector: @selector(initWithParentWindow:) withObject: [NSApp mainWindow] afterDelay: 0.01];
|
---|
150 | }
|
---|
151 | - (IBAction)terminalRequireOptionForSelfDrag:(NSButton *)sender;
|
---|
152 | {
|
---|
153 | [prefs setBool: [terminalRequireOptionForSelfDrag state] forKey: ICP(TerminalRequireOptionForSelfDrag)];
|
---|
154 | [self prefsChanged];
|
---|
155 | }
|
---|
156 | - (IBAction)errorSoundEnabled:(NSButton *)sender;
|
---|
157 | {
|
---|
158 | [prefs setBool: [errorSoundEnabled state] forKey: ICP(ErrorSoundEnabled)];
|
---|
159 | [self prefsChanged];
|
---|
160 | }
|
---|
161 | - (IBAction)errorDialogEnabled:(NSButton *)sender;
|
---|
162 | {
|
---|
163 | [prefs setBool: [errorDialogEnabled state] forKey: ICP(ErrorDialogEnabled)];
|
---|
164 | [self prefsChanged];
|
---|
165 | }
|
---|
166 |
|
---|
167 | @end
|
---|