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,27 +294,34 @@ export class WaveBrowserWindow extends BaseWindow {
|
|||||||
console.log("switchWorkspace already on this workspace", this.waveWindowId);
|
console.log("switchWorkspace already on this workspace", this.waveWindowId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const curWorkspace = await WorkspaceService.GetWorkspace(this.workspaceId);
|
|
||||||
if (curWorkspace.tabids.length > 1 && (!curWorkspace.name || !curWorkspace.icon)) {
|
// 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 choice = dialog.showMessageBoxSync(this, {
|
const workspaceList = await WorkspaceService.ListWorkspaces();
|
||||||
type: "question",
|
if (!workspaceList.find((wse) => wse.workspaceid === workspaceId)?.windowid) {
|
||||||
buttons: ["Cancel", "Open in New Window", "Yes"],
|
const curWorkspace = await WorkspaceService.GetWorkspace(this.workspaceId);
|
||||||
title: "Confirm",
|
if (curWorkspace.tabids.length > 1 && (!curWorkspace.name || !curWorkspace.icon)) {
|
||||||
message:
|
const choice = dialog.showMessageBoxSync(this, {
|
||||||
"This window has unsaved tabs, switching workspaces will delete the existing tabs. Would you like to continue?",
|
type: "question",
|
||||||
});
|
buttons: ["Cancel", "Open in New Window", "Yes"],
|
||||||
if (choice === 0) {
|
title: "Confirm",
|
||||||
console.log("user cancelled switch workspace", this.waveWindowId);
|
message:
|
||||||
return;
|
"This window has unsaved tabs, switching workspaces will delete the existing tabs. Would you like to continue?",
|
||||||
} else if (choice === 1) {
|
});
|
||||||
console.log("user chose open in new window", this.waveWindowId);
|
if (choice === 0) {
|
||||||
const newWin = await WindowService.CreateWindow(null, workspaceId);
|
console.log("user cancelled switch workspace", this.waveWindowId);
|
||||||
if (!newWin) {
|
return;
|
||||||
console.log("error creating new window", this.waveWindowId);
|
} 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);
|
const newWs = await WindowService.SwitchWorkspace(this.waveWindowId, workspaceId);
|
||||||
|
@ -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 &&
|
workspaceList?.length &&
|
||||||
workspaceMenu.push(
|
workspaceMenu.push(
|
||||||
{ type: "separator" },
|
{ type: "separator" },
|
||||||
...workspaceList.map<Electron.MenuItemConstructorOptions>((workspace) => {
|
...workspaceList.map<Electron.MenuItemConstructorOptions>((workspace, i) => {
|
||||||
return {
|
return {
|
||||||
label: `Switch to ${workspace.workspacedata.name} (${workspace.workspacedata.oid.slice(0, 5)})`,
|
label: `Switch to ${workspace.workspacedata.name} (${workspace.workspacedata.oid.slice(0, 5)})`,
|
||||||
click: (_, window) => {
|
click: (_, window) => {
|
||||||
const ww = window as WaveBrowserWindow;
|
const ww = window as WaveBrowserWindow;
|
||||||
ww.switchWorkspace(workspace.workspacedata.oid);
|
ww.switchWorkspace(workspace.workspacedata.oid);
|
||||||
},
|
},
|
||||||
|
accelerator: getWorkspaceSwitchAccelerator(i),
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user