Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binding an NSMenuItem's title breaks enabled/disabled validation

I have a menu where some of the menu items use bindings to get their title. These items are always enabled, and don't neither automatically enable/disable like they should NOR do they cause a call to validateUserInterfaceItem:. If you remove the binding on title, then that starts working again. The menu items have the target set to nil (First Responder). If you click on one, it does execute the selector (action).

Bug? What to do?

like image 827
Paul Avatar asked Jul 26 '10 17:07

Paul


1 Answers

For some reason when you set a menu item's title with bindings, the menu item becomes enabled even if the target/action are nil.

If you want to permanently disable the menu item you can workaround this by binding the menu item's enabled status to a constant NO:

NSNumber *alwaysNo = [NSNumber numberWithBool:NO];
[menuItem bind:@"enabled" toObject:alwaysNo withKeyPath:@"boolValue" options:nil];

Note that this isn't the most elegant workaround, but in my case it was still cleaner than not using bindings for the title.

like image 171
Philipp Avatar answered Nov 22 '22 04:11

Philipp