mirror of
https://github.com/zen-browser/components.git
synced 2025-07-08 00:59:57 +02:00
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:
parent
b645656e6f
commit
6031981acd
2 changed files with 38 additions and 9 deletions
|
@ -513,7 +513,9 @@ class ZenBrowserManagerSidebar extends ZenDOMOperatedFeature {
|
|||
_createWebPanelBrowser(data) {
|
||||
const titleContainer = document.getElementById('zen-sidebar-web-panel-title');
|
||||
titleContainer.textContent = 'Loading...';
|
||||
let browser = gBrowser.createBrowser({});
|
||||
let browser = gBrowser.createBrowser({
|
||||
userContextId: data.userContextId,
|
||||
});
|
||||
const tab = this.sidebar.querySelector(`[zen-sidebar-id='${data.id}']`);
|
||||
this.setTabForBrowser(browser, tab);
|
||||
tab.linkedBrowser = browser;
|
||||
|
@ -692,6 +694,30 @@ class ZenBrowserManagerSidebar extends ZenDOMOperatedFeature {
|
|||
}
|
||||
}
|
||||
|
||||
createContainerTabMenu(event) {
|
||||
let window = event.target.ownerGlobal;
|
||||
let data = this.sidebarData;
|
||||
let panelData = data.data[this.contextTab];
|
||||
return window.createUserContextMenu(event, {
|
||||
isContextMenu: true,
|
||||
excludeUserContextId: panelData.userContextId,
|
||||
showDefaultTab: true,
|
||||
});
|
||||
}
|
||||
|
||||
contextChangeContainerTab(event) {
|
||||
let data = this.sidebarData;
|
||||
let userContextId = parseInt(event.target.getAttribute('data-usercontextid'));
|
||||
data.data[this.contextTab].userContextId = userContextId;
|
||||
Services.prefs.setStringPref('zen.sidebar.data', JSON.stringify(data));
|
||||
let browser = this._getBrowserById(this.contextTab);
|
||||
if (browser) {
|
||||
browser.remove();
|
||||
// We need to re-apply a new browser so it takes the new userContextId
|
||||
this._updateWebPanel();
|
||||
}
|
||||
}
|
||||
|
||||
contextOpenNewTab() {
|
||||
let browser = this._getBrowserById(this.contextTab);
|
||||
let data = this.sidebarData;
|
||||
|
|
|
@ -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)) ||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue