Commit 2d0443cb authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

mac: add "Close Other Tabs" and "Close Tabs To Right"

These two items are now in the Tab menu, reusing the existing
strings and machinery from the context menu. I considered
adding separate descriptor strings but it seemed like extra work
for no particular gain.

This is the design we settled on during our offline discussion :)

Bug: 1017344
Change-Id: I5fe6798d4bf0f217e3065373d43d0ec217a4bcb4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1913974Reviewed-by: default avatarGreg Thompson <grt@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#715267}
parent 3d1dd793
...@@ -102,6 +102,8 @@ ...@@ -102,6 +102,8 @@
#define IDC_SEND_TAB_TO_SELF_SINGLE_TARGET 35018 #define IDC_SEND_TAB_TO_SELF_SINGLE_TARGET 35018
#define IDC_CONTENT_LINK_SEND_TAB_TO_SELF_SINGLE_TARGET 35019 #define IDC_CONTENT_LINK_SEND_TAB_TO_SELF_SINGLE_TARGET 35019
#define IDC_QRCODE_GENERATOR 35020 #define IDC_QRCODE_GENERATOR 35020
#define IDC_WINDOW_CLOSE_TABS_TO_RIGHT 35021
#define IDC_WINDOW_CLOSE_OTHER_TABS 35022
// Page-manipulation commands that target a specified tab, which may not be the // Page-manipulation commands that target a specified tab, which may not be the
// active one. // active one.
......
...@@ -749,6 +749,12 @@ bool BrowserCommandController::ExecuteCommandWithDisposition( ...@@ -749,6 +749,12 @@ bool BrowserCommandController::ExecuteCommandWithDisposition(
case IDC_WINDOW_PIN_TAB: case IDC_WINDOW_PIN_TAB:
PinTab(browser_); PinTab(browser_);
break; break;
case IDC_WINDOW_CLOSE_TABS_TO_RIGHT:
CloseTabsToRight(browser_);
break;
case IDC_WINDOW_CLOSE_OTHER_TABS:
CloseOtherTabs(browser_);
break;
case IDC_SHOW_MANAGEMENT_PAGE: { case IDC_SHOW_MANAGEMENT_PAGE: {
ShowSingletonTab(browser_, GURL(kChromeUIManagementURL)); ShowSingletonTab(browser_, GURL(kChromeUIManagementURL));
break; break;
...@@ -1043,6 +1049,10 @@ void BrowserCommandController::InitCommandState() { ...@@ -1043,6 +1049,10 @@ void BrowserCommandController::InitCommandState() {
command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE, normal_window); command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE, normal_window);
command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB, normal_window); command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB, normal_window);
command_updater_.UpdateCommandEnabled(IDC_WINDOW_CLOSE_TABS_TO_RIGHT,
normal_window);
command_updater_.UpdateCommandEnabled(IDC_WINDOW_CLOSE_OTHER_TABS,
normal_window);
// Initialize other commands whose state changes based on various conditions. // Initialize other commands whose state changes based on various conditions.
UpdateCommandsForFullscreenMode(); UpdateCommandsForFullscreenMode();
...@@ -1126,6 +1136,10 @@ void BrowserCommandController::UpdateCommandsForTabState() { ...@@ -1126,6 +1136,10 @@ void BrowserCommandController::UpdateCommandsForTabState() {
!browser_->deprecated_is_app()); !browser_->deprecated_is_app());
command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB, command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB,
!browser_->deprecated_is_app()); !browser_->deprecated_is_app());
command_updater_.UpdateCommandEnabled(IDC_WINDOW_CLOSE_TABS_TO_RIGHT,
CanCloseTabsToRight(browser_));
command_updater_.UpdateCommandEnabled(IDC_WINDOW_CLOSE_OTHER_TABS,
CanCloseOtherTabs(browser_));
// Page-related commands // Page-related commands
window()->SetStarredState( window()->SetStarredState(
......
...@@ -727,6 +727,18 @@ bool CanDuplicateKeyboardFocusedTab(const Browser* browser) { ...@@ -727,6 +727,18 @@ bool CanDuplicateKeyboardFocusedTab(const Browser* browser) {
return CanDuplicateTabAt(browser, *GetKeyboardFocusedTabIndex(browser)); return CanDuplicateTabAt(browser, *GetKeyboardFocusedTabIndex(browser));
} }
bool CanCloseTabsToRight(const Browser* browser) {
return browser->tab_strip_model()->IsContextMenuCommandEnabled(
browser->tab_strip_model()->active_index(),
TabStripModel::CommandCloseTabsToRight);
}
bool CanCloseOtherTabs(const Browser* browser) {
return browser->tab_strip_model()->IsContextMenuCommandEnabled(
browser->tab_strip_model()->active_index(),
TabStripModel::CommandCloseOtherTabs);
}
WebContents* DuplicateTabAt(Browser* browser, int index) { WebContents* DuplicateTabAt(Browser* browser, int index) {
WebContents* contents = browser->tab_strip_model()->GetWebContentsAt(index); WebContents* contents = browser->tab_strip_model()->GetWebContentsAt(index);
CHECK(contents); CHECK(contents);
...@@ -837,6 +849,18 @@ void ConvertPopupToTabbedBrowser(Browser* browser) { ...@@ -837,6 +849,18 @@ void ConvertPopupToTabbedBrowser(Browser* browser) {
b->window()->Show(); b->window()->Show();
} }
void CloseTabsToRight(Browser* browser) {
browser->tab_strip_model()->ExecuteContextMenuCommand(
browser->tab_strip_model()->active_index(),
TabStripModel::CommandCloseTabsToRight);
}
void CloseOtherTabs(Browser* browser) {
browser->tab_strip_model()->ExecuteContextMenuCommand(
browser->tab_strip_model()->active_index(),
TabStripModel::CommandCloseOtherTabs);
}
void Exit() { void Exit() {
base::RecordAction(UserMetricsAction("Exit")); base::RecordAction(UserMetricsAction("Exit"));
chrome::AttemptUserExit(); chrome::AttemptUserExit();
......
...@@ -105,6 +105,8 @@ void SelectLastTab( ...@@ -105,6 +105,8 @@ void SelectLastTab(
void DuplicateTab(Browser* browser); void DuplicateTab(Browser* browser);
bool CanDuplicateTab(const Browser* browser); bool CanDuplicateTab(const Browser* browser);
bool CanDuplicateKeyboardFocusedTab(const Browser* browser); bool CanDuplicateKeyboardFocusedTab(const Browser* browser);
bool CanCloseTabsToRight(const Browser* browser);
bool CanCloseOtherTabs(const Browser* browser);
content::WebContents* DuplicateTabAt(Browser* browser, int index); content::WebContents* DuplicateTabAt(Browser* browser, int index);
bool CanDuplicateTabAt(const Browser* browser, int index); bool CanDuplicateTabAt(const Browser* browser, int index);
void MuteSite(Browser* browser); void MuteSite(Browser* browser);
...@@ -114,6 +116,8 @@ bool HasKeyboardFocusedTab(const Browser* browser); ...@@ -114,6 +116,8 @@ bool HasKeyboardFocusedTab(const Browser* browser);
void PinKeyboardFocusedTab(Browser* browser); void PinKeyboardFocusedTab(Browser* browser);
void DuplicateKeyboardFocusedTab(Browser* browser); void DuplicateKeyboardFocusedTab(Browser* browser);
void ConvertPopupToTabbedBrowser(Browser* browser); void ConvertPopupToTabbedBrowser(Browser* browser);
void CloseTabsToRight(Browser* browser);
void CloseOtherTabs(Browser* browser);
void Exit(); void Exit();
void BookmarkCurrentTabIgnoringExtensionOverrides(Browser* browser); void BookmarkCurrentTabIgnoringExtensionOverrides(Browser* browser);
void BookmarkCurrentTabAllowingExtensionOverrides(Browser* browser); void BookmarkCurrentTabAllowingExtensionOverrides(Browser* browser);
......
...@@ -420,6 +420,10 @@ base::scoped_nsobject<NSMenuItem> BuildTabMenu( ...@@ -420,6 +420,10 @@ base::scoped_nsobject<NSMenuItem> BuildTabMenu(
.command_id(IDC_PIN_TARGET_TAB) .command_id(IDC_PIN_TARGET_TAB)
.is_alternate() .is_alternate()
.key_equivalent(@"", NSAlternateKeyMask), .key_equivalent(@"", NSAlternateKeyMask),
Item(IDS_TAB_CXMENU_CLOSEOTHERTABS)
.command_id(IDC_WINDOW_CLOSE_OTHER_TABS),
Item(IDS_TAB_CXMENU_CLOSETABSTORIGHT)
.command_id(IDC_WINDOW_CLOSE_TABS_TO_RIGHT),
Item().is_separator(), Item().is_separator(),
}) })
.Build(); .Build();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment