mirror of
https://github.com/zen-browser/components.git
synced 2025-07-07 21:49:59 +02:00
refactor: Remove unnecessary code in ZenViewSplitter.mjs and initialize workspace tab context menus in ZenWorkspaces.mjs
Remove the `insertSplitLinkIntoContextMenu` method in ZenViewSplitter.mjs as it is no longer needed. Additionally, initialize the workspace tab context menus in ZenWorkspaces.mjs to allow users to change the workspace of a tab. Refactor ZenViewSplitter.mjs: - Remove `insertSplitLinkIntoContextMenu` method Refactor ZenWorkspaces.mjs: - Initialize workspace tab context menus
This commit is contained in:
parent
bfda024538
commit
ccea9cbae7
2 changed files with 42 additions and 14 deletions
|
@ -109,18 +109,6 @@ var gZenViewSplitter = new class {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts the split link into the context menu.
|
||||
*/
|
||||
insertSplitLinkIntoContextMenu() {
|
||||
const element = window.MozXULElement.parseXULToFragment(`
|
||||
<menuitem id="context-split-with-newtab" data-l10n-id="floorp-split-view-open-menu"
|
||||
oncommand="gSplitView.splitLinkInNewTab();" hidden="true"/>
|
||||
<menuseparator id="context-stripOnShareLink"/>
|
||||
`);
|
||||
document.getElementById("context-stripOnShareLink").after(element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts the split view tab context menu item.
|
||||
*/
|
||||
|
@ -139,7 +127,6 @@ var gZenViewSplitter = new class {
|
|||
* Initializes the context menu.
|
||||
*/
|
||||
initializeContextMenu() {
|
||||
this.insertSplitLinkIntoContextMenu();
|
||||
this.insertSplitViewTabContextMenu();
|
||||
this.insetUpdateContextMenuItems();
|
||||
}
|
||||
|
|
|
@ -71,9 +71,12 @@ var ZenWorkspaces = {
|
|||
activeWorkspace.used = true;
|
||||
await this.saveWorkspaces();
|
||||
}
|
||||
await this.changeWorkspace(activeWorkspace, true);
|
||||
window.SessionStore.promiseInitialized.then(() => {
|
||||
this.changeWorkspace(activeWorkspace, true);
|
||||
});
|
||||
}
|
||||
this._initializeWorkspaceIcons();
|
||||
this._initializeWorkspaceTabContextMenus();
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -431,6 +434,44 @@ var ZenWorkspaces = {
|
|||
let nextWorkspace = workspaces.workspaces[workspaceIndex + 1] || workspaces.workspaces[0];
|
||||
this.changeWorkspace(nextWorkspace);
|
||||
},
|
||||
|
||||
_initializeWorkspaceTabContextMenus() {
|
||||
const contextMenu = document.getElementById("tabContextMenu");
|
||||
const element = window.MozXULElement.parseXULToFragment(`
|
||||
<menuseparator/>
|
||||
<menu id="context-zen-change-workspace-tab" data-l10n-id="context-zen-change-workspace-tab">
|
||||
<menupopup oncommand="ZenWorkspaces.changeTabWorkspace(event.target.getAttribute('zen-workspace-id'))">
|
||||
</menupopup>
|
||||
</menu>
|
||||
`);
|
||||
document.getElementById("context_closeDuplicateTabs").after(element);
|
||||
|
||||
contextMenu.addEventListener("popupshowing", async (event) => {
|
||||
const menu = document.getElementById("context-zen-change-workspace-tab").querySelector("menupopup");
|
||||
menu.innerHTML = "";
|
||||
const workspaces = await this._workspaces();
|
||||
const activeWorkspace = workspaces.workspaces.find(workspace => workspace.used);
|
||||
for (let workspace of workspaces.workspaces) {
|
||||
const menuItem = window.MozXULElement.parseXULToFragment(`
|
||||
<menuitem label="${workspace.name}" zen-workspace-id="${workspace.uuid}" />
|
||||
`);
|
||||
if (workspace.uuid === activeWorkspace.uuid) {
|
||||
menuItem.querySelector("menuitem").setAttribute("disabled", "true");
|
||||
}
|
||||
menu.appendChild(menuItem);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
async changeTabWorkspace(workspaceID) {
|
||||
const tabs = TabContextMenu.contextTab.multiselected
|
||||
? gBrowser.selectedTabs : [TabContextMenu.contextTab];
|
||||
for (let tab of tabs) {
|
||||
tab.setAttribute("zen-workspace-id", workspaceID);
|
||||
}
|
||||
const workspaces = await this._workspaces();
|
||||
await this.changeWorkspace(workspaces.workspaces.find(workspace => workspace.uuid === workspaceID));
|
||||
},
|
||||
};
|
||||
|
||||
ZenWorkspaces.init();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue