Skip to content

Commit e0ede0f

Browse files
authored
Add workspace switch accelerators, skip prompt if workspace is already open (#1427)
1 parent 7bf1ca5 commit e0ede0f

File tree

2 files changed

+39
-21
lines changed

2 files changed

+39
-21
lines changed

emain/emain-window.ts

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -294,27 +294,34 @@ export class WaveBrowserWindow extends BaseWindow {
294294
console.log("switchWorkspace already on this workspace", this.waveWindowId);
295295
return;
296296
}
297-
const curWorkspace = await WorkspaceService.GetWorkspace(this.workspaceId);
298-
if (curWorkspace.tabids.length > 1 && (!curWorkspace.name || !curWorkspace.icon)) {
299-
const choice = dialog.showMessageBoxSync(this, {
300-
type: "question",
301-
buttons: ["Cancel", "Open in New Window", "Yes"],
302-
title: "Confirm",
303-
message:
304-
"This window has unsaved tabs, switching workspaces will delete the existing tabs. Would you like to continue?",
305-
});
306-
if (choice === 0) {
307-
console.log("user cancelled switch workspace", this.waveWindowId);
308-
return;
309-
} else if (choice === 1) {
310-
console.log("user chose open in new window", this.waveWindowId);
311-
const newWin = await WindowService.CreateWindow(null, workspaceId);
312-
if (!newWin) {
313-
console.log("error creating new window", this.waveWindowId);
297+
298+
// 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.
299+
const workspaceList = await WorkspaceService.ListWorkspaces();
300+
if (!workspaceList.find((wse) => wse.workspaceid === workspaceId)?.windowid) {
301+
const curWorkspace = await WorkspaceService.GetWorkspace(this.workspaceId);
302+
if (curWorkspace.tabids.length > 1 && (!curWorkspace.name || !curWorkspace.icon)) {
303+
const choice = dialog.showMessageBoxSync(this, {
304+
type: "question",
305+
buttons: ["Cancel", "Open in New Window", "Yes"],
306+
title: "Confirm",
307+
message:
308+
"This window has unsaved tabs, switching workspaces will delete the existing tabs. Would you like to continue?",
309+
});
310+
if (choice === 0) {
311+
console.log("user cancelled switch workspace", this.waveWindowId);
312+
return;
313+
} else if (choice === 1) {
314+
console.log("user chose open in new window", this.waveWindowId);
315+
const newWin = await WindowService.CreateWindow(null, workspaceId);
316+
if (!newWin) {
317+
console.log("error creating new window", this.waveWindowId);
318+
}
319+
const newBwin = await createBrowserWindow(newWin, await FileService.GetFullConfig(), {
320+
unamePlatform,
321+
});
322+
newBwin.show();
323+
return;
314324
}
315-
const newBwin = await createBrowserWindow(newWin, await FileService.GetFullConfig(), { unamePlatform });
316-
newBwin.show();
317-
return;
318325
}
319326
}
320327
const newWs = await WindowService.SwitchWorkspace(this.waveWindowId, workspaceId);

emain/menu.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,27 @@ async function getWorkspaceMenu(): Promise<Electron.MenuItemConstructorOptions[]
4848
},
4949
},
5050
];
51+
function getWorkspaceSwitchAccelerator(i: number): string {
52+
if (i < 10) {
53+
if (i == 9) {
54+
i = 0;
55+
} else {
56+
i++;
57+
}
58+
return unamePlatform == "darwin" ? `Command+Control+${i}` : `Alt+Control+${i}`;
59+
}
60+
}
5161
workspaceList?.length &&
5262
workspaceMenu.push(
5363
{ type: "separator" },
54-
...workspaceList.map<Electron.MenuItemConstructorOptions>((workspace) => {
64+
...workspaceList.map<Electron.MenuItemConstructorOptions>((workspace, i) => {
5565
return {
5666
label: `Switch to ${workspace.workspacedata.name} (${workspace.workspacedata.oid.slice(0, 5)})`,
5767
click: (_, window) => {
5868
const ww = window as WaveBrowserWindow;
5969
ww.switchWorkspace(workspace.workspacedata.oid);
6070
},
71+
accelerator: getWorkspaceSwitchAccelerator(i),
6172
};
6273
})
6374
);

0 commit comments

Comments
 (0)