Bug 1944016 - Add new strings to tab context menu for switching to/from vertical tabs r=sidebar-reviewers,fluent-reviewers,tabbrowser-reviewers,dao,bolsson,nsharpley

Differential Revision: https://phabricator.services.mozilla.com/D236035
This commit is contained in:
Jonathan Sudiaman
2025-01-29 23:29:40 +00:00
parent bd5942f9f3
commit 70919ebe73
6 changed files with 68 additions and 0 deletions

View File

@@ -100,6 +100,8 @@
<menuitem id="context_fullscreenExit" <menuitem id="context_fullscreenExit"
contexttype="fullscreen" contexttype="fullscreen"
data-lazy-l10n-id="full-screen-exit"/> data-lazy-l10n-id="full-screen-exit"/>
<menuseparator/>
<menuitem id="context_toggleVerticalTabs" data-lazy-l10n-id="tab-context-enable-vertical-tabs"/>
</menupopup> </menupopup>
<menupopup id="open-tab-group-context-menu"> <menupopup id="open-tab-group-context-menu">

View File

@@ -104,6 +104,9 @@ document.addEventListener(
case "context_fullscreenExit": case "context_fullscreenExit":
BrowserCommands.fullScreen(); BrowserCommands.fullScreen();
break; break;
case "context_toggleVerticalTabs":
SidebarController.toggleVerticalTabs();
break;
// == open-tab-group-context-menu == // == open-tab-group-context-menu ==
case "open-tab-group-context-menu_moveToNewWindow": case "open-tab-group-context-menu_moveToNewWindow":

View File

@@ -521,6 +521,16 @@ var SidebarController = {
this.uiStateInitialized = true; this.uiStateInitialized = true;
}, },
/**
* Toggle the vertical tabs preference.
*/
toggleVerticalTabs() {
Services.prefs.setBoolPref(
"sidebar.verticalTabs",
!this.sidebarVerticalTabsEnabled
);
},
/** /**
* The handler for Services.obs.addObserver. * The handler for Services.obs.addObserver.
*/ */

View File

@@ -149,3 +149,41 @@ add_task(async function test_sidebar_extension_context_menu() {
await extension.unload(); await extension.unload();
await BrowserTestUtils.closeWindow(win); await BrowserTestUtils.closeWindow(win);
}); });
add_task(async function test_toggle_vertical_tabs_from_tab_strip() {
await SpecialPowers.pushPrefEnv({
set: [["sidebar.verticalTabs", false]],
});
info("Enable vertical tabs from the tab strip.");
const tabContextMenu = document.getElementById("tabContextMenu");
const toggleMenuItem = document.getElementById("context_toggleVerticalTabs");
await openAndWaitForContextMenu(tabContextMenu, gBrowser.selectedTab, () => {
Assert.deepEqual(
document.l10n.getAttributes(toggleMenuItem),
{ id: "tab-context-enable-vertical-tabs", args: null },
"Context menu item indicates that it enables vertical tabs."
);
toggleMenuItem.click();
});
await TestUtils.waitForCondition(
() => gBrowser.tabContainer.verticalMode,
"Vertical tabs are enabled."
);
info("Disable vertical tabs from the tab strip.");
await openAndWaitForContextMenu(tabContextMenu, gBrowser.selectedTab, () => {
Assert.deepEqual(
document.l10n.getAttributes(toggleMenuItem),
{ id: "tab-context-disable-vertical-tabs", args: null },
"Context menu item indicates that it disables vertical tabs."
);
toggleMenuItem.click();
});
await TestUtils.waitForCondition(
() => !gBrowser.tabContainer.verticalMode,
"Vertical tabs are disabled."
);
await SpecialPowers.popPrefEnv();
});

View File

@@ -8470,6 +8470,17 @@ var TabContextMenu = {
: "close-tabs-to-the-end" : "close-tabs-to-the-end"
); );
// Update context menu item for "Turn (on/off) Vertical Tabs".
const toggleVerticalTabsItem = document.getElementById(
"context_toggleVerticalTabs"
);
document.l10n.setAttributes(
toggleVerticalTabsItem,
gBrowser.tabContainer?.verticalMode
? "tab-context-disable-vertical-tabs"
: "tab-context-enable-vertical-tabs"
);
// Disable "Close Tabs to the Left/Right" if there are no tabs // Disable "Close Tabs to the Left/Right" if there are no tabs
// preceding/following it. // preceding/following it.
let noTabsToStart = !gBrowser._getTabsToTheStartFrom(this.contextTab) let noTabsToStart = !gBrowser._getTabsToTheStartFrom(this.contextTab)

View File

@@ -91,6 +91,10 @@ tab-context-close-duplicate-tabs =
tab-context-share-url = tab-context-share-url =
.label = Share .label = Share
.accesskey = h .accesskey = h
tab-context-enable-vertical-tabs =
.label = Turn on Vertical Tabs
tab-context-disable-vertical-tabs =
.label = Turn off Vertical Tabs
## Variables: ## Variables:
## $tabCount (Number): the number of tabs that are affected by the action. ## $tabCount (Number): the number of tabs that are affected by the action.