blob: 1e3f335040d6981a80ab4358d1b5ebd7db9c95f8 [file] [log] [blame]
Kateryna Kostiuk13b76882017-03-30 09:18:44 -04001/*
2 * Copyright (C) 2015-2017 Savoir-faire Linux Inc.
3 * Author: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
Anthony Léonard49cb2912017-11-13 16:15:39 -05004 * Author: Olivier Soldano <olivier.soldano@savoirfairelinux.com>
5 * Author: Anthony Léonard <anthony.leonard@savoirfairelinux.com>
Kateryna Kostiuk13b76882017-03-30 09:18:44 -04006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22#import "ChooseAccountVC.h"
23
24//Qt
25#import <QSize>
26#import <QtMacExtras/qmacfunctions.h>
27#import <QPixmap>
28
29//LRC
Kateryna Kostiuk13b76882017-03-30 09:18:44 -040030#import <globalinstances.h>
Kateryna Kostiuk13b76882017-03-30 09:18:44 -040031#import <QItemSelectionModel.h>
32#import <interfaces/pixmapmanipulatori.h>
Anthony Léonard49cb2912017-11-13 16:15:39 -050033#import <api/newaccountmodel.h>
34#import <api/account.h>
Kateryna Kostiuk312f9132017-04-18 12:09:06 -040035
Kateryna Kostiuk13b76882017-03-30 09:18:44 -040036//RING
37#import "views/AccountMenuItemView.h"
Kateryna Kostiuka16c9862017-05-03 13:30:14 -040038#import "AccountSelectionManager.h"
Anthony Léonard9bebf1d2017-12-21 14:33:51 -050039#import "RingWindowController.h"
Kateryna Kostiukd73f9602018-07-24 13:51:28 -040040#import "utils.h"
41#import "views/NSColor+RingTheme.h"
Kateryna Kostiuk13b76882017-03-30 09:18:44 -040042
Kateryna Kostiuk04a56122018-08-27 10:51:27 -040043@interface NSMenu ()
44- (void) _setHasPadding: (BOOL) pad onEdge: (int) whatEdge;
45@end
46
Kateryna Kostiuk13b76882017-03-30 09:18:44 -040047@interface ChooseAccountVC () <NSMenuDelegate>
48
49@end
50
51@implementation ChooseAccountVC {
Kateryna Kostiuk312f9132017-04-18 12:09:06 -040052
Kateryna Kostiuk13b76882017-03-30 09:18:44 -040053 __unsafe_unretained IBOutlet NSImageView* profileImage;
Kateryna Kostiukd73f9602018-07-24 13:51:28 -040054 __unsafe_unretained IBOutlet NSTextField* accountStatus;
Kateryna Kostiuk13b76882017-03-30 09:18:44 -040055 __unsafe_unretained IBOutlet NSPopUpButton* accountSelectionButton;
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -040056 lrc::api::NewAccountModel* accMdl_;
Anthony Léonard49cb2912017-11-13 16:15:39 -050057 AccountSelectionManager* accountSelectionManager_;
Kateryna Kostiuk13b76882017-03-30 09:18:44 -040058}
59Boolean menuIsOpen;
60Boolean menuNeedsUpdate;
61NSMenu* accountsMenu;
62NSMenuItem* selectedMenuItem;
Kateryna Kostiuk194f21e2018-10-22 16:21:03 -040063NSMutableDictionary* menuItemsTags;
Anthony Léonard49cb2912017-11-13 16:15:39 -050064
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -040065-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil model:(lrc::api::NewAccountModel*) accMdl delegate:(id <ChooseAccountDelegate> )mainWindow
Anthony Léonard49cb2912017-11-13 16:15:39 -050066{
67 accMdl_ = accMdl;
68 accountSelectionManager_ = [[AccountSelectionManager alloc] initWithAccountModel:accMdl_];
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -040069 self.delegate = mainWindow;
Anthony Léonard49cb2912017-11-13 16:15:39 -050070 return [self initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
71}
Kateryna Kostiuk13b76882017-03-30 09:18:44 -040072
73- (void)awakeFromNib
74{
75 [profileImage setWantsLayer: YES];
76 profileImage.layer.cornerRadius = profileImage.frame.size.width / 2;
77 profileImage.layer.masksToBounds = YES;
Kateryna Kostiukd73f9602018-07-24 13:51:28 -040078 profileImage.layer.backgroundColor = [[NSColor ringGreyLight] CGColor];
Kateryna Kostiuk065aaf22017-07-07 13:04:23 -040079
Kateryna Kostiuk13b76882017-03-30 09:18:44 -040080 accountsMenu = [[NSMenu alloc] initWithTitle:@""];
Kateryna Kostiuk04a56122018-08-27 10:51:27 -040081 if ([accountsMenu respondsToSelector: @selector(_setHasPadding:onEdge:)])
82 {
83 [accountsMenu _setHasPadding: NO onEdge: 1];
84 [accountsMenu _setHasPadding: NO onEdge: 3];
85 }
Kateryna Kostiuk13b76882017-03-30 09:18:44 -040086 [accountsMenu setDelegate:self];
87 accountSelectionButton.menu = accountsMenu;
Kateryna Kostiukd73f9602018-07-24 13:51:28 -040088 [accountSelectionButton setAutoenablesItems:NO];
Kateryna Kostiuk194f21e2018-10-22 16:21:03 -040089 menuItemsTags = [[NSMutableDictionary alloc] init];
Kateryna Kostiuk13b76882017-03-30 09:18:44 -040090 [self update];
91
Anthony Léonard49cb2912017-11-13 16:15:39 -050092 QObject::connect(accMdl_,
93 &lrc::api::NewAccountModel::accountAdded,
Kateryna Kostiukab499f42018-04-16 12:27:33 -040094 [self] (const std::string& accountID) {
Kateryna Kostiuk312f9132017-04-18 12:09:06 -040095 [self update];
Kateryna Kostiukab499f42018-04-16 12:27:33 -040096 @try {
97 auto& account = [self selectedAccount];
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -040098 [self.delegate selectAccount:account currentRemoved: NO];
Kateryna Kostiukab499f42018-04-16 12:27:33 -040099 }
100 @catch (NSException * e) {
101 NSLog(@"account selection failed");
102 }
Kateryna Kostiuk312f9132017-04-18 12:09:06 -0400103 });
Anthony Léonard49cb2912017-11-13 16:15:39 -0500104 QObject::connect(accMdl_,
105 &lrc::api::NewAccountModel::accountRemoved,
Kateryna Kostiukab499f42018-04-16 12:27:33 -0400106 [self] (const std::string& accountID) {
107 if ([self selectedAccount].id.compare(accountID) == 0) {
108 [accountSelectionManager_ clearSelectedAccount];
109 }
110 @try {
111 auto& account = [self selectedAccount];
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400112 [self.delegate selectAccount:account currentRemoved: YES];
Kateryna Kostiukab499f42018-04-16 12:27:33 -0400113 }
114 @catch (NSException * e) {
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400115 [self.delegate allAccountsDeleted];
Kateryna Kostiukab499f42018-04-16 12:27:33 -0400116 }
Kateryna Kostiuk312f9132017-04-18 12:09:06 -0400117 [self update];
118 });
Anthony Léonard49cb2912017-11-13 16:15:39 -0500119 QObject::connect(accMdl_,
120 &lrc::api::NewAccountModel::profileUpdated,
Kateryna Kostiukab499f42018-04-16 12:27:33 -0400121 [self] (const std::string& accountID) {
Kateryna Kostiuk312f9132017-04-18 12:09:06 -0400122 [self update];
123 });
Kateryna Kostiukd73f9602018-07-24 13:51:28 -0400124 QObject::connect(accMdl_,
125 &lrc::api::NewAccountModel::accountStatusChanged,
126 [self] (const std::string& accountID) {
Kateryna Kostiuk43a79232018-10-18 15:45:18 -0400127 [self updateMenuItemForAccount:accountID];
Kateryna Kostiuk194f21e2018-10-22 16:21:03 -0400128 if([self selectedAccount].id == accountID) {
129 // update account state
130 [self updatePhoto];
131 [self setPopUpButtonSelection];
132 }
Kateryna Kostiukd73f9602018-07-24 13:51:28 -0400133 });
Kateryna Kostiuk13b76882017-03-30 09:18:44 -0400134}
135
Anthony Léonard49cb2912017-11-13 16:15:39 -0500136-(const lrc::api::account::Info&) selectedAccount
137{
Anthony Léonard72128c92017-12-26 16:48:39 -0500138 try {
139 return [accountSelectionManager_ savedAccount];
Kateryna Kostiukab499f42018-04-16 12:27:33 -0400140 } catch (NSException *ex) {
Anthony Léonard72128c92017-12-26 16:48:39 -0500141 auto accountList = accMdl_->getAccountList();
142 if (!accountList.empty()) {
143 const auto& fallbackAccount = accMdl_->getAccountInfo(accountList.at(0));
Kateryna Kostiuk194f21e2018-10-22 16:21:03 -0400144 [accountSelectionManager_ setSavedAccount:fallbackAccount];
Anthony Léonard49cb2912017-11-13 16:15:39 -0500145 return fallbackAccount;
Anthony Léonard72128c92017-12-26 16:48:39 -0500146 } else {
147 NSException* noAccEx = [NSException
148 exceptionWithName:@"NoAccountException"
149 reason:@"No account in AccountModel"
150 userInfo:nil];
151 @throw noAccEx;
Anthony Léonard49cb2912017-11-13 16:15:39 -0500152 }
153 }
Anthony Léonard49cb2912017-11-13 16:15:39 -0500154}
155
Kateryna Kostiuk43a79232018-10-18 15:45:18 -0400156-(void) updateMenuItemForAccount: (const std::string&) accountID {
Kateryna Kostiuk194f21e2018-10-22 16:21:03 -0400157 NSMenuItem *item =[accountsMenu itemWithTag:[menuItemsTags[@(accountID.c_str())] intValue]];
158 if(!item) {return;}
159 AccountMenuItemView *itemView =item.view;
160 if(!itemView) {return;}
161 [self configureView:itemView forAccount:accountID forMenuItem: item];
Kateryna Kostiuk43a79232018-10-18 15:45:18 -0400162}
163
Kateryna Kostiuk13b76882017-03-30 09:18:44 -0400164-(void) updateMenu {
165 [accountsMenu removeAllItems];
Kateryna Kostiuk13b76882017-03-30 09:18:44 -0400166
Anthony Léonard49cb2912017-11-13 16:15:39 -0500167 auto accList = accMdl_->getAccountList();
168
169 for (std::string accId : accList) {
170 auto& account = accMdl_->getAccountInfo(accId);
171
Kateryna Kostiuk13b76882017-03-30 09:18:44 -0400172 NSMenuItem* menuBarItem = [[NSMenuItem alloc]
Kateryna Kostiuk312f9132017-04-18 12:09:06 -0400173 initWithTitle:[self itemTitleForAccount:account]
174 action:NULL
175 keyEquivalent:@""];
176
Kateryna Kostiuk13b76882017-03-30 09:18:44 -0400177 AccountMenuItemView *itemView = [[AccountMenuItemView alloc] initWithFrame:CGRectZero];
Kateryna Kostiuk194f21e2018-10-22 16:21:03 -0400178 [self configureView:itemView forAccount:accId forMenuItem: menuBarItem];
179 int itemTag = arc4random_uniform(1000);
180 menuItemsTags[@(accId.c_str())] = [NSNumber numberWithInt: itemTag];
181 [menuBarItem setTag:itemTag];
Kateryna Kostiuk13b76882017-03-30 09:18:44 -0400182 [menuBarItem setView:itemView];
183 [accountsMenu addItem:menuBarItem];
Kateryna Kostiuk13b76882017-03-30 09:18:44 -0400184 }
Kateryna Kostiukd73f9602018-07-24 13:51:28 -0400185
186 // create "add a new account" menu item
187 NSMenuItem* menuBarItem = [[NSMenuItem alloc]
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400188 initWithTitle:@"Add Account"
Kateryna Kostiukd73f9602018-07-24 13:51:28 -0400189 action:nil
190 keyEquivalent:@""];
191 AccountMenuItemView *itemView = [[AccountMenuItemView alloc] initWithFrame:CGRectZero];
192 [itemView.accountAvatar setHidden:YES];
193 [itemView.accountStatus setHidden:YES];
194 [itemView.accountTypeLabel setHidden:YES];
195 [itemView.userNameLabel setHidden:YES];
196 [itemView.accountLabel setHidden:YES];
197 [itemView.createNewAccount setAction:@selector(createNewAccount:)];
198 [itemView.createNewAccount setTarget:self];
199 [menuBarItem setView: itemView];
200 [accountsMenu addItem: menuBarItem];
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400201 [profileImage setHidden:accList.empty()];
202 [accountStatus setHidden:accList.empty()];
Kateryna Kostiukd73f9602018-07-24 13:51:28 -0400203}
204
Kateryna Kostiuk194f21e2018-10-22 16:21:03 -0400205-(void) configureView: (AccountMenuItemView *) itemView forAccount:(const std::string&) accountId forMenuItem:(NSMenuItem *) item {
Kateryna Kostiukd73f9602018-07-24 13:51:28 -0400206 auto& account = accMdl_->getAccountInfo(accountId);
Kateryna Kostiuk194f21e2018-10-22 16:21:03 -0400207 item.attributedTitle = [self attributedItemTitleForAccount:account];
Kateryna Kostiukd73f9602018-07-24 13:51:28 -0400208 [itemView.accountLabel setStringValue:@(account.profileInfo.alias.c_str())];
209 NSString* userNameString = [self nameForAccount: account];
210 [itemView.userNameLabel setStringValue:userNameString];
Kateryna Kostiuk43a79232018-10-18 15:45:18 -0400211 NSData *imageData = [[NSData alloc] initWithBase64EncodedString:@(account.profileInfo.avatar.c_str()) options:NSDataBase64DecodingIgnoreUnknownCharacters];
212 NSImage *image = [[NSImage alloc] initWithData:imageData];
213 if(image) {
214 [itemView.accountAvatar setImage: image];
Kateryna Kostiukd73f9602018-07-24 13:51:28 -0400215 } else {
216 [itemView.accountAvatar setImage: [NSImage imageNamed:@"default_avatar_overlay.png"]];
217 }
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400218 [itemView.accountStatus setHidden:!account.enabled];
Kateryna Kostiukd73f9602018-07-24 13:51:28 -0400219 switch (account.profileInfo.type) {
220 case lrc::api::profile::Type::SIP:
221 [itemView.accountTypeLabel setStringValue:@"SIP"];
222 break;
223 case lrc::api::profile::Type::RING:
224 [itemView.accountTypeLabel setStringValue:@"RING"];
225 break;
226 default:
227 break;
228 }
229 [itemView.createNewAccount setHidden:YES];
230 [itemView.createNewAccountImage setHidden:YES];
231}
232
233
234- (void)createNewAccount:(id)sender {
235 [accountSelectionButton.menu cancelTrackingWithoutAnimation];
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400236 [self.delegate createNewAccount];
Kateryna Kostiuk13b76882017-03-30 09:18:44 -0400237}
238
Anthony Léonard49cb2912017-11-13 16:15:39 -0500239-(void) updatePhoto
240{
Anthony Léonard72128c92017-12-26 16:48:39 -0500241 @try {
242 auto& account = [self selectedAccount];
243 if(account.profileInfo.type == lrc::api::profile::Type::INVALID)
244 return;
Kateryna Kostiuk43a79232018-10-18 15:45:18 -0400245 NSData *imageData = [[NSData alloc] initWithBase64EncodedString:@(account.profileInfo.avatar.c_str()) options:NSDataBase64DecodingIgnoreUnknownCharacters];
246 NSImage *image = [[NSImage alloc] initWithData:imageData];
247 if(image) {
248 [profileImage setImage: image];
Kateryna Kostiukd73f9602018-07-24 13:51:28 -0400249 } else {
250 [profileImage setImage: [NSImage imageNamed:@"default_avatar_overlay.png"]];
251 }
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400252 [accountStatus setHidden:!account.enabled];
Anthony Léonard72128c92017-12-26 16:48:39 -0500253 }
254 @catch (NSException *ex) {
255 NSLog(@"Caught exception %@: %@", [ex name], [ex reason]);
256 }
Kateryna Kostiuk13b76882017-03-30 09:18:44 -0400257}
258
Anthony Léonard49cb2912017-11-13 16:15:39 -0500259-(NSString*) nameForAccount:(const lrc::api::account::Info&) account {
Kateryna Kostiukd73f9602018-07-24 13:51:28 -0400260 return bestIDForAccount(account);
Anthony Léonard49cb2912017-11-13 16:15:39 -0500261}
262
263-(NSString*) itemTitleForAccount:(const lrc::api::account::Info&) account {
Kateryna Kostiukd73f9602018-07-24 13:51:28 -0400264 NSString* alias = bestNameForAccount(account);
Kateryna Kostiuk13b76882017-03-30 09:18:44 -0400265 NSString* userNameString = [self nameForAccount: account];
Kateryna Kostiukdff4c0e2018-08-31 10:58:32 -0400266 if([alias isEqualToString:userNameString] || [userNameString length] == 0) {
267 return alias;
Kateryna Kostiuka7248462017-04-18 16:15:31 -0400268 }
Kateryna Kostiukdff4c0e2018-08-31 10:58:32 -0400269 alias = [NSString stringWithFormat: @"%@\n", alias];
Kateryna Kostiuk13b76882017-03-30 09:18:44 -0400270 return [alias stringByAppendingString:userNameString];
271}
272
Anthony Léonard49cb2912017-11-13 16:15:39 -0500273- (NSAttributedString*) attributedItemTitleForAccount:(const lrc::api::account::Info&) account {
Kateryna Kostiukd73f9602018-07-24 13:51:28 -0400274 NSString* alias = bestNameForAccount(account);
Kateryna Kostiuk13b76882017-03-30 09:18:44 -0400275 NSString* userNameString = [self nameForAccount: account];
276 NSFont *fontAlias = [NSFont userFontOfSize:14.0];
277 NSFont *fontUserName = [NSFont userFontOfSize:11.0];
278 NSColor *colorAlias = [NSColor labelColor];
279 NSColor *colorAUserName = [NSColor secondaryLabelColor];
280 NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
281 paragraphStyle.lineBreakMode = NSLineBreakByTruncatingTail;
282 NSDictionary *aliasAttrs = [NSDictionary dictionaryWithObjectsAndKeys:fontAlias,NSFontAttributeName,
283 colorAlias,NSForegroundColorAttributeName,
284 paragraphStyle,NSParagraphStyleAttributeName, nil];
285 NSDictionary *userNameAttrs = [NSDictionary dictionaryWithObjectsAndKeys:fontUserName,NSFontAttributeName,
286 colorAUserName,NSForegroundColorAttributeName,
287 paragraphStyle,NSParagraphStyleAttributeName, nil];
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400288
289 if([alias isEqualToString:userNameString] || [userNameString length] == 0) {
290 paragraphStyle.paragraphSpacingBefore = 20;
291 aliasAttrs = [NSDictionary dictionaryWithObjectsAndKeys:fontAlias,NSFontAttributeName,
292 colorAlias,NSForegroundColorAttributeName,
293 paragraphStyle,NSParagraphStyleAttributeName, nil];
294 return [[NSAttributedString alloc] initWithString:alias attributes:aliasAttrs];
295 }
296 alias = [NSString stringWithFormat: @"%@\n", alias];
Kateryna Kostiuk13b76882017-03-30 09:18:44 -0400297 NSAttributedString* attributedString = [[NSAttributedString alloc] initWithString:alias attributes:aliasAttrs];
298 NSAttributedString* attributedStringSecond= [[NSAttributedString alloc] initWithString:userNameString attributes:userNameAttrs];
299 NSMutableAttributedString *result = [[NSMutableAttributedString alloc] init];
300 [result appendAttributedString:attributedString];
301 [result appendAttributedString:attributedStringSecond];
302 return result;
303}
304
Kateryna Kostiuk13b76882017-03-30 09:18:44 -0400305-(void) update {
306 if(menuIsOpen) {
307 return;
308 }
309 [self updateMenu];
Kateryna Kostiuk312f9132017-04-18 12:09:06 -0400310 [self setPopUpButtonSelection];
Kateryna Kostiukecaa3952018-07-13 16:00:34 -0400311 [self updatePhoto];
Kateryna Kostiuk13b76882017-03-30 09:18:44 -0400312}
313
Kateryna Kostiuk312f9132017-04-18 12:09:06 -0400314-(void) setPopUpButtonSelection {
Kateryna Kostiuk13b76882017-03-30 09:18:44 -0400315 if(accountsMenu.itemArray.count == 0) {
316 [self.view setHidden:YES];
317 return;
318 }
Kateryna Kostiuk312f9132017-04-18 12:09:06 -0400319 [self.view setHidden:NO];
Anthony Léonard72128c92017-12-26 16:48:39 -0500320 @try {
321 auto& account = [self selectedAccount];
322 if(account.profileInfo.type == lrc::api::profile::Type::INVALID){
323 return;
324 }
Kateryna Kostiuk194f21e2018-10-22 16:21:03 -0400325 [accountSelectionButton selectItemWithTag:[menuItemsTags[@(account.id.c_str())] intValue]];
Kateryna Kostiuk13b76882017-03-30 09:18:44 -0400326 }
Anthony Léonard72128c92017-12-26 16:48:39 -0500327 @catch (NSException *ex) {
328 NSLog(@"Caught exception %@: %@", [ex name], [ex reason]);
329 }
Kateryna Kostiuk13b76882017-03-30 09:18:44 -0400330}
331
332#pragma mark - NSPopUpButton item selection
333
334- (IBAction)itemChanged:(id)sender {
Kateryna Kostiuk04a56122018-08-27 10:51:27 -0400335 NSInteger row = [(NSPopUpButton *)sender indexOfSelectedItem];
Anthony Léonard49cb2912017-11-13 16:15:39 -0500336 auto accList = accMdl_->getAccountList();
337 if (row >= accList.size())
Kateryna Kostiuka16c9862017-05-03 13:30:14 -0400338 return;
Anthony Léonard49cb2912017-11-13 16:15:39 -0500339
340 auto& account = accMdl_->getAccountInfo(accList[row]);
341 [accountSelectionManager_ setSavedAccount:account];
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400342 [self.delegate selectAccount:account currentRemoved: NO];
Kateryna Kostiukecaa3952018-07-13 16:00:34 -0400343 [self updatePhoto];
Kateryna Kostiuk13b76882017-03-30 09:18:44 -0400344}
345
346#pragma mark - NSMenuDelegate
347- (void)menuWillOpen:(NSMenu *)menu {
348 menuIsOpen = true;
349 // remember selected item to remove highlighting when menu is open
350 selectedMenuItem = [accountSelectionButton selectedItem];
351}
352- (void)menuDidClose:(NSMenu *)menu {
353
354 menuIsOpen = false;
355}
356
357- (void)menu:(NSMenu *)menu willHighlightItem:(nullable NSMenuItem *)item {
358 if (!selectedMenuItem || selectedMenuItem == item) {
359 return;
360 }
361 int index = [menu indexOfItem:selectedMenuItem];
362 [menu removeItemAtIndex:index];
363 [menu insertItem:selectedMenuItem atIndex:index];
364 [accountSelectionButton selectItemAtIndex:index];
365 selectedMenuItem = nil;
366}
367
Kateryna Kostiukabf4e272017-04-18 14:18:00 -0400368-(void) enable {
369 [accountSelectionButton setEnabled:YES];
370}
371-(void) disable {
372 [accountSelectionButton setEnabled:NO];
373}
374
Kateryna Kostiuk13b76882017-03-30 09:18:44 -0400375@end