Chromium Code Reviews| Index: chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.mm |
| diff --git a/chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.mm b/chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.mm |
| index 6b02afd143884f37d3574a24baff44668fec413b..7bb91141b7cb4a0857c3235bb844aa2fa720eb54 100644 |
| --- a/chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.mm |
| +++ b/chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.mm |
| @@ -75,6 +75,20 @@ void RemoveMenuItemWithTag(NSMenuItem* top_level_item, |
| [submenu removeItem:nextItem]; |
| } |
| +void HideMenuItemWithIndex(NSMenuItem* top_level_item, |
|
tapted
2015/01/29 05:13:37
Comment for this function - e.g. it's a bit subtle
tapted
2015/01/29 05:13:37
Since it both hides and shows, a better name would
mitchellj
2015/01/30 00:06:57
Done.
|
| + NSInteger index, |
|
tapted
2015/01/29 05:13:37
could you use WithTag instead? combined with has_a
mitchellj
2015/01/30 00:06:57
Done.
|
| + bool hidden, |
| + bool isAlternateMenuItem) { |
|
tapted
2015/01/29 05:13:37
since this isn't an Objective C method, use hacker
mitchellj
2015/01/30 00:06:57
Done.
|
| + NSMenu* submenu = [top_level_item submenu]; |
| + if (index >= [submenu numberOfItems]) |
|
tapted
2015/01/29 05:13:37
if this ever hit? DCHECK instead?
mitchellj
2015/01/30 00:06:57
This is now checked, as we are grabbing the next m
|
| + return; |
| + |
| + NSMenuItem* menuItem = [submenu itemAtIndex:index]; |
| + if (isAlternateMenuItem) |
| + [menuItem setAlternate:!hidden]; |
| + [menuItem setHidden:hidden]; |
| +} |
| + |
| } // namespace |
| // Used by AppShimMenuController to manage menu items that are a copy of a |
| @@ -270,14 +284,10 @@ void RemoveMenuItemWithTag(NSMenuItem* top_level_item, |
| [closeWindowMenuItem setKeyEquivalent:@"w"]; |
| [closeWindowMenuItem setKeyEquivalentModifierMask:NSCommandKeyMask]; |
| - // Edit menu. This copies the menu entirely and removes |
| - // "Paste and Match Style" and "Find". This is because the last two items, |
| - // "Start Dictation" and "Special Characters" are added by OSX, so we can't |
| - // copy them explicitly. |
| + // Edit menu. We copy the menu because the last two items, "Start Dictation" |
| + // and "Special Characters" are added by OSX, so we can't copy them |
| + // explicitly. |
| editMenuItem_.reset([[[NSApp mainMenu] itemWithTag:IDC_EDIT_MENU] copy]); |
| - RemoveMenuItemWithTag(editMenuItem_, |
| - IDC_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE, NO); |
| - RemoveMenuItemWithTag(editMenuItem_, IDC_FIND_MENU, NO); |
| // View menu. Remove "Always Show Bookmark Bar" and separator. |
| viewMenuItem_.reset([[[NSApp mainMenu] itemWithTag:IDC_VIEW_MENU] copy]); |
| @@ -379,7 +389,28 @@ void RemoveMenuItemWithTag(NSMenuItem* top_level_item, |
| [mainMenu addItem:appMenuItem_]; |
| [mainMenu addItem:fileMenuItem_]; |
| + |
| + // Hide the "Paste and Match Style" and "Find" menu items for non-hosted |
| + // apps from the Edit menu. |
| + NSInteger pasteMatchStyleindex = [[editMenuItem_ submenu] |
|
tapted
2015/01/29 05:13:37
index -> Index
mitchellj
2015/01/30 00:06:57
Done.
|
| + indexOfItemWithTag:IDC_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE]; |
| + if (!app->is_hosted_app()) { |
| + // We need to hide the alternate menu item to "Patch and Match Style" |
|
tapted
2015/01/29 05:13:37
I'd say this more like
// AppKit requires that al
mitchellj
2015/01/30 00:06:57
Done. Moved this comment to the new function SetIt
|
| + // first. |
| + HideMenuItemWithIndex(editMenuItem_, pasteMatchStyleindex + 1, YES, YES); |
|
tapted
2015/01/29 05:13:37
since they are being passed to bool (not BOOL) use
mitchellj
2015/01/30 00:06:57
Done.
|
| + HideMenuItemWithIndex(editMenuItem_, pasteMatchStyleindex, YES, NO); |
| + HideMenuItemWithIndex( |
| + editMenuItem_, |
| + [[editMenuItem_ submenu] indexOfItemWithTag:IDC_FIND_MENU], YES, NO); |
|
tapted
2015/01/29 05:13:37
nit: make a temporary for this, same as pasteMatch
mitchellj
2015/01/30 00:06:57
Done.
|
| + } else { |
| + HideMenuItemWithIndex(editMenuItem_, pasteMatchStyleindex + 1, NO, YES); |
| + HideMenuItemWithIndex(editMenuItem_, pasteMatchStyleindex, NO, NO); |
| + HideMenuItemWithIndex( |
| + editMenuItem_, |
| + [[editMenuItem_ submenu] indexOfItemWithTag:IDC_FIND_MENU], NO, NO); |
| + } |
| [mainMenu addItem:editMenuItem_]; |
| + |
| if (app->is_hosted_app()) { |
| [mainMenu addItem:viewMenuItem_]; |
| [mainMenu addItem:historyMenuItem_]; |