Updating svn:mergeinfo
[adiumx.git] / Source / AIChatCyclingPlugin.m
blob44d5253b83c3b36a09cc298086e7682d7bb72b3f
1 /* 
2  * Adium is the legal property of its developers, whose names are listed in the copyright file included
3  * with this source distribution.
4  * 
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.
8  * 
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.
12  * 
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.
15  */
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;
29 @end
31 /*!
32  * @class AIChatCyclingPlugin
33  * @brief Component to manage the chat cycling menu items
34  *
35  * Adium supports several different key combinations for switching tabs, configuring via the General Preferences.
36  */
37 @implementation AIChatCyclingPlugin
39 /*!
40  * @brief Install
41  */
42 - (void)installPlugin
44         id<AIMenuController> menuController = [adium menuController];
46         //Cycling menu items
47         previousChatMenuItem = [[NSMenuItem alloc] initWithTitle:PREVIOUS_MESSAGE_MENU_TITLE
48                                                                                                           target:self 
49                                                                                                           action:@selector(previousChat:)
50                                                                                            keyEquivalent:@""];
51         [menuController addMenuItem:previousChatMenuItem toLocation:LOC_Window_Commands];
53         nextChatMenuItem = [[NSMenuItem alloc] initWithTitle:NEXT_MESSAGE_MENU_TITLE 
54                                                                                                   target:self
55                                                                                                   action:@selector(nextChat:)
56                                                                                    keyEquivalent:@""];
57         [menuController addMenuItem:nextChatMenuItem toLocation:LOC_Window_Commands];
59         //Prefs
60         [[adium preferenceController] registerPreferenceObserver:self forGroup:PREF_GROUP_CHAT_CYCLING];
63 - (void)uninstallPlugin
65         [[adium preferenceController] unregisterPreferenceObserver:self];
68 /*!
69  * @brief Preferences changed
70  *
71  * Update the key equivalents for our previous and next chat menu items
72  */
73 - (void)preferencesChangedForGroup:(NSString *)group key:(NSString *)key
74                                                         object:(AIListObject *)object preferenceDict:(NSDictionary *)prefDict firstTime:(BOOL)firstTime
75 {       
76         //Configure our tab switching hotkeys
77         unichar                 left = NSLeftArrowFunctionKey;
78         unichar                 right = NSRightArrowFunctionKey;
79         NSString                *leftKey, *rightKey;
80         unsigned int    keyMask = NSCommandKeyMask;
81         
82         switch ([[prefDict objectForKey:KEY_TAB_SWITCH_KEYS] intValue]) {
83                 case AISwitchArrows:
84                 default:
85                         leftKey = [NSString stringWithCharacters:&left length:1];
86                         rightKey = [NSString stringWithCharacters:&right length:1];
87                         break;
88                 case AISwitchShiftArrows:
89                         leftKey = [NSString stringWithCharacters:&left length:1];
90                         rightKey = [NSString stringWithCharacters:&right length:1];
91                         keyMask = (NSCommandKeyMask | NSShiftKeyMask);
92                         break;
93                 case AIBrackets:
94                         leftKey = @"[";
95                         rightKey = @"]";
96                         break;
97                 case AIBraces:
98                         leftKey = @"{";
99                         rightKey = @"}";
100                         break;
101         }
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
116  */
117 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
119         return [[[adium interfaceController] openChats] count] != 0;
123  * @brief Select the next chat
124  */
125 - (IBAction)nextChat:(id)sender
127         [[adium interfaceController] nextChat:nil];
131  * @brief Select the previous chat
132  */
133 - (IBAction)previousChat:(id)sender
135         [[adium interfaceController] previousChat:nil];
136 }       
138 @end