Refactor ZenWorkspaces to fix newWorkspacesButton height calculation

This commit is contained in:
mauro-balades 2024-09-20 13:33:01 +02:00
parent 20c2fc640f
commit 3c66cbdc24
2 changed files with 16 additions and 3 deletions

View file

@ -77,11 +77,11 @@ var ZenWorkspaces = {
async initializeWorkspaces() {
Services.prefs.addObserver('zen.workspaces.enabled', this.onWorkspacesEnabledChanged.bind(this));
Services.prefs.addObserver('zen.workspaces.show-icon-strip', this.onWorkspacesIconStripChanged.bind(this));
await this.initializeWorkspacesButton();
let file = new FileUtils.File(this._storeFile);
if (!file.exists()) {
await IOUtils.writeJSON(this._storeFile, {});
}
await this.initializeWorkspacesButton();
if (this.workspaceEnabled) {
this._initializeWorkspaceCreationIcons();
this._initializeWorkspaceEditIcons();
@ -391,7 +391,11 @@ var ZenWorkspaces = {
if (workspace.default) {
button.setAttribute('default', 'true');
}
button.onclick = (async () => {
button.onclick = (async (_, event) => {
// Make sure it's not a context menu event
if (event.button !== 0) {
return;
}
await this.changeWorkspace(workspace);
}).bind(this, workspace);
let icon = document.createXULElement('div');
@ -400,6 +404,11 @@ var ZenWorkspaces = {
button.appendChild(icon);
newWorkspacesButton.appendChild(button);
}
// Listen for context menu events and open the all workspaces dialog
newWorkspacesButton.addEventListener('contextmenu', (event) => {
event.preventDefault();
this.openWorkspacesDialog(event);
});
}
workspaceList.after(newWorkspacesButton);
@ -568,6 +577,10 @@ var ZenWorkspaces = {
let firstTab = undefined;
let workspaces = await this._workspaces();
for (let workspace of workspaces.workspaces) {
if (workspace.uuid === window.uuid && workspace.used) {
// If the workspace is already active, do nothing
return;
}
workspace.used = workspace.uuid === window.uuid;
}
await this.unsafeSaveWorkspaces(workspaces);