Add workspace switch accelerators, skip prompt if workspace is already open (#1427)

This commit is contained in:
Evan Simkowitz 2024-12-06 16:35:01 -08:00 committed by GitHub
parent 7bf1ca5a49
commit e0ede0ff60
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 39 additions and 21 deletions

View File

@ -294,6 +294,10 @@ export class WaveBrowserWindow extends BaseWindow {
console.log("switchWorkspace already on this workspace", this.waveWindowId);
return;
}
// 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, {
@ -312,11 +316,14 @@ export class WaveBrowserWindow extends BaseWindow {
if (!newWin) {
console.log("error creating new window", this.waveWindowId);
}
const newBwin = await createBrowserWindow(newWin, await FileService.GetFullConfig(), { unamePlatform });
const newBwin = await createBrowserWindow(newWin, await FileService.GetFullConfig(), {
unamePlatform,
});
newBwin.show();
return;
}
}
}
const newWs = await WindowService.SwitchWorkspace(this.waveWindowId, workspaceId);
if (!newWs) {
return;

View File

@ -48,16 +48,27 @@ async function getWorkspaceMenu(): Promise<Electron.MenuItemConstructorOptions[]
},
},
];
function getWorkspaceSwitchAccelerator(i: number): string {
if (i < 10) {
if (i == 9) {
i = 0;
} else {
i++;
}
return unamePlatform == "darwin" ? `Command+Control+${i}` : `Alt+Control+${i}`;
}
}
workspaceList?.length &&
workspaceMenu.push(
{ type: "separator" },
...workspaceList.map<Electron.MenuItemConstructorOptions>((workspace) => {
...workspaceList.map<Electron.MenuItemConstructorOptions>((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),
};
})
);