diff --git a/src/platform/macos/menu_macos.mm b/src/platform/macos/menu_macos.mm index ffb280a..2f2a18f 100644 --- a/src/platform/macos/menu_macos.mm +++ b/src/platform/macos/menu_macos.mm @@ -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 @@ -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) @@ -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() {