mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
Add workspace switch accelerators, skip prompt if workspace is already open (#1427)
This commit is contained in:
parent
7bf1ca5a49
commit
e0ede0ff60
@ -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;
|
||||
|
@ -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),
|
||||
};
|
||||
})
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user