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 "AIInterfaceController.h"
19 #import "AIMenuController.h"
20 #import "AIPreferenceController.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 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]){
84 leftKey = [NSString stringWithCharacters:&left length:1];
85 rightKey = [NSString stringWithCharacters:&right length:1];
87 case AISwitchShiftArrows:
88 leftKey = [NSString stringWithCharacters:&left length:1];
89 rightKey = [NSString stringWithCharacters:&right length:1];
90 keyMask = (NSCommandKeyMask | NSShiftKeyMask);
92 default://case AIBrackets:
97 //Previous and nextMessage menuItems are in the same menu, so the setMenuChangedMessagesEnabled applies to both.
98 [[previousChatMenuItem menu] setMenuChangedMessagesEnabled:NO];
99 [previousChatMenuItem setKeyEquivalent:@""];
100 [previousChatMenuItem setKeyEquivalent:leftKey];
101 [previousChatMenuItem setKeyEquivalentModifierMask:keyMask];
102 [nextChatMenuItem setKeyEquivalent:@""];
103 [nextChatMenuItem setKeyEquivalent:rightKey];
104 [nextChatMenuItem setKeyEquivalentModifierMask:keyMask];
105 [[previousChatMenuItem menu] setMenuChangedMessagesEnabled:YES];
109 * @brief Menu item validation
111 - (BOOL)validateMenuItem:(id <NSMenuItem>)menuItem
113 return([[[adium interfaceController] openChats] count] != 0);
117 * @brief Select the next chat
119 - (IBAction)nextChat:(id)sender
121 [[adium interfaceController] nextMessage:nil];
125 * @brief Select the previous chat
127 - (IBAction)previousChat:(id)sender
129 [[adium interfaceController] previousMessage:nil];