From 62ced1749f6aeeb9b0579933cbf8968627c653c7 Mon Sep 17 00:00:00 2001 From: Aparajita Fishman Date: Wed, 27 Feb 2013 18:26:34 -0500 Subject: [PATCH] Fixed: invalid menu item validator was not checked properly Previously, if CPApplication -targetForAction:to:from: returned nil, no check was done to see if that failed because there was no action or no valid target. If the item had no item, no target, and to action binding, it would be left enabled, which was incorrect. This commit fixes the validation to disable the item if targetForAction:to:from: returns nil and the item has an action or target. --- AppKit/CPMenu/CPMenu.j | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/AppKit/CPMenu/CPMenu.j b/AppKit/CPMenu/CPMenu.j index 26ab8981c..8c00006d9 100644 --- a/AppKit/CPMenu/CPMenu.j +++ b/AppKit/CPMenu/CPMenu.j @@ -628,19 +628,26 @@ var _CPMenuBarVisible = NO, if (!validator) { - // Check to see if there is a target binding with a valid selector - var info = [CPBinder infoForBinding:CPTargetBinding forObject:item]; - - if (info) + // If targetForAction: returns nil, it could be that there is no action. + // If there is an action and nil is returned, no valid target could be found. + if ([item action] || [item target]) + [item setEnabled:NO]; + else { - var object = [info objectForKey:CPObservedObjectKey], - keyPath = [info objectForKey:CPObservedKeyPathKey], - options = [info objectForKey:CPOptionsKey], - target = [object valueForKeyPath:keyPath], - selector = [options valueForKey:CPSelectorNameBindingOption]; + // Check to see if there is a target binding with an invalid selector + var info = [CPBinder infoForBinding:CPTargetBinding forObject:item]; - if (target && selector && ![target respondsToSelector:CPSelectorFromString(selector)]) - [item setEnabled:NO]; + if (info) + { + var object = [info objectForKey:CPObservedObjectKey], + keyPath = [info objectForKey:CPObservedKeyPathKey], + options = [info objectForKey:CPOptionsKey], + target = [object valueForKeyPath:keyPath], + selector = [options valueForKey:CPSelectorNameBindingOption]; + + if (target && selector && ![target respondsToSelector:CPSelectorFromString(selector)]) + [item setEnabled:NO]; + } } } else if (![validator respondsToSelector:[item action]])