2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright © 2007-2022 Transmission authors and contributors.
|
|
|
|
// It may be used under the MIT (SPDX: MIT) license.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2007-12-06 17:21:42 +00:00
|
|
|
|
2007-12-07 06:27:42 +00:00
|
|
|
#import "GroupToolbarItem.h"
|
2007-12-06 17:21:42 +00:00
|
|
|
|
2007-12-07 06:27:42 +00:00
|
|
|
@implementation GroupToolbarItem
|
2007-12-06 17:21:42 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)validate
|
2007-12-06 17:21:42 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSSegmentedControl* control = (NSSegmentedControl*)self.view;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-07-23 19:37:57 +00:00
|
|
|
NSInteger const count = self.subitems.count;
|
|
|
|
for (NSInteger i = 0; i < count; i++)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-07-23 19:37:57 +00:00
|
|
|
NSToolbarItem* item = self.subitems[i];
|
|
|
|
[control setEnabled:[self.target validateToolbarItem:item] forSegment:i];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-12-06 17:21:42 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)createMenu:(NSArray*)labels
|
2007-12-06 17:21:42 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMenuItem* menuItem = [[NSMenuItem alloc] initWithTitle:self.label action:NULL keyEquivalent:@""];
|
|
|
|
NSMenu* menu = [[NSMenu alloc] initWithTitle:self.label];
|
2021-08-07 07:27:56 +00:00
|
|
|
menuItem.submenu = menu;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
menu.autoenablesItems = NO;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-07-23 19:37:57 +00:00
|
|
|
NSInteger const count = self.subitems.count;
|
2008-10-12 21:38:13 +00:00
|
|
|
for (NSInteger i = 0; i < count; i++)
|
2007-12-06 20:25:38 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMenuItem* addItem = [[NSMenuItem alloc] initWithTitle:labels[i] action:self.action keyEquivalent:@""];
|
2021-08-07 07:27:56 +00:00
|
|
|
addItem.target = self.target;
|
|
|
|
addItem.tag = i;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[menu addItem:addItem];
|
2007-12-06 20:25:38 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
self.menuFormRepresentation = menuItem;
|
2007-12-06 20:46:58 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSMenuItem*)menuFormRepresentation
|
2007-12-06 20:46:58 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMenuItem* menuItem = super.menuFormRepresentation;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-07-23 19:37:57 +00:00
|
|
|
NSInteger const count = self.subitems.count;
|
2008-10-12 21:38:13 +00:00
|
|
|
for (NSInteger i = 0; i < count; i++)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-07-23 19:37:57 +00:00
|
|
|
NSToolbarItem* item = self.subitems[i];
|
|
|
|
[menuItem.submenu itemAtIndex:i].enabled = [self.target validateToolbarItem:item];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-12-06 20:25:38 +00:00
|
|
|
return menuItem;
|
2007-12-06 20:09:45 +00:00
|
|
|
}
|
2007-12-06 17:21:42 +00:00
|
|
|
|
|
|
|
@end
|