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 "base/string_util.h" | 8 #include "base/string_util.h" |
8 #include "base/sys_string_conversions.h" | 9 #include "grit/generated_resources.h" |
9 | 10 |
10 @implementation AutocompleteTextFieldEditor | 11 @implementation AutocompleteTextFieldEditor |
11 | 12 |
12 - (void)copy:(id)sender { | 13 - (void)copy:(id)sender { |
13 NSPasteboard* pb = [NSPasteboard generalPasteboard]; | 14 NSPasteboard* pb = [NSPasteboard generalPasteboard]; |
14 [self performCopy:pb]; | 15 [self performCopy:pb]; |
15 } | 16 } |
16 | 17 |
17 - (void)cut:(id)sender { | 18 - (void)cut:(id)sender { |
18 NSPasteboard* pb = [NSPasteboard generalPasteboard]; | 19 NSPasteboard* pb = [NSPasteboard generalPasteboard]; |
(...skipping 19 matching lines...) Expand all Loading... |
38 } | 39 } |
39 return NO; | 40 return NO; |
40 } | 41 } |
41 | 42 |
42 - (void)paste:(id)sender { | 43 - (void)paste:(id)sender { |
43 if ([self shouldPaste]) { | 44 if ([self shouldPaste]) { |
44 [super paste:sender]; | 45 [super paste:sender]; |
45 } | 46 } |
46 } | 47 } |
47 | 48 |
| 49 - (void)pasteAndGo:sender { |
| 50 id delegate = [self delegate]; |
| 51 if ([delegate respondsToSelector:@selector(textDidPasteAndGo:)]) |
| 52 [delegate textDidPasteAndGo:self]; |
| 53 } |
| 54 |
48 // We have rich text, but it shouldn't be modified by the user, so | 55 // We have rich text, but it shouldn't be modified by the user, so |
49 // don't update the font panel. In theory, -setUsesFontPanel: should | 56 // don't update the font panel. In theory, -setUsesFontPanel: should |
50 // accomplish this, but that gets called frequently with YES when | 57 // accomplish this, but that gets called frequently with YES when |
51 // NSTextField and NSTextView synchronize their contents. That is | 58 // NSTextField and NSTextView synchronize their contents. That is |
52 // probably unavoidable because in most cases having rich text in the | 59 // probably unavoidable because in most cases having rich text in the |
53 // field you probably would expect it to update the font panel. | 60 // field you probably would expect it to update the font panel. |
54 - (void)updateFontPanel { | 61 - (void)updateFontPanel { |
55 } | 62 } |
56 | 63 |
57 // No ruler bar, so don't update any of that state, either. | 64 // No ruler bar, so don't update any of that state, either. |
58 - (void)updateRuler { | 65 - (void)updateRuler { |
59 } | 66 } |
60 | 67 |
| 68 - (NSMenu*)menuForEvent:(NSEvent*)event { |
| 69 NSMenu* menu = [[[NSMenu alloc] initWithTitle:@"TITLE"] autorelease]; |
| 70 [menu insertItemWithTitle:l10n_util::GetNSStringWithFixup(IDS_CUT) |
| 71 action:@selector(cut:) |
| 72 keyEquivalent:@"" atIndex:0]; |
| 73 [menu insertItemWithTitle:l10n_util::GetNSStringWithFixup(IDS_COPY) |
| 74 action:@selector(copy:) |
| 75 keyEquivalent:@"" atIndex:1]; |
| 76 [menu insertItemWithTitle:l10n_util::GetNSStringWithFixup(IDS_PASTE) |
| 77 action:@selector(paste:) |
| 78 keyEquivalent:@"" atIndex:2]; |
| 79 |
| 80 // Paste and go/search. |
| 81 id delegate = [self delegate]; |
| 82 |
| 83 if ([delegate respondsToSelector:@selector(textPasteActionString:)]) { |
| 84 NSString* label = [delegate textPasteActionString:self]; |
| 85 // TODO(rohitrao): If the clipboard is empty, should we show a greyed-out |
| 86 // "Paste and Go" or nothing at all? |
| 87 if (label) { |
| 88 [menu insertItemWithTitle:label action:@selector(pasteAndGo:) |
| 89 keyEquivalent:@"" atIndex:3]; |
| 90 } |
| 91 } |
| 92 |
| 93 return menu; |
| 94 } |
| 95 |
61 @end | 96 @end |
OLD | NEW |