| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/ui/tabs/tab_menu_model.h" | 5 #include "chrome/browser/ui/tabs/tab_menu_model.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 8 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 9 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
| 10 #include "grit/generated_resources.h" | 10 #include "grit/generated_resources.h" |
| 11 | 11 |
| 12 TabMenuModel::TabMenuModel(ui::SimpleMenuModel::Delegate* delegate, | 12 TabMenuModel::TabMenuModel(ui::SimpleMenuModel::Delegate* delegate, |
| 13 TabStripModel* tab_strip, | 13 TabStripModel* tab_strip, |
| 14 int index) | 14 int index) |
| 15 : ui::SimpleMenuModel(delegate) { | 15 : ui::SimpleMenuModel(delegate) { |
| 16 Build(tab_strip, index); | 16 Build(tab_strip, index); |
| 17 } | 17 } |
| 18 | 18 |
| 19 void TabMenuModel::Build(TabStripModel* tab_strip, int index) { | 19 void TabMenuModel::Build(TabStripModel* tab_strip, int index) { |
| 20 bool affects_multiple_tabs = | 20 bool affects_multiple_tabs = |
| 21 (tab_strip->IsTabSelected(index) && | 21 (tab_strip->IsTabSelected(index) && |
| 22 tab_strip->selection_model().selected_indices().size() > 1); | 22 tab_strip->selection_model().selected_indices().size() > 1); |
| 23 AddItemWithStringId(TabStripModel::CommandNewTab, IDS_TAB_CXMENU_NEWTAB); | 23 AddItemWithStringId(TabStripModel::CommandNewTab, IDS_TAB_CXMENU_NEWTAB); |
| 24 AddSeparator(); | 24 AddSeparator(ui::NORMAL_SEPARATOR); |
| 25 AddItemWithStringId(TabStripModel::CommandReload, IDS_TAB_CXMENU_RELOAD); | 25 AddItemWithStringId(TabStripModel::CommandReload, IDS_TAB_CXMENU_RELOAD); |
| 26 AddItemWithStringId(TabStripModel::CommandDuplicate, | 26 AddItemWithStringId(TabStripModel::CommandDuplicate, |
| 27 IDS_TAB_CXMENU_DUPLICATE); | 27 IDS_TAB_CXMENU_DUPLICATE); |
| 28 bool will_pin = tab_strip->WillContextMenuPin(index); | 28 bool will_pin = tab_strip->WillContextMenuPin(index); |
| 29 if (affects_multiple_tabs) { | 29 if (affects_multiple_tabs) { |
| 30 AddItemWithStringId( | 30 AddItemWithStringId( |
| 31 TabStripModel::CommandTogglePinned, | 31 TabStripModel::CommandTogglePinned, |
| 32 will_pin ? IDS_TAB_CXMENU_PIN_TABS : IDS_TAB_CXMENU_UNPIN_TABS); | 32 will_pin ? IDS_TAB_CXMENU_PIN_TABS : IDS_TAB_CXMENU_UNPIN_TABS); |
| 33 } else { | 33 } else { |
| 34 AddItemWithStringId( | 34 AddItemWithStringId( |
| 35 TabStripModel::CommandTogglePinned, | 35 TabStripModel::CommandTogglePinned, |
| 36 will_pin ? IDS_TAB_CXMENU_PIN_TAB : IDS_TAB_CXMENU_UNPIN_TAB); | 36 will_pin ? IDS_TAB_CXMENU_PIN_TAB : IDS_TAB_CXMENU_UNPIN_TAB); |
| 37 } | 37 } |
| 38 AddSeparator(); | 38 AddSeparator(ui::NORMAL_SEPARATOR); |
| 39 if (affects_multiple_tabs) { | 39 if (affects_multiple_tabs) { |
| 40 AddItemWithStringId(TabStripModel::CommandCloseTab, | 40 AddItemWithStringId(TabStripModel::CommandCloseTab, |
| 41 IDS_TAB_CXMENU_CLOSETABS); | 41 IDS_TAB_CXMENU_CLOSETABS); |
| 42 } else { | 42 } else { |
| 43 AddItemWithStringId(TabStripModel::CommandCloseTab, | 43 AddItemWithStringId(TabStripModel::CommandCloseTab, |
| 44 IDS_TAB_CXMENU_CLOSETAB); | 44 IDS_TAB_CXMENU_CLOSETAB); |
| 45 } | 45 } |
| 46 AddItemWithStringId(TabStripModel::CommandCloseOtherTabs, | 46 AddItemWithStringId(TabStripModel::CommandCloseOtherTabs, |
| 47 IDS_TAB_CXMENU_CLOSEOTHERTABS); | 47 IDS_TAB_CXMENU_CLOSEOTHERTABS); |
| 48 AddItemWithStringId(TabStripModel::CommandCloseTabsToRight, | 48 AddItemWithStringId(TabStripModel::CommandCloseTabsToRight, |
| 49 IDS_TAB_CXMENU_CLOSETABSTORIGHT); | 49 IDS_TAB_CXMENU_CLOSETABSTORIGHT); |
| 50 AddSeparator(); | 50 AddSeparator(ui::NORMAL_SEPARATOR); |
| 51 AddItemWithStringId(TabStripModel::CommandRestoreTab, IDS_RESTORE_TAB); | 51 AddItemWithStringId(TabStripModel::CommandRestoreTab, IDS_RESTORE_TAB); |
| 52 AddItemWithStringId(TabStripModel::CommandBookmarkAllTabs, | 52 AddItemWithStringId(TabStripModel::CommandBookmarkAllTabs, |
| 53 IDS_TAB_CXMENU_BOOKMARK_ALL_TABS); | 53 IDS_TAB_CXMENU_BOOKMARK_ALL_TABS); |
| 54 if (CommandLine::ForCurrentProcess()->HasSwitch( | 54 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 55 switches::kEnableTabGroupsContextMenu)) { | 55 switches::kEnableTabGroupsContextMenu)) { |
| 56 AddSeparator(); | 56 AddSeparator(ui::NORMAL_SEPARATOR); |
| 57 AddItemWithStringId(TabStripModel::CommandSelectByDomain, | 57 AddItemWithStringId(TabStripModel::CommandSelectByDomain, |
| 58 IDS_TAB_CXMENU_SELECT_BY_DOMAIN); | 58 IDS_TAB_CXMENU_SELECT_BY_DOMAIN); |
| 59 AddItemWithStringId(TabStripModel::CommandSelectByOpener, | 59 AddItemWithStringId(TabStripModel::CommandSelectByOpener, |
| 60 IDS_TAB_CXMENU_SELECT_BY_OPENER); | 60 IDS_TAB_CXMENU_SELECT_BY_OPENER); |
| 61 } | 61 } |
| 62 } | 62 } |
| OLD | NEW |