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 "AIChatCyclingPlugin.h"
18 #import <Adium/AIInterfaceControllerProtocol.h>
19 #import <Adium/AIMenuControllerProtocol.h>
20 #import <Adium/AIPreferenceControllerProtocol.h>
21 #import "ESGeneralPreferencesPlugin.h"
22 #import <AIUtilities/AIMenuAdditions.h>
24 #define PREVIOUS_MESSAGE_MENU_TITLE AILocalizedString(@"Previous Chat",nil)
25 #define NEXT_MESSAGE_MENU_TITLE AILocalizedString(@"Next Chat",nil)
27 @interface AIChatCyclingPlugin (PRIVATE)
28 - (void)preferencesChanged:(NSNotification *)notification;
32 * @class AIChatCyclingPlugin
33 * @brief Component to manage the chat cycling menu items
35 * Adium supports several different key combinations for switching tabs, configuring via the General Preferences.
37 @implementation AIChatCyclingPlugin
44 id<AIMenuController> menuController = [adium menuController];
47 previousChatMenuItem = [[NSMenuItem alloc] initWithTitle:PREVIOUS_MESSAGE_MENU_TITLE
49 action:@selector(previousChat:)
51 [menuController addMenuItem:previousChatMenuItem toLocation:LOC_Window_Commands];
53 nextChatMenuItem = [[NSMenuItem alloc] initWithTitle:NEXT_MESSAGE_MENU_TITLE
55 action:@selector(nextChat:)
57 [menuController addMenuItem:nextChatMenuItem toLocation:LOC_Window_Commands];
60 [[adium preferenceController] registerPreferenceObserver:self forGroup:PREF_GROUP_CHAT_CYCLING];
63 - (void)uninstallPlugin
65 [[adium preferenceController] unregisterPreferenceObserver:self];
69 * @brief Preferences changed
71 * Update the key equivalents for our previous and next chat menu items
73 - (void)preferencesChangedForGroup:(NSString *)group key:(NSString *)key
74 object:(AIListObject *)object preferenceDict:(NSDictionary *)prefDict firstTime:(BOOL)firstTime
76 //Configure our tab switching hotkeys
77 unichar left = NSLeftArrowFunctionKey;
78 unichar right = NSRightArrowFunctionKey;
79 NSString *leftKey, *rightKey;
80 unsigned int keyMask = NSCommandKeyMask;
82 switch ([[prefDict objectForKey:KEY_TAB_SWITCH_KEYS] intValue]) {
85 leftKey = [NSString stringWithCharacters:&left length:1];
86 rightKey = [NSString stringWithCharacters:&right length:1];
88 case AISwitchShiftArrows:
89 leftKey = [NSString stringWithCharacters:&left length:1];
90 rightKey = [NSString stringWithCharacters:&right length:1];
91 keyMask = (NSCommandKeyMask | NSShiftKeyMask);
103 //Previous and nextMessage menuItems are in the same menu, so the setMenuChangedMessagesEnabled applies to both.
104 [[previousChatMenuItem menu] setMenuChangedMessagesEnabled:NO];
105 [previousChatMenuItem setKeyEquivalent:@""];
106 [previousChatMenuItem setKeyEquivalent:leftKey];
107 [previousChatMenuItem setKeyEquivalentModifierMask:keyMask];
108 [nextChatMenuItem setKeyEquivalent:@""];
109 [nextChatMenuItem setKeyEquivalent:rightKey];
110 [nextChatMenuItem setKeyEquivalentModifierMask:keyMask];
111 [[previousChatMenuItem menu] setMenuChangedMessagesEnabled:YES];
115 * @brief Menu item validation
117 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
119 return [[[adium interfaceController] openChats] count] != 0;
123 * @brief Select the next chat
125 - (IBAction)nextChat:(id)sender
127 [[adium interfaceController] nextChat:nil];
131 * @brief Select the previous chat
133 - (IBAction)previousChat:(id)sender
135 [[adium interfaceController] previousChat:nil];