Versioned to .88b3 and fixed the copyright date to 2006
[adiumx.git] / Source / AIChatCyclingPlugin.m
blobad392a8d3079d8778df66e3000a6fd7a7a48b6f4
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 "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;
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         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                         leftKey = [NSString stringWithCharacters:&left length:1];
85                         rightKey = [NSString stringWithCharacters:&right length:1];
86                         break;
87                 case AISwitchShiftArrows:
88                         leftKey = [NSString stringWithCharacters:&left length:1];
89                         rightKey = [NSString stringWithCharacters:&right length:1];
90                         keyMask = (NSCommandKeyMask | NSShiftKeyMask);
91                         break;
92                 default://case AIBrackets:
93                         leftKey = @"[";
94                         rightKey = @"]";
95                         break;
96         }
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
110  */
111 - (BOOL)validateMenuItem:(id <NSMenuItem>)menuItem
113         return([[[adium interfaceController] openChats] count] != 0);
117  * @brief Select the next chat
118  */
119 - (IBAction)nextChat:(id)sender
121         [[adium interfaceController] nextMessage:nil];
125  * @brief Select the previous chat
126  */
127 - (IBAction)previousChat:(id)sender
129         [[adium interfaceController] previousMessage:nil];
130 }       
132 @end