From e0ede0ff606bf5325da89944e06aa6c29bbe5f95 Mon Sep 17 00:00:00 2001 From: Evan Simkowitz Date: Fri, 6 Dec 2024 16:35:01 -0800 Subject: [PATCH] Add workspace switch accelerators, skip prompt if workspace is already open (#1427) --- emain/emain-window.ts | 47 +++++++++++++++++++++++++------------------ emain/menu.ts | 13 +++++++++++- 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/emain/emain-window.ts b/emain/emain-window.ts index 3e511eae1..2cf191504 100644 --- a/emain/emain-window.ts +++ b/emain/emain-window.ts @@ -294,27 +294,34 @@ export class WaveBrowserWindow extends BaseWindow { console.log("switchWorkspace already on this workspace", this.waveWindowId); return; } - const curWorkspace = await WorkspaceService.GetWorkspace(this.workspaceId); - if (curWorkspace.tabids.length > 1 && (!curWorkspace.name || !curWorkspace.icon)) { - const choice = dialog.showMessageBoxSync(this, { - type: "question", - buttons: ["Cancel", "Open in New Window", "Yes"], - title: "Confirm", - message: - "This window has unsaved tabs, switching workspaces will delete the existing tabs. Would you like to continue?", - }); - if (choice === 0) { - console.log("user cancelled switch workspace", this.waveWindowId); - return; - } else if (choice === 1) { - console.log("user chose open in new window", this.waveWindowId); - const newWin = await WindowService.CreateWindow(null, workspaceId); - if (!newWin) { - console.log("error creating new window", this.waveWindowId); + + // If the workspace is already owned by a window, then we can just call SwitchWorkspace without first prompting the user, since it'll just focus to the other window. + const workspaceList = await WorkspaceService.ListWorkspaces(); + if (!workspaceList.find((wse) => wse.workspaceid === workspaceId)?.windowid) { + const curWorkspace = await WorkspaceService.GetWorkspace(this.workspaceId); + if (curWorkspace.tabids.length > 1 && (!curWorkspace.name || !curWorkspace.icon)) { + const choice = dialog.showMessageBoxSync(this, { + type: "question", + buttons: ["Cancel", "Open in New Window", "Yes"], + title: "Confirm", + message: + "This window has unsaved tabs, switching workspaces will delete the existing tabs. Would you like to continue?", + }); + if (choice === 0) { + console.log("user cancelled switch workspace", this.waveWindowId); + return; + } else if (choice === 1) { + console.log("user chose open in new window", this.waveWindowId); + const newWin = await WindowService.CreateWindow(null, workspaceId); + if (!newWin) { + console.log("error creating new window", this.waveWindowId); + } + const newBwin = await createBrowserWindow(newWin, await FileService.GetFullConfig(), { + unamePlatform, + }); + newBwin.show(); + return; } - const newBwin = await createBrowserWindow(newWin, await FileService.GetFullConfig(), { unamePlatform }); - newBwin.show(); - return; } } const newWs = await WindowService.SwitchWorkspace(this.waveWindowId, workspaceId); diff --git a/emain/menu.ts b/emain/menu.ts index a97e98fa7..a4a22eedd 100644 --- a/emain/menu.ts +++ b/emain/menu.ts @@ -48,16 +48,27 @@ async function getWorkspaceMenu(): Promise((workspace) => { + ...workspaceList.map((workspace, i) => { return { label: `Switch to ${workspace.workspacedata.name} (${workspace.workspacedata.oid.slice(0, 5)})`, click: (_, window) => { const ww = window as WaveBrowserWindow; ww.switchWorkspace(workspace.workspacedata.oid); }, + accelerator: getWorkspaceSwitchAccelerator(i), }; }) );