| Index: chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm
|
| diff --git a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm
|
| index 68dd4938a6aa5525e73194480b4eab0ebbdb7fa2..08967b88f7968048cac820cb3ef86f697bb445c3 100644
|
| --- a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm
|
| +++ b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm
|
| @@ -49,6 +49,24 @@ BOOL ThePasteboardIsTooDamnBig() {
|
| return [[pb stringForType:type] length] > kMaxPasteLength;
|
| }
|
|
|
| +// Returns a possibly disabled "Paste and {Go, Search}" menu item.
|
| +NSMenuItem* PasteAndGoMenuItemForObserver(
|
| + AutocompleteTextFieldObserver* observer) {
|
| + DCHECK(observer);
|
| + int string_id = IDS_PASTE_AND_GO;
|
| + BOOL enabled = !ThePasteboardIsTooDamnBig() && observer->CanPasteAndGo();
|
| + if (enabled)
|
| + string_id = observer->GetPasteActionStringId();
|
| +
|
| + NSString* title = l10n_util::GetNSStringWithFixup(string_id);
|
| + base::scoped_nsobject<NSMenuItem> item([[NSMenuItem alloc]
|
| + initWithTitle:title
|
| + action:@selector(pasteAndGo:)
|
| + keyEquivalent:@""]);
|
| + [item setEnabled:enabled];
|
| + return item.autorelease();
|
| +}
|
| +
|
| } // namespace
|
|
|
| @interface AutocompleteTextFieldEditor ()<NSDraggingSource>
|
| @@ -285,21 +303,8 @@ BOOL ThePasteboardIsTooDamnBig() {
|
| action:@selector(paste:)
|
| keyEquivalent:@""];
|
|
|
| - // TODO(shess): If the control is not editable, should we show a
|
| - // greyed-out "Paste and Go"?
|
| if ([self isEditable]) {
|
| - // Paste and go/search.
|
| - AutocompleteTextFieldObserver* observer = [self observer];
|
| - DCHECK(observer);
|
| - if (!ThePasteboardIsTooDamnBig()) {
|
| - NSString* pasteAndGoLabel =
|
| - l10n_util::GetNSStringWithFixup(observer->GetPasteActionStringId());
|
| - DCHECK([pasteAndGoLabel length]);
|
| - [menu addItemWithTitle:pasteAndGoLabel
|
| - action:@selector(pasteAndGo:)
|
| - keyEquivalent:@""];
|
| - }
|
| -
|
| + [menu addItem:PasteAndGoMenuItemForObserver([self observer])];
|
| [menu addItem:[NSMenuItem separatorItem]];
|
|
|
| NSString* searchEngineLabel =
|
| @@ -565,13 +570,12 @@ BOOL ThePasteboardIsTooDamnBig() {
|
| - (BOOL)validateMenuItem:(NSMenuItem*)item {
|
| if ([item action] == @selector(copyToFindPboard:))
|
| return [self selectedRange].length > 0;
|
| - if ([item action] == @selector(pasteAndGo:)) {
|
| - // TODO(rohitrao): If the clipboard is empty, should we show a
|
| - // greyed-out "Paste and Go" or nothing at all?
|
| - AutocompleteTextFieldObserver* observer = [self observer];
|
| - DCHECK(observer);
|
| - return observer->CanPasteAndGo();
|
| - }
|
| +
|
| + // Paste & Go doesn't appear in the mainMenu. Use the enabled state when the
|
| + // menu item was added in -menuForEvent:.
|
| + if ([item action] == @selector(pasteAndGo:))
|
| + return [item isEnabled];
|
| +
|
| return [super validateMenuItem:item];
|
| }
|
|
|
|
|