2 // AIContactInfoWindowPlugin.m
5 // Created by Evan Schoenberg on 7/27/06.
8 #import "AIContactInfoWindowPlugin.h"
9 #import "AIContactInfoWindowController.h"
10 #import "ESShowContactInfoPromptController.h"
12 #import <Adium/AIAccountControllerProtocol.h>
13 #import <Adium/AIContactControllerProtocol.h>
14 #import <Adium/AIMenuControllerProtocol.h>
15 #import <Adium/AIInterfaceControllerProtocol.h>
16 #import <Adium/AIToolbarControllerProtocol.h>
18 #import <Adium/AIListObject.h>
19 #import <AIUtilities/AIImageAdditions.h>
20 #import <AIUtilities/AIMenuAdditions.h>
21 #import <AIUtilities/AIStringAdditions.h>
22 #import <AIUtilities/AIToolbarUtilities.h>
24 #define VIEW_CONTACTS_INFO AILocalizedString(@"Get Info",nil)
25 #define VIEW_CONTACTS_INFO_WITH_PROMPT [AILocalizedString(@"Get Info for Contact", nil) stringByAppendingEllipsis]
26 #define GET_INFO_MASK (NSCommandKeyMask | NSShiftKeyMask)
27 #define ALTERNATE_GET_INFO_MASK (NSCommandKeyMask | NSShiftKeyMask | NSControlKeyMask)
29 #define TITLE_SHOW_INFO AILocalizedString(@"Show Info",nil)
30 #define TOOLTIP_SHOW_INFO AILocalizedString(@"Show information about this contact or group and change settings specific to it","Tooltip for the Show Info toolbar button")
32 @interface AIContactInfoWindowPlugin (PRIVATE)
33 - (void)prepareContactInfo;
36 @implementation AIContactInfoWindowPlugin
39 [self prepareContactInfo];
42 //Contact Info --------------------------------------------------------------------------------
43 #pragma mark Contact Info
44 //Show info for the selected contact
45 - (IBAction)showContactInfo:(id)sender
47 AIListObject *listObject = nil;
49 if ((sender == menuItem_getInfoContextualContact) || (sender == menuItem_getInfoContextualGroup)) {
50 listObject = [[adium menuController] currentContextMenuObject];
52 listObject = [[adium interfaceController] selectedListObject];
56 [NSApp activateIgnoringOtherApps:YES];
57 [[[AIContactInfoWindowController showInfoWindowForListObject:listObject] window] makeKeyAndOrderFront:nil];
61 - (void)showSpecifiedContactInfo:(id)sender
63 [ESShowContactInfoPromptController showPrompt];
66 //Prepare the contact info menu and toolbar items
67 - (void)prepareContactInfo
69 //Add our get info contextual menu item
70 menuItem_getInfoContextualContact = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:VIEW_CONTACTS_INFO
72 action:@selector(showContactInfo:)
74 [[adium menuController] addContextualMenuItem:menuItem_getInfoContextualContact
75 toLocation:Context_Contact_Manage];
77 menuItem_getInfoContextualGroup = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:VIEW_CONTACTS_INFO
79 action:@selector(showContactInfo:)
81 [[adium menuController] addContextualMenuItem:menuItem_getInfoContextualGroup
82 toLocation:Context_Group_Manage];
84 //Install the standard Get Info menu item which will always be command-shift-I
85 menuItem_getInfo = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:VIEW_CONTACTS_INFO
87 action:@selector(showContactInfo:)
89 [menuItem_getInfo setKeyEquivalentModifierMask:GET_INFO_MASK];
90 [[adium menuController] addMenuItem:menuItem_getInfo toLocation:LOC_Contact_Info];
92 /* Install the alternate Get Info menu item which will be alternately command-I and command-shift-I, in the contact list
93 * and in all other places, respectively.
95 menuItem_getInfoAlternate = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:VIEW_CONTACTS_INFO
97 action:@selector(showContactInfo:)
99 [menuItem_getInfoAlternate setKeyEquivalentModifierMask:ALTERNATE_GET_INFO_MASK];
100 [menuItem_getInfoAlternate setAlternate:YES];
101 [[adium menuController] addMenuItem:menuItem_getInfoAlternate toLocation:LOC_Contact_Info];
103 //Register for the contact list notifications
104 [[adium notificationCenter] addObserver:self selector:@selector(contactListDidBecomeMain:)
105 name:Interface_ContactListDidBecomeMain
107 [[adium notificationCenter] addObserver:self selector:@selector(contactListDidResignMain:)
108 name:Interface_ContactListDidResignMain
111 //Watch changes in viewContactInfoMenuItem_alternate's menu so we can maintain its alternate status
112 //(it will expand into showing both the normal and the alternate items when the menu changes)
113 [[adium notificationCenter] addObserver:self selector:@selector(menuChanged:)
115 object:[menuItem_getInfoAlternate menu]];
117 //Install the Get Info (prompting for a contact name) menu item
118 menuItem_getInfoWithPrompt = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:VIEW_CONTACTS_INFO_WITH_PROMPT
120 action:@selector(showSpecifiedContactInfo:)
122 [menuItem_getInfoWithPrompt setKeyEquivalentModifierMask:(NSCommandKeyMask | NSAlternateKeyMask)];
123 [[adium menuController] addMenuItem:menuItem_getInfoWithPrompt toLocation:LOC_Contact_Info];
125 //Add our get info toolbar item
126 NSToolbarItem *toolbarItem = [AIToolbarUtilities toolbarItemWithIdentifier:@"ShowInfo"
127 label:AILocalizedString(@"Info",nil)
128 paletteLabel:TITLE_SHOW_INFO
129 toolTip:TOOLTIP_SHOW_INFO
131 settingSelector:@selector(setImage:)
132 itemContent:[NSImage imageNamed:@"pref-personal" forClass:[self class] loadLazily:YES]
133 action:@selector(showContactInfo:)
135 [[adium toolbarController] registerToolbarItem:toolbarItem forToolbarType:@"ListObject"];
138 //Always be able to show the inspector
139 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
141 if ((menuItem == menuItem_getInfo) || (menuItem == menuItem_getInfoAlternate)) {
142 return [[adium interfaceController] selectedListObject] != nil;
144 } else if ((menuItem == menuItem_getInfoContextualContact) || (menuItem == menuItem_getInfoContextualGroup)) {
145 return [[adium menuController] currentContextMenuObject] != nil;
147 } else if (menuItem == menuItem_getInfoWithPrompt) {
148 return [[adium accountController] oneOrMoreConnectedAccounts];
154 - (void)contactListDidBecomeMain:(NSNotification *)notification
156 [[adium menuController] removeItalicsKeyEquivalent];
157 [menuItem_getInfoAlternate setKeyEquivalentModifierMask:(NSCommandKeyMask)];
158 [menuItem_getInfoAlternate setAlternate:YES];
161 - (void)contactListDidResignMain:(NSNotification *)notification
163 //set our alternate modifier mask back to the obscure combination
164 [menuItem_getInfoAlternate setKeyEquivalent:@"i"];
165 [menuItem_getInfoAlternate setKeyEquivalentModifierMask:ALTERNATE_GET_INFO_MASK];
166 [menuItem_getInfoAlternate setAlternate:YES];
168 //Now give the italics its combination back
169 [[adium menuController] restoreItalicsKeyEquivalent];
172 - (void)menuChanged:(NSNotification *)notification
174 [NSMenu updateAlternateMenuItem:menuItem_getInfoAlternate];