Code simplification; remove the old preferences, and don't use a static variable to count the lines. Refs #13362.
I can't imagine using a static variable like this wouldn't cause problems, especially with "save chats" enabled; we'd be messing with the same static variable like crazy. I'm betting this explains some weird context problems, so let's see if this helps #13362.
2 * Adium is the legal property of its developers, whose names are listed in the copyright file included
3 * with this source distribution.
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11 * Public License for more details.
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 #import <Adium/AIContentControllerProtocol.h>
18 #import <Adium/AIInterfaceControllerProtocol.h>
19 #import "AISoundController.h"
20 #import "ESGeneralPreferences.h"
21 #import "ESGeneralPreferencesPlugin.h"
22 #import "PTHotKeyCenter.h"
24 #import "SRRecorderControl.h"
26 #import "AIMessageHistoryPreferencesWindowController.h"
27 #import "AIMessageWindowController.h"
28 #import <Adium/AIServiceIcons.h>
29 #import <Adium/AIStatusIcons.h>
30 #import <AIUtilities/AIColorAdditions.h>
31 #import <AIUtilities/AIFontAdditions.h>
32 #import <AIUtilities/AIImageAdditions.h>
33 #import <AIUtilities/AIMenuAdditions.h>
34 #import <AIUtilities/AIPopUpButtonAdditions.h>
36 #define PREF_GROUP_DUAL_WINDOW_INTERFACE @"Dual Window Interface"
37 #define KEY_TABBAR_POSITION @"Tab Bar Position"
39 @interface ESGeneralPreferences ()
40 - (NSMenu *)tabChangeKeysMenu;
41 - (NSMenu *)sendKeysMenu;
42 - (NSMenu *)tabPositionMenu;
45 @implementation ESGeneralPreferences
47 // XXX in order to edit the nib, you need the ShortcutReporter palette
48 // You can download it at http://evands.penguinmilitia.net/ShortcutRecorder.palette.zip
49 // This comes from http://wafflesoftware.net/shortcut/
51 + (NSSet *)keyPathsForValuesAffectingChatHistoryDisplayActive
53 return [NSSet setWithObjects:@"adium.preferenceController.Logging.Enable Logging",
54 @"adium.preferenceController.Message Context Display.Display Message Context",
58 //Preference pane properties
59 - (NSString *)paneIdentifier
63 - (NSString *)paneName{
64 return AILocalizedString(@"General","General preferences label");
66 - (NSString *)nibName{
67 return @"GeneralPreferences";
71 return [NSImage imageNamed:@"pref-general" forClass:[self class]];
74 //Configure the preference view
77 BOOL sendOnEnter, sendOnReturn;
80 [checkBox_messagesInTabs setState:[[adium.preferenceController preferenceForKey:KEY_TABBED_CHATTING
81 group:PREF_GROUP_INTERFACE] boolValue]];
82 [checkBox_arrangeByGroup setState:[[adium.preferenceController preferenceForKey:KEY_GROUP_CHATS_BY_GROUP
83 group:PREF_GROUP_INTERFACE] boolValue]];
86 [checkBox_updatesAutomatic setState:[[NSUserDefaults standardUserDefaults] boolForKey:@"SUEnableAutomaticChecks"]];
87 [checkBox_updatesProfileInfo setState:[[NSUserDefaults standardUserDefaults] boolForKey:@"SUSendProfileInfo"]];
88 [checkBox_updatesIncludeBetas setState:[[NSUserDefaults standardUserDefaults] boolForKey:@"AIAlwaysUpdateToBetas"]];
91 [popUp_tabKeys setMenu:[self tabChangeKeysMenu]];
92 [popUp_tabKeys selectItemWithTag:[[adium.preferenceController preferenceForKey:KEY_TAB_SWITCH_KEYS
93 group:PREF_GROUP_CHAT_CYCLING] intValue]];
96 sendOnEnter = [[adium.preferenceController preferenceForKey:SEND_ON_ENTER
97 group:PREF_GROUP_GENERAL] boolValue];
98 sendOnReturn = [[adium.preferenceController preferenceForKey:SEND_ON_RETURN
99 group:PREF_GROUP_GENERAL] boolValue];
100 [popUp_sendKeys setMenu:[self sendKeysMenu]];
102 if (sendOnEnter && sendOnReturn) {
103 [popUp_sendKeys selectItemWithTag:AISendOnBoth];
104 } else if (sendOnEnter) {
105 [popUp_sendKeys selectItemWithTag:AISendOnEnter];
106 } else if (sendOnReturn) {
107 [popUp_sendKeys selectItemWithTag:AISendOnReturn];
110 [popUp_tabPositionMenu setMenu:[self tabPositionMenu]];
111 [popUp_tabPositionMenu selectItemWithTag:[[adium.preferenceController preferenceForKey:KEY_TABBAR_POSITION
112 group:PREF_GROUP_DUAL_WINDOW_INTERFACE] intValue]];
115 TISInputSourceRef currentLayout = TISCopyCurrentKeyboardLayoutInputSource();
117 if (TISGetInputSourceProperty(currentLayout, kTISPropertyUnicodeKeyLayoutData)) {
118 PTKeyCombo *keyCombo = [[[PTKeyCombo alloc] initWithPlistRepresentation:[adium.preferenceController preferenceForKey:KEY_GENERAL_HOTKEY
119 group:PREF_GROUP_GENERAL]] autorelease];
120 [shortcutRecorder setKeyCombo:SRMakeKeyCombo([keyCombo keyCode], [shortcutRecorder carbonToCocoaFlags:[keyCombo modifiers]])];
121 [shortcutRecorder setAnimates:YES];
122 [shortcutRecorder setStyle:SRGreyStyle];
124 [label_shortcutRecorder setLocalizedString:AILocalizedString(@"When pressed, this key combination will bring Adium to the front", nil)];
126 [shortcutRecorder setEnabled:NO];
128 [label_shortcutRecorder setLocalizedString:AILocalizedString(@"You are using an old-style (rsrc) keyboard layout which Adium does not support.", nil)];
131 CFRelease(currentLayout);
133 [self configureControlDimming];
136 //Called in response to all preference controls, applies new settings
137 - (IBAction)changePreference:(id)sender
139 if (sender == popUp_tabKeys) {
140 AITabKeys keySelection = [[sender selectedItem] tag];
142 [adium.preferenceController setPreference:[NSNumber numberWithInt:keySelection]
143 forKey:KEY_TAB_SWITCH_KEYS
144 group:PREF_GROUP_CHAT_CYCLING];
146 } else if (sender == popUp_sendKeys) {
147 AISendKeys keySelection = [[sender selectedItem] tag];
148 BOOL sendOnEnter = (keySelection == AISendOnEnter || keySelection == AISendOnBoth);
149 BOOL sendOnReturn = (keySelection == AISendOnReturn || keySelection == AISendOnBoth);
151 [adium.preferenceController setPreference:[NSNumber numberWithInt:sendOnEnter]
153 group:PREF_GROUP_GENERAL];
154 [adium.preferenceController setPreference:[NSNumber numberWithInt:sendOnReturn]
155 forKey:SEND_ON_RETURN
156 group:PREF_GROUP_GENERAL];
157 } else if (sender == checkBox_updatesAutomatic) {
158 [[NSUserDefaults standardUserDefaults] setBool:[sender state] forKey:@"SUEnableAutomaticChecks"];
159 [self configureControlDimming];
160 } else if (sender == checkBox_updatesProfileInfo) {
161 [[NSUserDefaults standardUserDefaults] setBool:[sender state] forKey:@"SUSendProfileInfo"];
162 } else if (sender == checkBox_updatesIncludeBetas) {
163 [[NSUserDefaults standardUserDefaults] setBool:[sender state] forKey:@"AIAlwaysUpdateToBetas"];
167 //Dim controls as needed
168 - (void)configureControlDimming
170 [checkBox_arrangeByGroup setEnabled:[checkBox_messagesInTabs state]];
171 [checkBox_updatesProfileInfo setEnabled:[checkBox_updatesAutomatic state]];
173 [checkBox_updatesIncludeBetas setEnabled:NO];
174 [checkBox_updatesIncludeBetas setState:NSOnState];
176 [checkBox_updatesIncludeBetas setEnabled:[checkBox_updatesAutomatic state]];
181 * @brief Construct our menu by hand for easy localization
183 - (NSMenu *)tabChangeKeysMenu
185 NSMenu *menu = [[NSMenu allocWithZone:[NSMenu menuZone]] init];
186 #define PLACE_OF_INTEREST_SIGN "\u2318"
187 #define LEFTWARDS_ARROW "\u2190"
188 #define RIGHTWARDS_ARROW "\u2192"
189 #define SHIFT_ARROW "\u21E7"
190 #define OPTION_KEY "\u2325"
192 [menu addItemWithTitle:[NSString stringWithFormat:AILocalizedString(@"Arrows (%@ and %@)","Directional arrow keys word"), [NSString stringWithUTF8String:PLACE_OF_INTEREST_SIGN LEFTWARDS_ARROW], [NSString stringWithUTF8String:PLACE_OF_INTEREST_SIGN RIGHTWARDS_ARROW]]
198 [menu addItemWithTitle:[NSString stringWithFormat:AILocalizedString(@"Shift + Arrows (%@ and %@)","Shift key word + Directional arrow keys word"), [NSString stringWithUTF8String:SHIFT_ARROW PLACE_OF_INTEREST_SIGN LEFTWARDS_ARROW], [NSString stringWithUTF8String:SHIFT_ARROW PLACE_OF_INTEREST_SIGN RIGHTWARDS_ARROW]]
202 tag:AISwitchShiftArrows];
204 [menu addItemWithTitle:[NSString stringWithFormat:AILocalizedString(@"Option + Arrows (%@ and %@)","Option key word + Directional arrow keys word"), [NSString stringWithUTF8String:OPTION_KEY PLACE_OF_INTEREST_SIGN LEFTWARDS_ARROW], [NSString stringWithUTF8String:OPTION_KEY PLACE_OF_INTEREST_SIGN RIGHTWARDS_ARROW]]
210 [menu addItemWithTitle:[NSString stringWithFormat:AILocalizedString(@"Brackets (%@ and %@)","Word for [ and ] keys"), [NSString stringWithUTF8String:PLACE_OF_INTEREST_SIGN "["], [NSString stringWithUTF8String:PLACE_OF_INTEREST_SIGN "]"]]
216 [menu addItemWithTitle:[NSString stringWithFormat:AILocalizedString(@"Curly braces (%@ and %@)","Word for { and } keys"), [NSString stringWithUTF8String:PLACE_OF_INTEREST_SIGN "{"], [NSString stringWithUTF8String:PLACE_OF_INTEREST_SIGN "}"]]
223 return [menu autorelease];
226 - (BOOL)shortcutRecorder:(SRRecorderControl *)aRecorder isKeyCode:(signed short)keyCode andFlagsTaken:(unsigned int)flags reason:(NSString **)aReason
231 - (void)shortcutRecorder:(SRRecorderControl *)aRecorder keyComboDidChange:(KeyCombo)newKeyCombo
233 if (aRecorder == shortcutRecorder) {
234 PTKeyCombo *keyCombo = [PTKeyCombo keyComboWithKeyCode:[shortcutRecorder keyCombo].code
235 modifiers:[shortcutRecorder cocoaToCarbonFlags:[shortcutRecorder keyCombo].flags]];
236 [adium.preferenceController setPreference:[keyCombo plistRepresentation]
237 forKey:KEY_GENERAL_HOTKEY
238 group:PREF_GROUP_GENERAL];
243 * @brief Construct our menu by hand for easy localization
245 - (NSMenu *)sendKeysMenu
247 NSMenu *menu = [[NSMenu allocWithZone:[NSMenu menuZone]] init];
249 [menu addItemWithTitle:AILocalizedString(@"Enter","Enter key for sending messages")
255 [menu addItemWithTitle:AILocalizedString(@"Return","Return key for sending messages")
261 [menu addItemWithTitle:AILocalizedString(@"Enter and Return","Enter and return key for sending messages")
267 return [menu autorelease];
270 - (NSMenu *)tabPositionMenu
272 NSMenu *menu = [[NSMenu allocWithZone:[NSMenu menuZone]] init];
274 [menu addItemWithTitle:AILocalizedString(@"Top","Position menu item for tabs at the top of the message window")
278 tag:AdiumTabPositionTop];
280 [menu addItemWithTitle:AILocalizedString(@"Bottom","Position menu item for tabs at the bottom of the message window")
284 tag:AdiumTabPositionBottom];
286 [menu addItemWithTitle:AILocalizedString(@"Left","Position menu item for tabs at the left of the message window")
290 tag:AdiumTabPositionLeft];
292 [menu addItemWithTitle:AILocalizedString(@"Right","Position menu item for tabs at the right of the message window")
296 tag:AdiumTabPositionRight];
298 return [menu autorelease];
301 - (BOOL)chatHistoryDisplayActive
303 return ([[adium.preferenceController preferenceForKey:@"Display Message Context" group:@"Message Context Display"] boolValue] &&
304 [[adium.preferenceController preferenceForKey:@"Enable Logging" group:@"Logging"] boolValue]);
306 - (void)setChatHistoryDisplayActive:(BOOL)flag
308 [adium.preferenceController setPreference:[NSNumber numberWithBool:flag]
309 forKey:@"Display Message Context"
310 group:@"Message Context Display"];
313 #pragma mark Message history
314 - (IBAction)configureMessageHistory:(id)sender
316 [AIMessageHistoryPreferencesWindowController configureMessageHistoryPreferencesOnWindow:[[self view] window]];