OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "chrome/browser/cocoa/autocomplete_text_field_editor.h" | 5 #import "chrome/browser/cocoa/autocomplete_text_field_editor.h" |
6 | 6 |
7 #include "app/l10n_util_mac.h" | 7 #include "app/l10n_util_mac.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "grit/generated_resources.h" | 9 #include "grit/generated_resources.h" |
10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 | 49 |
50 - (void)paste:(id)sender { | 50 - (void)paste:(id)sender { |
51 AutocompleteTextFieldObserver* observer = [self observer]; | 51 AutocompleteTextFieldObserver* observer = [self observer]; |
52 DCHECK(observer); | 52 DCHECK(observer); |
53 if (observer) { | 53 if (observer) { |
54 observer->OnPaste(); | 54 observer->OnPaste(); |
55 } | 55 } |
56 } | 56 } |
57 | 57 |
58 - (void)pasteAndGo:sender { | 58 - (void)pasteAndGo:sender { |
59 id delegate = [self delegate]; | 59 AutocompleteTextFieldObserver* observer = [self observer]; |
60 if ([delegate respondsToSelector:@selector(textDidPasteAndGo:)]) | 60 DCHECK(observer); |
61 [delegate textDidPasteAndGo:self]; | 61 if (observer) { |
| 62 observer->OnPasteAndGo(); |
| 63 } |
62 } | 64 } |
63 | 65 |
64 // We have rich text, but it shouldn't be modified by the user, so | 66 // We have rich text, but it shouldn't be modified by the user, so |
65 // don't update the font panel. In theory, -setUsesFontPanel: should | 67 // don't update the font panel. In theory, -setUsesFontPanel: should |
66 // accomplish this, but that gets called frequently with YES when | 68 // accomplish this, but that gets called frequently with YES when |
67 // NSTextField and NSTextView synchronize their contents. That is | 69 // NSTextField and NSTextView synchronize their contents. That is |
68 // probably unavoidable because in most cases having rich text in the | 70 // probably unavoidable because in most cases having rich text in the |
69 // field you probably would expect it to update the font panel. | 71 // field you probably would expect it to update the font panel. |
70 - (void)updateFontPanel { | 72 - (void)updateFontPanel { |
71 } | 73 } |
72 | 74 |
73 // No ruler bar, so don't update any of that state, either. | 75 // No ruler bar, so don't update any of that state, either. |
74 - (void)updateRuler { | 76 - (void)updateRuler { |
75 } | 77 } |
76 | 78 |
77 - (NSMenu*)menuForEvent:(NSEvent*)event { | 79 - (NSMenu*)menuForEvent:(NSEvent*)event { |
78 NSMenu* menu = [[[NSMenu alloc] initWithTitle:@"TITLE"] autorelease]; | 80 NSMenu* menu = [[[NSMenu alloc] initWithTitle:@"TITLE"] autorelease]; |
79 [menu insertItemWithTitle:l10n_util::GetNSStringWithFixup(IDS_CUT) | 81 [menu addItemWithTitle:l10n_util::GetNSStringWithFixup(IDS_CUT) |
80 action:@selector(cut:) | 82 action:@selector(cut:) |
81 keyEquivalent:@"" atIndex:0]; | 83 keyEquivalent:@""]; |
82 [menu insertItemWithTitle:l10n_util::GetNSStringWithFixup(IDS_COPY) | 84 [menu addItemWithTitle:l10n_util::GetNSStringWithFixup(IDS_COPY) |
83 action:@selector(copy:) | 85 action:@selector(copy:) |
84 keyEquivalent:@"" atIndex:1]; | 86 keyEquivalent:@""]; |
85 [menu insertItemWithTitle:l10n_util::GetNSStringWithFixup(IDS_PASTE) | 87 [menu addItemWithTitle:l10n_util::GetNSStringWithFixup(IDS_PASTE) |
86 action:@selector(paste:) | 88 action:@selector(paste:) |
87 keyEquivalent:@"" atIndex:2]; | 89 keyEquivalent:@""]; |
88 | 90 |
89 // Paste and go/search. | 91 // Paste and go/search. |
90 id delegate = [self delegate]; | 92 AutocompleteTextFieldObserver* observer = [self observer]; |
| 93 DCHECK(observer); |
| 94 if (observer && observer->CanPasteAndGo()) { |
| 95 const int string_id = observer->GetPasteActionStringId(); |
| 96 NSString* label = l10n_util::GetNSStringWithFixup(string_id); |
91 | 97 |
92 if ([delegate respondsToSelector:@selector(textPasteActionString:)]) { | 98 // TODO(rohitrao): If the clipboard is empty, should we show a |
93 NSString* label = [delegate textPasteActionString:self]; | 99 // greyed-out "Paste and Go" or nothing at all? |
94 // TODO(rohitrao): If the clipboard is empty, should we show a greyed-out | |
95 // "Paste and Go" or nothing at all? | |
96 if (label) { | 100 if (label) { |
97 [menu insertItemWithTitle:label action:@selector(pasteAndGo:) | 101 [menu addItemWithTitle:label |
98 keyEquivalent:@"" atIndex:3]; | 102 action:@selector(pasteAndGo:) |
| 103 keyEquivalent:@""]; |
99 } | 104 } |
100 } | 105 } |
101 | 106 |
102 return menu; | 107 return menu; |
103 } | 108 } |
104 | 109 |
105 @end | 110 @end |
OLD | NEW |