Refactor ZenSidebarManager and ZenWorkspaces

This commit refactors the ZenSidebarManager and ZenWorkspaces classes. In ZenSidebarManager, the _createWebPanelBrowser method now includes the userContextId when creating a new browser. Additionally, a new method createContainerTabMenu is added to handle the creation of a context menu for container tabs. The contextChangeContainerTab method is also added to handle changing the userContextId for a container tab.

In ZenWorkspaces, the ownerWindow property is now set to the window object. The _contextMenuId property is now bound to the ZenWorkspaces instance. The onclick event handler is modified to use the ownerWindow property and the changeWorkspace method is now called on the ZenWorkspaces instance.

These changes improve the functionality and maintainability of the ZenSidebarManager and ZenWorkspaces classes.
This commit is contained in:
mr. M 2024-10-14 18:31:05 +02:00
parent b645656e6f
commit 6031981acd
No known key found for this signature in database
GPG key ID: CBD57A2AEDBDA1FB
2 changed files with 38 additions and 9 deletions

View file

@ -10,6 +10,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
console.warn('ZenWorkspaces: !!! ZenWorkspaces is disabled in hidden windows !!!');
return; // We are in a hidden window, don't initialize ZenWorkspaces
}
this.ownerWindow = window;
console.info('ZenWorkspaces: Initializing ZenWorkspaces...');
XPCOMUtils.defineLazyPreferenceGetter(
this,
@ -339,24 +340,27 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
);
}
childs.querySelector('.zen-workspace-actions').addEventListener('command', (event) => {
childs.querySelector('.zen-workspace-actions').addEventListener('command', ((event) => {
let button = event.target;
browser.ZenWorkspaces._contextMenuId = button
this._contextMenuId = button
.closest('toolbarbutton[zen-workspace-id]')
.getAttribute('zen-workspace-id');
const popup = button.ownerDocument.getElementById('zenWorkspaceActionsMenu');
popup.openPopup(button, 'after_end');
});
}).bind(browser.ZenWorkspaces));
element.appendChild(childs);
element.onclick = (async () => {
if (event.target.closest('.zen-workspace-actions')) {
return; // Ignore clicks on the actions button
}
await browser.ZenWorkspaces.changeWorkspace(workspace);
let panel = browser.document.getElementById('PanelUI-zen-workspaces');
const workspaceId = element.getAttribute('zen-workspace-id');
const workspaces = await this._workspaces();
const workspace = workspaces.workspaces.find((w) => w.uuid === workspaceId);
await this.changeWorkspace(workspace);
let panel = this.ownerWindow.document.getElementById('PanelUI-zen-workspaces');
PanelMultiView.hidePopup(panel);
browser.document.getElementById('zen-workspaces-button').removeAttribute('open');
}).bind(browser.ZenWorkspaces, workspace, browser);
this.ownerWindow.document.getElementById('zen-workspaces-button').removeAttribute('open');
}).bind(browser.ZenWorkspaces);
return element;
};
browser.ZenWorkspaces._workspaceCache = null;
@ -624,7 +628,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
const shouldAllowPinnedTabs = this._shouldAllowPinTab;
this.tabContainer._invalidateCachedTabs();
let firstTab = undefined;
console.info('ZenWorkspaces: Changing workspace to', window.uuid);
for (let tab of gBrowser.tabs) {
if (
(tab.getAttribute('zen-workspace-id') === window.uuid && !(tab.pinned && !shouldAllowPinnedTabs)) ||