feat: allow multiple plots at once with checkmarks

This commit is contained in:
Sylvia Crowe 2024-09-25 16:58:39 -07:00
parent bae31cc438
commit f196656f43
4 changed files with 12 additions and 3 deletions

View File

@ -750,6 +750,7 @@ function convertMenuDefArrToMenu(menuDefArr: ElectronContextMenuItem[]): electro
click: (_, window) => {
(window as electron.BrowserWindow)?.webContents?.send("contextmenu-click", menuDef.id);
},
checked: menuDef.checked,
};
if (menuDef.submenu != null) {
menuItemTemplate.submenu = convertMenuDefArrToMenu(menuDef.submenu);

View File

@ -25,6 +25,7 @@ class ContextMenuModelType {
type: item.type,
label: item.label,
id: crypto.randomUUID(),
checked: item.checked,
};
if (item.click) {
this.handlers.set(electronItem.id, item.click);

View File

@ -205,18 +205,23 @@ class CpuPlotViewModel {
e.preventDefault();
e.stopPropagation();
const plotData = globalStore.get(this.dataAtom);
const metrics = globalStore.get(this.metrics);
if (plotData.length == 0) {
return;
}
const menu = Object.keys(plotData[plotData.length - 1])
.filter((dataType) => dataType !== "ts")
.map((dataType) => {
const inMetrics = metrics.includes(dataType);
const newMetrics = inMetrics ? metrics.filter((dt) => dt !== dataType) : [...metrics, dataType];
const menuItem: ContextMenuItem = {
label: dataType,
type: "checkbox",
checked: inMetrics,
click: async () => {
await RpcApi.SetMetaCommand(WindowRpcClient, {
oref: WOS.makeORef("block", this.blockId),
meta: { "graph:metrics": [dataType] },
meta: { "graph:metrics": newMetrics },
});
},
};

View File

@ -81,16 +81,18 @@ declare global {
id: string; // unique id, used for communication
label: string;
role?: string; // electron role (optional)
type?: "separator" | "normal" | "submenu";
type?: "separator" | "normal" | "submenu" | "checkbox";
submenu?: ElectronContextMenuItem[];
checked?: boolean;
};
type ContextMenuItem = {
label?: string;
type?: "separator" | "normal" | "submenu";
type?: "separator" | "normal" | "submenu" | "checkbox";
role?: string; // electron role (optional)
click?: () => void; // not required if role is set
submenu?: ContextMenuItem[];
checked?: boolean;
};
type KeyPressDecl = {