From 08eff6ec22b2b8548c66d26df740418b95234b7a Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Mon, 19 Aug 2013 21:40:16 +0100 Subject: [PATCH] New: grey out Edit menu non applicable items for text fields. Copy, cut and delete are now disabled if there's no selection in the active text field. Cut, paste and delete are greyed out if the text field is not editable (a label). Refs #1964. --- AppKit/CPTextField.j | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/AppKit/CPTextField.j b/AppKit/CPTextField.j index 732564800..d76c02b63 100644 --- a/AppKit/CPTextField.j +++ b/AppKit/CPTextField.j @@ -1765,6 +1765,23 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder"); [self _becomeFirstKeyResponder]; } +- (BOOL)validateUserInterfaceItem:(id )anItem +{ + var theAction = [anItem action]; + + if (![self isEditable] && (theAction == @selector(cut:) || theAction == @selector(paste:) || theAction == @selector(delete:))) + return NO; + + // FIXME - [self selectedRange] is always empty if we're not an editable field, so we must assume yes here. + if (![self isEditable]) + return YES; + + if (theAction == @selector(copy:) || theAction == @selector(cut:) || theAction == @selector(delete:)) + return [self selectedRange].length; + + return YES; +} + #pragma mark Private - (BOOL)_isWithinUsablePlatformRect