Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/platform/macos/menu_macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ - (void)menuItemClicked:(id)sender {
if (!menu_item)
return;

// Ignore clicks on disabled items as an extra safety net.
if (![menu_item isEnabled])
return;

// Call the block if it exists
if (_clickedBlock) {
// Get the MenuItemId from the menu item's associated object
Expand Down Expand Up @@ -162,6 +166,14 @@ - (void)menuWillOpen:(NSMenu*)menu {
}
}

- (BOOL)menu:(NSMenu*)menu validateMenuItem:(NSMenuItem*)item {
// Respect the programmatically set enabled state on NSMenuItem.
// Without this override, NSMenu's default autoenablesItems (YES)
// would re-enable all items whose target responds to the action,
// overriding explicit setEnabled:NO calls.
return [item isEnabled];
}

- (void)menuDidClose:(NSMenu*)menu {
@try {
if (!menu)
Expand Down Expand Up @@ -509,6 +521,8 @@ - (void)menuDidClose:(NSMenu*)menu {
Impl(MenuId id, NSMenu* menu)
: id_(id), ns_menu_(menu), delegate_([[NSMenuDelegateImpl alloc] init]) {
[ns_menu_ setDelegate:delegate_];
// Disable auto-enabling so explicit setEnabled: calls are respected.
[ns_menu_ setAutoenablesItems:NO];
}

~Impl() {
Expand Down
Loading