diff --git a/src/browser/base/zen-components/ZenWorkspaces.mjs b/src/browser/base/zen-components/ZenWorkspaces.mjs
index 9e5aa724e..f3778ca86 100644
--- a/src/browser/base/zen-components/ZenWorkspaces.mjs
+++ b/src/browser/base/zen-components/ZenWorkspaces.mjs
@@ -6,7 +6,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
_inChangingWorkspace = false;
draggedElement = null;
-
_swipeState = {
isGestureActive: true,
cumulativeDelta: 0,
@@ -15,7 +14,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
_hoveringSidebar = false;
_lastScrollTime = 0;
-
async init() {
if (!this.shouldHaveWorkspaces) {
document.getElementById('zen-current-workspace-indicator').setAttribute('hidden', 'true');
@@ -53,48 +51,39 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
await ZenWorkspacesStorage.init();
}
-
async _delayedStartup() {
await this.initializeWorkspaces();
console.info('ZenWorkspaces: ZenWorkspaces initialized');
-
if (Services.prefs.getBoolPref('zen.workspaces.swipe-actions', false) && this.workspaceEnabled) {
this.initializeGestureHandlers();
this.initializeWorkspaceNavigation();
}
-
Services.obs.addObserver(this, 'weave:engine:sync:finish');
}
-
initializeWorkspaceNavigation() {
this._setupAppCommandHandlers();
this._setupSidebarHandlers();
}
-
_setupAppCommandHandlers() {
// Remove existing handler temporarily - this is needed so that _handleAppCommand is called before the original
window.removeEventListener("AppCommand", HandleAppCommandEvent, true);
-
// Add our handler first
window.addEventListener("AppCommand", this._handleAppCommand.bind(this), true);
-
// Re-add original handler
window.addEventListener("AppCommand", HandleAppCommandEvent, true);
}
-
_handleAppCommand(event) {
if (!this.workspaceEnabled || !this._hoveringSidebar) {
return;
}
-
switch (event.command) {
case "Forward":
this.changeWorkspaceShortcut(1);
@@ -181,8 +170,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
-
-
initializeGestureHandlers() {
const elements = [
document.getElementById('navigator-toolbox'),
@@ -190,17 +177,14 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
document.getElementById("tabbrowser-arrowscrollbox").shadowRoot.querySelector("scrollbox"),
];
-
// Attach gesture handlers to each element
for (const element of elements) {
if (!element) continue;
-
this.attachGestureHandlers(element);
}
}
-
attachGestureHandlers(element) {
element.addEventListener('MozSwipeGestureMayStart', this._handleSwipeMayStart.bind(this), true);
element.addEventListener('MozSwipeGestureStart', this._handleSwipeStart.bind(this), true);
@@ -208,31 +192,25 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
element.addEventListener('MozSwipeGestureEnd', this._handleSwipeEnd.bind(this), true);
}
-
_handleSwipeMayStart(event) {
if (!this.workspaceEnabled) return;
-
// Only handle horizontal swipes
if (event.direction === event.DIRECTION_LEFT || event.direction === event.DIRECTION_RIGHT) {
event.preventDefault();
event.stopPropagation();
-
// Set allowed directions based on available workspaces
event.allowedDirections |= event.DIRECTION_LEFT | event.DIRECTION_RIGHT;
}
}
-
_handleSwipeStart(event) {
if (!this.workspaceEnabled) return;
-
event.preventDefault();
event.stopPropagation();
-
this._swipeState = {
isGestureActive: true,
cumulativeDelta: 0,
@@ -240,28 +218,22 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
};
}
-
_handleSwipeUpdate(event) {
if (!this.workspaceEnabled || !this._swipeState?.isGestureActive) return;
-
event.preventDefault();
event.stopPropagation();
-
// Update cumulative delta
this._swipeState.cumulativeDelta += event.delta;
-
// Determine swipe direction based on cumulative delta
if (Math.abs(this._swipeState.cumulativeDelta) > 0.04) {
this._swipeState.direction = this._swipeState.cumulativeDelta > 0 ? 'right' : 'left';
}
-
}
-
async _handleSwipeEnd(event) {
if (!this.workspaceEnabled || !this._swipeState?.isGestureActive) return;
event.preventDefault();
@@ -292,8 +264,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}
}
}
-
-
// Reset swipe state
this._swipeState = {
@@ -303,24 +273,20 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
};
}
-
get activeWorkspace() {
return this._activeWorkspace;
}
-
set activeWorkspace(value) {
this._activeWorkspace = value;
Services.prefs.setStringPref('zen.workspaces.active', value);
}
-
async observe(subject, topic, data) {
if (topic === 'weave:engine:sync:finish' && data === 'workspaces') {
try {
const lastChangeTimestamp = await ZenWorkspacesStorage.getLastChangeTimestamp();
-
if (
!this._workspaceCache ||
!this._workspaceCache.lastChangeTimestamp ||
@@ -328,7 +294,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
) {
await this._propagateWorkspaceData();
-
const currentWorkspace = await this.getActiveWorkspace();
await gZenThemePicker.onWorkspaceChange(currentWorkspace);
}
@@ -338,7 +303,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}
}
-
get shouldHaveWorkspaces() {
if (typeof this._shouldHaveWorkspaces === 'undefined') {
let docElement = document.documentElement;
@@ -352,7 +316,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
return this._shouldHaveWorkspaces;
}
-
get workspaceEnabled() {
if (typeof this._workspaceEnabled === 'undefined') {
this._workspaceEnabled = Services.prefs.getBoolPref('zen.workspaces.enabled', false) && this.shouldHaveWorkspaces;
@@ -361,7 +324,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
return this._workspaceEnabled;
}
-
getActiveWorkspaceFromCache() {
try {
return this._workspaceCache.workspaces.find((workspace) => workspace.uuid === this.activeWorkspace);
@@ -370,24 +332,20 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}
}
-
async _workspaces() {
if (this._workspaceCache) {
return this._workspaceCache;
}
-
const [workspaces, lastChangeTimestamp] = await Promise.all([
ZenWorkspacesStorage.getWorkspaces(),
ZenWorkspacesStorage.getLastChangeTimestamp(),
]);
-
this._workspaceCache = { workspaces, lastChangeTimestamp };
// Get the active workspace ID from preferences
const activeWorkspaceId = this.activeWorkspace;
-
if (activeWorkspaceId) {
const activeWorkspace = this._workspaceCache.workspaces.find((w) => w.uuid === activeWorkspaceId);
// Set the active workspace ID to the first one if the one with selected id doesn't exist
@@ -401,11 +359,9 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
// sort by position
this._workspaceCache.workspaces.sort((a, b) => (a.position ?? Infinity) - (b.position ?? Infinity));
-
return this._workspaceCache;
}
-
async onWorkspacesEnabledChanged() {
if (this.workspaceEnabled) {
throw Error("Shoud've had reloaded the window");
@@ -418,11 +374,9 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}
}
-
async initializeWorkspaces() {
Services.prefs.addObserver('zen.workspaces.enabled', this.onWorkspacesEnabledChanged.bind(this));
-
await this.initializeWorkspacesButton();
if (this.workspaceEnabled) {
this._initializeWorkspaceCreationIcons();
@@ -453,7 +407,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
this.initIndicatorContextMenu();
}
-
initIndicatorContextMenu() {
const indicator = document.getElementById('zen-current-workspace-indicator');
const th = (event) => {
@@ -465,54 +418,44 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
indicator.addEventListener('click', th);
}
-
handleTabBeforeClose(tab) {
if (!this.workspaceEnabled || this.__contextIsDelete) {
return null;
}
-
let workspaceID = tab.getAttribute('zen-workspace-id');
if (!workspaceID) {
return null;
}
-
const shouldOpenNewTabIfLastUnpinnedTabIsClosed = this.shouldOpenNewTabIfLastUnpinnedTabIsClosed;
-
let tabs = gBrowser.tabs.filter(t =>
t.getAttribute('zen-workspace-id') === workspaceID &&
(!shouldOpenNewTabIfLastUnpinnedTabIsClosed ||!t.pinned || t.getAttribute("pending") !== "true")
);
-
if (tabs.length === 1 && tabs[0] === tab) {
let newTab = this._createNewTabForWorkspace({ uuid: workspaceID });
return newTab;
}
-
return null;
}
-
_createNewTabForWorkspace(window) {
let tab = gZenUIManager.openAndChangeToTab(Services.prefs.getStringPref('browser.startup.homepage'));
-
if(window.uuid){
tab.setAttribute('zen-workspace-id', window.uuid);
}
return tab;
}
-
_kIcons = JSON.parse(Services.prefs.getStringPref('zen.workspaces.icons')).map((icon) =>
typeof Intl.Segmenter !== 'undefined' ? new Intl.Segmenter().segment(icon).containing().segment : Array.from(icon)[0]
);
-
_initializeWorkspaceCreationIcons() {
let container = document.getElementById('PanelUI-zen-workspaces-icon-picker-wrapper');
for (let icon of this._kIcons) {
@@ -538,14 +481,12 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}
}
-
async saveWorkspace(workspaceData) {
await ZenWorkspacesStorage.saveWorkspace(workspaceData);
await this._propagateWorkspaceData();
await this._updateWorkspacesChangeContextMenu();
}
-
async removeWorkspace(windowID) {
let workspacesData = await this._workspaces();
console.info('ZenWorkspaces: Removing workspace', windowID);
@@ -557,23 +498,19 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
await this._updateWorkspacesChangeContextMenu();
}
-
isWorkspaceActive(workspace) {
return workspace.uuid === this.activeWorkspace;
}
-
async getActiveWorkspace() {
const workspaces = await this._workspaces();
return workspaces.workspaces.find((workspace) => workspace.uuid === this.activeWorkspace) ?? workspaces.workspaces[0];
}
// Workspaces dialog UI management
-
openSaveDialog() {
let parentPanel = document.getElementById('PanelUI-zen-workspaces-multiview');
-
// randomly select an icon
let icon = this._kIcons[Math.floor(Math.random() * this._kIcons.length)];
this._workspaceCreateInput.textContent = '';
@@ -588,11 +525,9 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
});
document.querySelector('.PanelUI-zen-workspaces-icons-container.create').textContent = icon;
-
PanelUI.showSubView('PanelUI-zen-workspaces-create', parentPanel);
}
-
async openEditDialog(workspaceUuid) {
this._workspaceEditDialog.setAttribute('data-workspace-uuid', workspaceUuid);
document.getElementById('PanelUI-zen-workspaces-edit-save').setAttribute('disabled', 'true');
@@ -618,7 +553,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
PanelUI.showSubView('PanelUI-zen-workspaces-edit', parentPanel);
}
-
onWorkspaceIconChangeInner(type = 'create', icon) {
const container = document.querySelector(`.PanelUI-zen-workspaces-icons-container.${type}`);
if (container.textContent !== icon) {
@@ -627,25 +561,21 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
this.goToPreviousSubView();
}
-
onWorkspaceIconContainerClick(event) {
event.preventDefault();
const parentPanel = document.getElementById('PanelUI-zen-workspaces-edit');
PanelUI.showSubView('PanelUI-zen-workspaces-icon-picker', parentPanel);
}
-
goToPreviousSubView() {
const parentPanel = document.getElementById('PanelUI-zen-workspaces-multiview');
parentPanel.goBack();
}
-
workspaceHasIcon(workspace) {
return workspace.icon && workspace.icon !== '';
}
-
getWorkspaceIcon(workspace) {
if (this.workspaceHasIcon(workspace)) {
return workspace.icon;
@@ -656,14 +586,12 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
return Array.from(workspace.name)[0].toUpperCase();
}
-
get shouldShowContainers() {
return (
Services.prefs.getBoolPref('privacy.userContext.ui.enabled') && ContextualIdentityService.getPublicIdentities().length > 0
);
}
-
async _propagateWorkspaceData({ ignoreStrip = false, clearCache = true } = {}) {
await this.foreachWindowAsActive(async (browser) => {
await browser.ZenWorkspaces.updateWorkspaceIndicator();
@@ -690,7 +618,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
element.setAttribute('draggable', 'true');
}
-
element.addEventListener(
'dragstart',
function (event) {
@@ -705,7 +632,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}.bind(browser.ZenWorkspaces)
);
-
element.addEventListener(
'dragover',
function (event) {
@@ -716,7 +642,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}.bind(browser.ZenWorkspaces)
);
-
element.addEventListener(
'dragenter',
function (event) {
@@ -726,7 +651,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}.bind(browser.ZenWorkspaces)
);
-
element.addEventListener(
'dragleave',
function (event) {
@@ -734,7 +658,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}.bind(browser.ZenWorkspaces)
);
-
element.addEventListener(
'drop',
async function (event) {
@@ -754,7 +677,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}.bind(browser.ZenWorkspaces)
);
-
element.addEventListener(
'dragend',
function (event) {
@@ -769,7 +691,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}.bind(browser.ZenWorkspaces)
);
-
let childs = browser.MozXULElement.parseXULToFragment(`
@@ -779,13 +700,12 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
-
+
`);
-
// use text content instead of innerHTML to avoid XSS
childs.querySelector('.zen-workspace-icon').textContent = browser.ZenWorkspaces.getWorkspaceIcon(workspace);
childs.querySelector('.zen-workspace-name').textContent = workspace.name;
@@ -795,7 +715,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
);
}
-
childs.querySelector('.zen-workspace-actions').addEventListener(
'command',
((event) => {
@@ -824,12 +743,10 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
return element;
};
-
const createLastPositionDropTarget = () => {
const element = browser.document.createXULElement('div');
element.className = 'zen-workspace-last-place-drop-target';
-
element.addEventListener(
'dragover',
function (event) {
@@ -840,7 +757,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}.bind(browser.ZenWorkspaces)
);
-
element.addEventListener(
'dragenter',
function (event) {
@@ -850,7 +766,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}.bind(browser.ZenWorkspaces)
);
-
element.addEventListener(
'dragleave',
function (event) {
@@ -858,19 +773,16 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}.bind(browser.ZenWorkspaces)
);
-
element.addEventListener(
'drop',
async function (event) {
event.preventDefault();
element.classList.remove('dragover');
-
if (this.isReorderModeOn(browser)) {
const draggedWorkspaceId = event.dataTransfer.getData('text/plain');
await this.moveWorkspaceToEnd(draggedWorkspaceId);
-
if (this.draggedElement) {
this.draggedElement.classList.remove('dragging');
this.draggedElement = null;
@@ -879,11 +791,9 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}.bind(browser.ZenWorkspaces)
);
-
return element;
};
-
if(clearCache) {
browser.ZenWorkspaces._workspaceCache = null;
}
@@ -897,50 +807,41 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
workspaceList.removeAttribute('empty');
}
-
for (let workspace of workspaces.workspaces) {
let workspaceElement = createWorkspaceElement(workspace);
workspaceList.appendChild(workspaceElement);
}
-
workspaceList.appendChild(createLastPositionDropTarget());
-
if (!ignoreStrip) {
await browser.ZenWorkspaces._expandWorkspacesStrip(browser);
}
});
}
-
handlePanelHidden() {
const workspacesList = document.getElementById('PanelUI-zen-workspaces-list');
const reorderModeButton = document.getElementById('PanelUI-zen-workspaces-reorder-mode');
-
workspacesList?.removeAttribute('reorder-mode');
reorderModeButton?.removeAttribute('active');
}
-
async moveWorkspaceToEnd(draggedWorkspaceId) {
const workspaces = (await this._workspaces()).workspaces;
const draggedIndex = workspaces.findIndex((w) => w.uuid === draggedWorkspaceId);
const draggedWorkspace = workspaces.splice(draggedIndex, 1)[0];
workspaces.push(draggedWorkspace);
-
await ZenWorkspacesStorage.updateWorkspacePositions(workspaces);
await this._propagateWorkspaceData();
}
-
isReorderModeOn(browser) {
return browser.document.getElementById('PanelUI-zen-workspaces-list').getAttribute('reorder-mode') === 'true';
}
-
toggleReorderMode() {
const workspacesList = document.getElementById('PanelUI-zen-workspaces-list');
const reorderModeButton = document.getElementById('PanelUI-zen-workspaces-reorder-mode');
@@ -953,7 +854,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
reorderModeButton.setAttribute('active', 'true');
}
-
// Update draggable attribute
const workspaceElements = document.querySelectorAll('.zen-workspace-button');
workspaceElements.forEach((elem) => {
@@ -965,7 +865,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
});
}
-
async moveWorkspace(draggedWorkspaceId, targetWorkspaceId) {
const workspaces = (await this._workspaces()).workspaces;
const draggedIndex = workspaces.findIndex((w) => w.uuid === draggedWorkspaceId);
@@ -973,12 +872,10 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
const targetIndex = workspaces.findIndex((w) => w.uuid === targetWorkspaceId);
workspaces.splice(targetIndex, 0, draggedWorkspace);
-
await ZenWorkspacesStorage.updateWorkspacePositions(workspaces);
await this._propagateWorkspaceData();
}
-
async openWorkspacesDialog(event) {
if (!this.workspaceEnabled) {
return;
@@ -995,7 +892,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}).catch(console.error);
}
-
async initializeWorkspacesButton() {
if (!this.workspaceEnabled) {
return;
@@ -1007,14 +903,12 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
await this._expandWorkspacesStrip();
}
-
async _expandWorkspacesStrip(browser = window) {
if (typeof browser.ZenWorkspaces === 'undefined') {
browser = window;
}
let button = browser.document.getElementById('zen-workspaces-button');
-
if (!button) {
button = browser.document.createXULElement('toolbarbutton');
button.id = 'zen-workspaces-button';
@@ -1022,22 +916,18 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
navbar.appendChild(button);
}
-
while (button.firstChild) {
button.firstChild.remove();
}
-
for (let attr of [...button.attributes]) {
if (attr.name !== 'id') {
button.removeAttribute(attr.name);
}
}
-
button.className = '';
-
if (this._workspacesButtonClickListener) {
button.removeEventListener('click', this._workspacesButtonClickListener);
this._workspacesButtonClickListener = null;
@@ -1047,21 +937,18 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
this._workspaceButtonContextMenuListener = null;
}
-
button.setAttribute('removable', 'true');
button.setAttribute('showInPrivateBrowsing', 'false');
button.setAttribute('tooltiptext', 'Workspaces');
if (this.shouldShowIconStrip) {
let workspaces = await this._workspaces();
-
for (let workspace of workspaces.workspaces) {
let workspaceButton = browser.document.createXULElement('toolbarbutton');
workspaceButton.className = 'subviewbutton';
workspaceButton.setAttribute('tooltiptext', workspace.name);
workspaceButton.setAttribute('zen-workspace-id', workspace.uuid);
-
if (this.isWorkspaceActive(workspace)) {
workspaceButton.setAttribute('active', 'true');
} else {
@@ -1073,7 +960,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
workspaceButton.removeAttribute('default');
}
-
workspaceButton.addEventListener('click', async (event) => {
if (event.button !== 0) {
return;
@@ -1081,7 +967,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
await this.changeWorkspace(workspace);
});
-
let icon = browser.document.createXULElement('div');
icon.className = 'zen-workspace-icon';
icon.textContent = this.getWorkspaceIcon(workspace);
@@ -1089,14 +974,12 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
button.appendChild(workspaceButton);
}
-
if (workspaces.workspaces.length <= 1) {
button.setAttribute('dont-show', true);
} else {
button.removeAttribute('dont-show');
}
-
this._workspaceButtonContextMenuListener = (event) => {
event.preventDefault();
event.stopPropagation();
@@ -1109,69 +992,55 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
button.setAttribute('as-button', 'true');
button.classList.add('toolbarbutton-1', 'zen-sidebar-action-button');
-
this._workspacesButtonClickListener = browser.ZenWorkspaces.openWorkspacesDialog.bind(browser.ZenWorkspaces);
button.addEventListener('click', this._workspacesButtonClickListener);
-
const wrapper = browser.document.createXULElement('hbox');
wrapper.className = 'zen-workspace-sidebar-wrapper';
-
const icon = browser.document.createXULElement('div');
icon.className = 'zen-workspace-sidebar-icon';
icon.textContent = this.getWorkspaceIcon(activeWorkspace);
-
const name = browser.document.createXULElement('div');
name.className = 'zen-workspace-sidebar-name';
name.textContent = activeWorkspace.name;
-
if (!this.workspaceHasIcon(activeWorkspace)) {
icon.setAttribute('no-icon', 'true');
}
-
wrapper.appendChild(icon);
wrapper.appendChild(name);
-
button.appendChild(wrapper);
}
}
}
-
closeWorkspacesSubView() {
let parentPanel = document.getElementById('PanelUI-zen-workspaces-multiview');
parentPanel.goBack(parentPanel);
}
-
// Workspaces management
-
get _workspaceCreateInput() {
return document.getElementById('PanelUI-zen-workspaces-create-input');
}
-
get _workspaceEditDialog() {
return document.getElementById('PanelUI-zen-workspaces-edit');
}
-
get _workspaceEditInput() {
return document.getElementById('PanelUI-zen-workspaces-edit-input');
}
-
get _workspaceEditIconsContainer() {
return document.getElementById('PanelUI-zen-workspaces-icon-picker');
}
-
_deleteAllTabsInWorkspace(workspaceID) {
for (let tab of gBrowser.tabs) {
if (tab.getAttribute('zen-workspace-id') === workspaceID) {
@@ -1184,7 +1053,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}
}
-
_prepareNewWorkspace(window) {
document.documentElement.setAttribute('zen-workspace-id', window.uuid);
let tabCount = 0;
@@ -1200,17 +1068,14 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}
}
-
_createNewTabForWorkspace(window) {
let tab = gZenUIManager.openAndChangeToTab(Services.prefs.getStringPref('browser.startup.homepage'));
-
if(window.uuid){
tab.setAttribute('zen-workspace-id', window.uuid);
}
}
-
async saveWorkspaceFromCreate() {
let workspaceName = this._workspaceCreateInput.value;
if (!workspaceName) {
@@ -1223,7 +1088,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
this.goToPreviousSubView();
}
-
async saveWorkspaceFromEdit() {
let workspaceUuid = this._workspaceEditDialog.getAttribute('data-workspace-uuid');
let workspaceName = this._workspaceEditInput.value;
@@ -1241,7 +1105,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
this.goToPreviousSubView();
}
-
onWorkspaceCreationNameChange(event) {
let button = document.getElementById('PanelUI-zen-workspaces-create-save');
if (this._workspaceCreateInput.value === '') {
@@ -1251,7 +1114,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
button.removeAttribute('disabled');
}
-
onWorkspaceEditChange(icon) {
let button = document.getElementById('PanelUI-zen-workspaces-edit-save');
let name = this._workspaceEditInput.value;
@@ -1265,7 +1127,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
button.removeAttribute('disabled');
}
-
addChangeListeners(func) {
if (!this._changeListeners) {
this._changeListeners = [];
@@ -1273,13 +1134,11 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
this._changeListeners.push(func);
}
-
async changeWorkspace(window, onInit = false) {
if (!this.workspaceEnabled || this._inChangingWorkspace) {
return;
}
-
this._inChangingWorkspace = true;
try {
await this._performWorkspaceChange(window, onInit);
@@ -1288,55 +1147,44 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}
}
-
async _performWorkspaceChange(window, onInit) {
this.activeWorkspace = window.uuid;
const containerId = window.containerTabId?.toString();
const workspaces = await this._workspaces();
-
// Refresh tab cache
this.tabContainer._invalidateCachedTabs();
-
// First pass: Handle tab visibility and workspace ID assignment
const visibleTabs = this._processTabVisibility(window.uuid, containerId, workspaces);
-
// Second pass: Handle tab selection
await this._handleTabSelection(window, onInit, visibleTabs, containerId, workspaces);
-
// Update UI and state
await this._updateWorkspaceState(window, onInit);
}
-
-
_processTabVisibility(workspaceUuid, containerId, workspaces) {
const visibleTabs = new Set();
const lastSelectedTab = this._lastSelectedWorkspaceTabs[workspaceUuid];
-
for (const tab of gBrowser.tabs) {
const tabWorkspaceId = tab.getAttribute('zen-workspace-id');
const isEssential = tab.getAttribute("zen-essential") === "true";
const tabContextId = tab.getAttribute("usercontextid");
-
// Always hide last selected tabs from other workspaces
if (lastSelectedTab === tab && tabWorkspaceId !== workspaceUuid && !isEssential) {
gBrowser.hideTab(tab, undefined, true);
continue;
}
-
if (this._shouldShowTab(tab, workspaceUuid, containerId, workspaces)) {
gBrowser.showTab(tab);
visibleTabs.add(tab);
-
// Assign workspace ID if needed
if (!tabWorkspaceId && !isEssential) {
tab.setAttribute('zen-workspace-id', workspaceUuid);
@@ -1346,24 +1194,20 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}
}
-
return visibleTabs;
}
-
_shouldShowTab(tab, workspaceUuid, containerId, workspaces) {
const isEssential = tab.getAttribute("zen-essential") === "true";
const tabWorkspaceId = tab.getAttribute('zen-workspace-id');
const tabContextId = tab.getAttribute("usercontextid");
-
// Handle essential tabs
if (isEssential) {
if (!this.containerSpecificEssentials) {
return true; // Show all essential tabs when containerSpecificEssentials is false
}
-
if (containerId) {
// In workspaces with default container: Show essentials that match the container
return tabContextId === containerId;
@@ -1376,7 +1220,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}
}
-
// For non-essential tabs (both normal and pinned)
if (!tabWorkspaceId) {
// Assign workspace ID to tabs without one
@@ -1384,27 +1227,22 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
return true;
}
-
// Show if tab belongs to current workspace
return tabWorkspaceId === workspaceUuid;
}
-
async _handleTabSelection(window, onInit, visibleTabs, containerId, workspaces) {
const currentSelectedTab = gBrowser.selectedTab;
const oldWorkspaceId = currentSelectedTab.getAttribute('zen-workspace-id');
const lastSelectedTab = this._lastSelectedWorkspaceTabs[window.uuid];
-
// Save current tab as last selected for old workspace if it shouldn't be visible in new workspace
if (oldWorkspaceId && oldWorkspaceId !== window.uuid) {
this._lastSelectedWorkspaceTabs[oldWorkspaceId] = currentSelectedTab;
}
-
let tabToSelect = null;
-
// If current tab is visible in new workspace, keep it
if (this._shouldShowTab(currentSelectedTab, window.uuid, containerId, workspaces) && visibleTabs.has(currentSelectedTab)) {
tabToSelect = currentSelectedTab;
@@ -1419,10 +1257,8 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
.find(tab => !tab.pinned);
}
-
const previousSelectedTab = gBrowser.selectedTab;
-
// If we found a tab to select, select it
if (tabToSelect) {
gBrowser.selectedTab = tabToSelect;
@@ -1434,7 +1270,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
this._lastSelectedWorkspaceTabs[window.uuid] = newTab;
}
-
// After selecting the new tab, hide the previous selected tab if it shouldn't be visible in the new workspace
if (!this._shouldShowTab(previousSelectedTab, window.uuid, containerId, workspaces)) {
gBrowser.hideTab(previousSelectedTab, undefined, true);
@@ -1442,20 +1277,16 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}
-
-
async _updateWorkspaceState(window, onInit) {
// Update document state
document.documentElement.setAttribute('zen-workspace-id', window.uuid);
-
// Update workspace UI
await this._updateWorkspacesChangeContextMenu();
document.getElementById('tabbrowser-tabs')._positionPinnedTabs();
gZenUIManager.updateTabsToolbar();
await this._propagateWorkspaceData({ clearCache: false });
-
// Notify listeners
if (this._changeListeners?.length) {
for (const listener of this._changeListeners) {
@@ -1463,19 +1294,16 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}
}
-
// Reset bookmarks toolbar
const placesToolbar = document.getElementById("PlacesToolbar");
if (placesToolbar?._placesView) {
placesToolbar._placesView.invalidateContainer(placesToolbar._placesView._resultNode);
}
-
// Update workspace indicator
await this.updateWorkspaceIndicator();
}
-
async updateWorkspaceIndicator() {
// Update current workspace indicator
const currentWorkspace = await this.getActiveWorkspace();
@@ -1483,7 +1311,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
const indicatorName = document.getElementById('zen-current-workspace-indicator-name');
const indicatorIcon = document.getElementById('zen-current-workspace-indicator-icon');
-
if (this.workspaceHasIcon(currentWorkspace)) {
indicatorIcon.removeAttribute('no-icon');
} else {
@@ -1493,37 +1320,30 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
indicatorName.textContent = currentWorkspace.name;
}
-
async _updateWorkspacesChangeContextMenu() {
const workspaces = await this._workspaces();
-
const menuPopup = document.getElementById('context-zen-change-workspace-tab-menu-popup');
if (!menuPopup) {
return;
}
menuPopup.innerHTML = '';
-
const activeWorkspace = await this.getActiveWorkspace();
-
for (let workspace of workspaces.workspaces) {
const menuItem = document.createXULElement('menuitem');
menuItem.setAttribute('label', workspace.name);
menuItem.setAttribute('zen-workspace-id', workspace.uuid);
-
if (workspace.uuid === activeWorkspace.uuid) {
menuItem.setAttribute('disabled', 'true');
}
-
menuPopup.appendChild(menuItem);
}
}
-
_createWorkspaceData(name, isDefault, icon) {
let window = {
uuid: gZenUIManager.generateUuidv4(),
@@ -1535,7 +1355,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
return window;
}
-
async createAndSaveWorkspace(name = 'New Workspace', isDefault = false, icon = undefined) {
if (!this.workspaceEnabled) {
return;
@@ -1545,7 +1364,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
await this.changeWorkspace(workspaceData);
}
-
async onTabBrowserInserted(event) {
let tab = event.originalTarget;
const isEssential = tab.getAttribute("zen-essential") === "true";
@@ -1553,7 +1371,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
return;
}
-
let activeWorkspace = await this.getActiveWorkspace();
if (!activeWorkspace) {
return;
@@ -1561,36 +1378,30 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
tab.setAttribute('zen-workspace-id', activeWorkspace.uuid);
}
-
async onLocationChange(browser) {
if (!this.workspaceEnabled || this._inChangingWorkspace) {
return;
}
-
const parent = browser.ownerGlobal;
const tab = gBrowser.getTabForBrowser(browser);
const workspaceID = tab.getAttribute('zen-workspace-id');
const isEssential = tab.getAttribute("zen-essential") === "true";
const activeWorkspace = await parent.ZenWorkspaces.getActiveWorkspace();
-
// Only update last selected tab for non-essential tabs in their workspace
if (!isEssential && workspaceID === activeWorkspace.uuid) {
this._lastSelectedWorkspaceTabs[workspaceID] = tab;
}
-
// Switch workspace if needed
if (workspaceID && workspaceID !== activeWorkspace.uuid) {
await parent.ZenWorkspaces.changeWorkspace({ uuid: workspaceID });
}
}
-
// Context menu management
-
_contextMenuId = null;
async updateContextMenu(_) {
console.assert(this._contextMenuId, 'No context menu ID set');
@@ -1629,7 +1440,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}
}
-
async contextChangeContainerTab(event) {
let workspaces = await this._workspaces();
let workspace = workspaces.workspaces.find((workspace) => workspace.uuid === this._contextMenuId);
@@ -1638,7 +1448,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
await this.saveWorkspace(workspace);
}
-
onContextMenuClose() {
let target = document.querySelector(
`#PanelUI-zen-workspaces [zen-workspace-id="${this._contextMenuId}"] .zen-workspace-actions`
@@ -1649,20 +1458,17 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
this._contextMenuId = null;
}
-
async setDefaultWorkspace() {
await ZenWorkspacesStorage.setDefaultWorkspace(this._contextMenuId);
await this._propagateWorkspaceData();
}
-
async openWorkspace() {
let workspaces = await this._workspaces();
let workspace = workspaces.workspaces.find((workspace) => workspace.uuid === this._contextMenuId);
await this.changeWorkspace(workspace);
}
-
async contextDelete(event) {
this.__contextIsDelete = true;
event.stopPropagation();
@@ -1670,13 +1476,11 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
this.__contextIsDelete = false;
}
-
async contextEdit(event) {
event.stopPropagation();
await this.openEditDialog(this._contextMenuId);
}
-
async changeWorkspaceShortcut(offset = 1) {
// Cycle through workspaces
let workspaces = await this._workspaces();
@@ -1688,25 +1492,20 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
await this.changeWorkspace(nextWorkspace);
}
-
_initializeWorkspaceTabContextMenus() {
const menu = document.createXULElement('menu');
menu.setAttribute('id', 'context-zen-change-workspace-tab');
menu.setAttribute('data-l10n-id', 'context-zen-change-workspace-tab');
-
const menuPopup = document.createXULElement('menupopup');
menuPopup.setAttribute('id', 'context-zen-change-workspace-tab-menu-popup');
menuPopup.setAttribute('oncommand', "ZenWorkspaces.changeTabWorkspace(event.target.getAttribute('zen-workspace-id'))");
-
menu.appendChild(menuPopup);
-
document.getElementById('context_closeDuplicateTabs').after(menu);
}
-
async changeTabWorkspace(workspaceID) {
const tabs = TabContextMenu.contextTab.multiselected ? gBrowser.selectedTabs : [TabContextMenu.contextTab];
const previousWorkspaceID = document.documentElement.getAttribute('zen-workspace-id');
@@ -1722,7 +1521,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
await this.changeWorkspace(workspaces.workspaces.find((workspace) => workspace.uuid === workspaceID));
}
-
// Tab browser utilities
createContainerTabMenu(event) {
let window = event.target.ownerGlobal;
@@ -1735,18 +1533,15 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
});
}
-
getContextIdIfNeeded(userContextId, fromExternal, allowInheritPrincipal) {
if (!this.workspaceEnabled) {
return [userContextId, false];
}
-
if (this.shouldForceContainerTabsToWorkspace && typeof userContextId !== 'undefined' && this._workspaceCache?.workspaces) {
// Find all workspaces that match the given userContextId
const matchingWorkspaces = this._workspaceCache.workspaces.filter((workspace) => workspace.containerTabId === userContextId);
-
// Check if exactly one workspace matches
if (matchingWorkspaces.length === 1) {
const workspace = matchingWorkspaces[0];
@@ -1757,23 +1552,19 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}
}
-
const activeWorkspace = this.getActiveWorkspaceFromCache();
const activeWorkspaceUserContextId = activeWorkspace?.containerTabId;
-
if ((fromExternal || allowInheritPrincipal === false) && !!activeWorkspaceUserContextId) {
return [activeWorkspaceUserContextId, true];
}
-
if (typeof userContextId !== 'undefined' && userContextId !== activeWorkspaceUserContextId) {
return [userContextId, false];
}
return [activeWorkspaceUserContextId, true];
}
-
async shortcutSwitchTo(index) {
const workspaces = await this._workspaces();
// The index may be out of bounds, if it doesnt exist, don't do anything
@@ -1784,7 +1575,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
await this.changeWorkspace(workspaceToSwitch);
}
-
isBookmarkInAnotherWorkspace(bookmark) {
let tags = bookmark.tags;
// if any tag starts with "_workspace_id" and the workspace id doesnt match the active workspace id, return null
@@ -1795,8 +1585,3 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}
}
})();
-
-
-
-
-