Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Unified Diff: chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm

Issue 2523053003: Mac: Fix errors in adding the "Paste & Go" menu item. (Closed)
Patch Set: gmock dance Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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];
}
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698