mirror of
https://github.com/zen-browser/desktop.git
synced 2026-04-01 21:31:58 +00:00
feat: Added context menus to workspace icons at the button and small fixes, b=no-bug, c=common, workspaces
This commit is contained in:
@@ -1028,9 +1028,13 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||
}
|
||||
|
||||
changeWorkspaceIcon() {
|
||||
const anchor = this.activeWorkspaceIndicator?.querySelector(
|
||||
let anchor = this.activeWorkspaceIndicator?.querySelector(
|
||||
'.zen-current-workspace-indicator-icon'
|
||||
);
|
||||
if (this.#contextMenuData?.workspaceId) {
|
||||
anchor = this.#contextMenuData.originalTarget;
|
||||
}
|
||||
const workspaceId = this.#contextMenuData?.workspaceId || this.activeWorkspace;
|
||||
if (!anchor) {
|
||||
return;
|
||||
}
|
||||
@@ -1042,7 +1046,7 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||
gZenEmojiPicker
|
||||
.open(anchor)
|
||||
.then(async (emoji) => {
|
||||
const workspace = this.getActiveWorkspaceFromCache();
|
||||
const workspace = this.getWorkspaceFromId(workspaceId);
|
||||
if (!workspace) {
|
||||
console.warn('No active workspace found to change icon');
|
||||
return;
|
||||
@@ -1129,6 +1133,11 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||
addPopupListeners() {
|
||||
const workspaceActions = document.getElementById('zenWorkspaceMoreActions');
|
||||
workspaceActions.addEventListener('popupshowing', this.updateWorkspaceActionsMenu.bind(this));
|
||||
workspaceActions.addEventListener('popuphidden', () => {
|
||||
setTimeout(() => {
|
||||
this.#contextMenuData = null;
|
||||
}, 0); // Delay to ensure the context menu data is cleared after the popup is hidden
|
||||
});
|
||||
|
||||
const contextChangeContainerTabMenu = document.getElementById(
|
||||
'context_zenWorkspacesOpenInContainerTab'
|
||||
@@ -1143,6 +1152,7 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||
);
|
||||
}
|
||||
|
||||
#contextMenuData = null;
|
||||
updateWorkspaceActionsMenu(event) {
|
||||
if (event.target.id !== 'zenWorkspaceMoreActions') {
|
||||
return;
|
||||
@@ -1155,10 +1165,35 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||
} else {
|
||||
openInContainerMenuItem.setAttribute('hidden', 'true');
|
||||
}
|
||||
const target = event.explicitOriginalTarget?.closest('toolbarbutton');
|
||||
this.#contextMenuData = {
|
||||
workspaceId: target?.getAttribute('zen-workspace-id'),
|
||||
originalTarget: target,
|
||||
};
|
||||
const workspaceName = document.getElementById('context_zenEditWorkspace');
|
||||
const themePicker = document.getElementById('context_zenChangeWorkspaceTheme');
|
||||
workspaceName.hidden =
|
||||
this.#contextMenuData.workspaceId &&
|
||||
this.#contextMenuData.workspaceId !== this.activeWorkspace;
|
||||
themePicker.hidden =
|
||||
this.#contextMenuData.workspaceId &&
|
||||
this.#contextMenuData.workspaceId !== this.activeWorkspace;
|
||||
event.target.addEventListener(
|
||||
'popuphidden',
|
||||
() => {
|
||||
this.#contextMenuData = null;
|
||||
},
|
||||
{ once: true }
|
||||
);
|
||||
}
|
||||
|
||||
updateWorkspaceActionsMenuContainer(event) {
|
||||
const workspace = this.getActiveWorkspaceFromCache();
|
||||
let workspace;
|
||||
if (this.#contextMenuData?.workspaceId) {
|
||||
workspace = this.getWorkspaceFromId(this.#contextMenuData.workspaceId);
|
||||
} else {
|
||||
workspace = this.getActiveWorkspaceFromCache();
|
||||
}
|
||||
let containerTabId = workspace.containerTabId;
|
||||
return window.createUserContextMenu(event, {
|
||||
isContextMenu: true,
|
||||
@@ -2349,12 +2384,12 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||
this._organizingWorkspaceStrip = true;
|
||||
let workspaces = await this._workspaces();
|
||||
let workspace = workspaces.workspaces.find(
|
||||
(workspace) => workspace.uuid === this.activeWorkspace
|
||||
(workspace) => workspace.uuid === (this.#contextMenuData?.workspaceId || this.activeWorkspace)
|
||||
);
|
||||
let userContextId = parseInt(event.target.getAttribute('data-usercontextid'));
|
||||
workspace.containerTabId = userContextId + 0; // +0 to convert to number
|
||||
await this.saveWorkspace(workspace);
|
||||
await this._organizeWorkspaceStripLocations(workspace, true);
|
||||
await this._organizeWorkspaceStripLocations(this.getActiveWorkspaceFromCache(), true);
|
||||
await gZenWorkspaces.updateTabsContainers();
|
||||
this.tabContainer._invalidateCachedTabs();
|
||||
}
|
||||
@@ -2365,7 +2400,7 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||
{ id: 'zen-workspaces-delete-workspace-body' },
|
||||
]);
|
||||
if (Services.prompt.confirm(null, title, body)) {
|
||||
await this.removeWorkspace(this.activeWorkspace);
|
||||
await this.removeWorkspace(this.#contextMenuData?.workspaceId || this.activeWorkspace);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user