mirror of
https://github.com/zen-browser/components.git
synced 2025-07-10 04:55:30 +02:00
Refactor ZenWorkspaces to handle changing workspaces and update context menu
This commit is contained in:
parent
0a23df721e
commit
9a1beadc03
1 changed files with 15 additions and 9 deletions
|
@ -3,6 +3,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||||
* Stores workspace IDs and their last selected tabs.
|
* Stores workspace IDs and their last selected tabs.
|
||||||
*/
|
*/
|
||||||
_lastSelectedWorkspaceTabs = {};
|
_lastSelectedWorkspaceTabs = {};
|
||||||
|
_inChangingWorkspace = false;
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
if (!this.shouldHaveWorkspaces) {
|
if (!this.shouldHaveWorkspaces) {
|
||||||
|
@ -606,10 +607,11 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||||
}
|
}
|
||||||
|
|
||||||
async changeWorkspace(window, onInit = false) {
|
async changeWorkspace(window, onInit = false) {
|
||||||
if (!this.workspaceEnabled) {
|
if (!this.workspaceEnabled || this._inChangingWorkspace) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._inChangingWorkspace = true;
|
||||||
Services.prefs.setStringPref('zen.workspaces.active', window.uuid);
|
Services.prefs.setStringPref('zen.workspaces.active', window.uuid);
|
||||||
|
|
||||||
const shouldAllowPinnedTabs = this._shouldAllowPinTab;
|
const shouldAllowPinnedTabs = this._shouldAllowPinTab;
|
||||||
|
@ -657,13 +659,16 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||||
});
|
});
|
||||||
|
|
||||||
await this._propagateWorkspaceData();
|
await this._propagateWorkspaceData();
|
||||||
|
this._inChangingWorkspace = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async _updateWorkspacesChangeContextMenu() {
|
async _updateWorkspacesChangeContextMenu() {
|
||||||
const workspaces = await this._workspaces();
|
const workspaces = await this._workspaces();
|
||||||
|
|
||||||
const menuPopup = document.getElementById('context-zen-change-workspace-tab-menu-popup');
|
const menuPopup = document.getElementById('context-zen-change-workspace-tab-menu-popup');
|
||||||
|
if (!menuPopup) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
menuPopup.innerHTML = '';
|
menuPopup.innerHTML = '';
|
||||||
|
|
||||||
const activeWorkspace = await this.getActiveWorkspace();
|
const activeWorkspace = await this.getActiveWorkspace();
|
||||||
|
@ -715,17 +720,18 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||||
}
|
}
|
||||||
|
|
||||||
async onLocationChange(browser) {
|
async onLocationChange(browser) {
|
||||||
|
if (!this.workspaceEnabled || this._inChangingWorkspace) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const parent = browser.ownerGlobal;
|
||||||
let tab = gBrowser.getTabForBrowser(browser);
|
let tab = gBrowser.getTabForBrowser(browser);
|
||||||
let workspaceID = tab.getAttribute('zen-workspace-id');
|
let workspaceID = tab.getAttribute('zen-workspace-id');
|
||||||
if (!workspaceID) {
|
let activeWorkspace = await parent.ZenWorkspaces.getActiveWorkspace();
|
||||||
let activeWorkspace = await this.getActiveWorkspace();
|
if (workspaceID === activeWorkspace.uuid) {
|
||||||
if (!activeWorkspace || tab.hasAttribute('hidden')) {
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
tab.setAttribute('zen-workspace-id', activeWorkspace.uuid);
|
|
||||||
workspaceID = activeWorkspace.uuid;
|
|
||||||
}
|
}
|
||||||
this._lastSelectedWorkspaceTabs[workspaceID] = tab;
|
this._lastSelectedWorkspaceTabs[workspaceID] = tab;
|
||||||
|
await parent.ZenWorkspaces.changeWorkspace({ uuid: workspaceID });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Context menu management
|
// Context menu management
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue