mirror of
https://github.com/zen-browser/components.git
synced 2025-07-08 13:49:59 +02:00
Refactor ZenWorkspaces to add event listener for TabBrowserInserted
This commit is contained in:
parent
da8446fc27
commit
f84a42cb7e
1 changed files with 39 additions and 9 deletions
|
@ -65,7 +65,7 @@ var ZenWorkspaces = {
|
||||||
|
|
||||||
async initializeWorkspaces() {
|
async initializeWorkspaces() {
|
||||||
Services.prefs.addObserver('zen.workspaces.enabled', this.onWorkspacesEnabledChanged.bind(this));
|
Services.prefs.addObserver('zen.workspaces.enabled', this.onWorkspacesEnabledChanged.bind(this));
|
||||||
this.initializeWorkspacesButton();
|
await this.initializeWorkspacesButton();
|
||||||
let file = new FileUtils.File(this._storeFile);
|
let file = new FileUtils.File(this._storeFile);
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
await IOUtils.writeJSON(this._storeFile, {});
|
await IOUtils.writeJSON(this._storeFile, {});
|
||||||
|
@ -240,6 +240,7 @@ var ZenWorkspaces = {
|
||||||
async _propagateWorkspaceData() {
|
async _propagateWorkspaceData() {
|
||||||
let currentContainer = document.getElementById('PanelUI-zen-workspaces-current-info');
|
let currentContainer = document.getElementById('PanelUI-zen-workspaces-current-info');
|
||||||
let workspaceList = document.getElementById('PanelUI-zen-workspaces-list');
|
let workspaceList = document.getElementById('PanelUI-zen-workspaces-list');
|
||||||
|
await this._expandWorkspacesStrip();
|
||||||
const createWorkspaceElement = (workspace) => {
|
const createWorkspaceElement = (workspace) => {
|
||||||
let element = document.createXULElement('toolbarbutton');
|
let element = document.createXULElement('toolbarbutton');
|
||||||
element.className = 'subviewbutton';
|
element.className = 'subviewbutton';
|
||||||
|
@ -336,7 +337,7 @@ var ZenWorkspaces = {
|
||||||
}).catch(console.error);
|
}).catch(console.error);
|
||||||
},
|
},
|
||||||
|
|
||||||
initializeWorkspacesButton() {
|
async initializeWorkspacesButton() {
|
||||||
if (!this.workspaceEnabled) {
|
if (!this.workspaceEnabled) {
|
||||||
return;
|
return;
|
||||||
} else if (document.getElementById('zen-workspaces-button')) {
|
} else if (document.getElementById('zen-workspaces-button')) {
|
||||||
|
@ -345,13 +346,42 @@ var ZenWorkspaces = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const nextSibling = document.getElementById('zen-sidepanel-button');
|
const nextSibling = document.getElementById('zen-sidepanel-button');
|
||||||
let button = document.createElement('toolbarbutton');
|
const wrapper = document.createXULElement('toolbarbutton');
|
||||||
button.id = 'zen-workspaces-button';
|
wrapper.id = 'zen-workspaces-buttons';
|
||||||
button.className = 'toolbarbutton-1 chromeclass-toolbar-additional';
|
wrapper.className = 'subviewbutton';
|
||||||
button.setAttribute('label', 'Workspaces');
|
nextSibling.before(wrapper);
|
||||||
button.setAttribute('tooltiptext', 'Workspaces');
|
await this._expandWorkspacesStrip();
|
||||||
button.onclick = this.openWorkspacesDialog.bind(this);
|
},
|
||||||
nextSibling.before(button);
|
|
||||||
|
async _expandWorkspacesStrip() {
|
||||||
|
let workspaces = await this._workspaces();
|
||||||
|
let activeWorkspace = workspaces.workspaces.find((workspace) => workspace.used);
|
||||||
|
let workspaceList = document.getElementById('zen-workspaces-buttons');
|
||||||
|
workspaceList.innerHTML = '';
|
||||||
|
for (let workspace of workspaces.workspaces) {
|
||||||
|
let button = document.createXULElement('toolbarbutton');
|
||||||
|
button.className = 'subviewbutton';
|
||||||
|
button.setAttribute('tooltiptext', workspace.name);
|
||||||
|
button.setAttribute('zen-workspace-id', workspace.uuid);
|
||||||
|
if (workspace.used) {
|
||||||
|
button.setAttribute('active', 'true');
|
||||||
|
}
|
||||||
|
if (workspace.default) {
|
||||||
|
button.setAttribute('default', 'true');
|
||||||
|
}
|
||||||
|
button.onclick = (async () => {
|
||||||
|
await this.changeWorkspace(workspace);
|
||||||
|
}).bind(this, workspace);
|
||||||
|
let icon = document.createXULElement('div');
|
||||||
|
icon.className = 'zen-workspace-icon';
|
||||||
|
icon.textContent = this.getWorkspaceIcon(workspace);
|
||||||
|
let name = document.createXULElement('div');
|
||||||
|
name.className = 'zen-workspace-name';
|
||||||
|
name.textContent = workspace.name;
|
||||||
|
button.appendChild(icon);
|
||||||
|
button.appendChild(name);
|
||||||
|
workspaceList.appendChild(button);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async _updateWorkspacesButton() {
|
async _updateWorkspacesButton() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue