fix: allow NSMenuItems to be disabled (#46342)
* fix: disable NSMenu autoenable feature to allow disabling of NSMenuItems Co-authored-by: Hailey Schauman <hschauman@slack-corp.com> * style: fix linter issues and update comments Co-authored-by: Hailey Schauman <hschauman@slack-corp.com> * chore: remove unneeded comment Co-authored-by: Hailey <hschauman@slack-corp.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Hailey Schauman <hschauman@slack-corp.com>
This commit is contained in:
parent
cb7335b4f0
commit
200550da3c
1 changed files with 9 additions and 6 deletions
|
@ -320,6 +320,10 @@ NSArray* ConvertSharingItemToNS(const SharingItem& item) {
|
|||
NSMenuItem* item = [[NSMenuItem alloc] initWithTitle:label
|
||||
action:@selector(itemSelected:)
|
||||
keyEquivalent:@""];
|
||||
if (model->IsEnabledAt(index))
|
||||
[item setEnabled:YES];
|
||||
else
|
||||
[item setEnabled:NO];
|
||||
|
||||
// If the menu item has an icon, set it.
|
||||
ui::ImageModel icon = model->GetIconAt(index);
|
||||
|
@ -349,11 +353,6 @@ NSArray* ConvertSharingItemToNS(const SharingItem& item) {
|
|||
[item setSubmenu:[self createShareMenuForItem:sharing_item]];
|
||||
} else if (type == electron::ElectronMenuModel::TYPE_SUBMENU &&
|
||||
model->IsVisibleAt(index)) {
|
||||
// We need to specifically check that the submenu top-level item has been
|
||||
// enabled as it's not validated by validateUserInterfaceItem
|
||||
if (!model->IsEnabledAt(index))
|
||||
[item setEnabled:NO];
|
||||
|
||||
// Recursively build a submenu from the sub-model at this index.
|
||||
[item setTarget:nil];
|
||||
[item setAction:nil];
|
||||
|
@ -493,8 +492,10 @@ NSArray* ConvertSharingItemToNS(const SharingItem& item) {
|
|||
}
|
||||
|
||||
- (NSMenu*)menu {
|
||||
if (menu_)
|
||||
if (menu_) {
|
||||
[menu_ setAutoenablesItems:NO];
|
||||
return menu_;
|
||||
}
|
||||
|
||||
if (model_ && model_->sharing_item()) {
|
||||
NSMenu* menu = [self createShareMenuForItem:*model_->sharing_item()];
|
||||
|
@ -504,6 +505,8 @@ NSArray* ConvertSharingItemToNS(const SharingItem& item) {
|
|||
if (model_)
|
||||
[self populateWithModel:model_.get()];
|
||||
}
|
||||
|
||||
[menu_ setAutoenablesItems:NO];
|
||||
[menu_ setDelegate:self];
|
||||
return menu_;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue