From de92e53c3879b4398951834fde9902a40d421906 Mon Sep 17 00:00:00 2001 From: Sylvie Crowe <107814465+oneirocosm@users.noreply.github.com> Date: Wed, 25 Sep 2024 20:53:32 -0700 Subject: [PATCH] Checkbox and Radio Context Menu Items (#861) Expands the context menu to allow checkbox and radio button items. --- emain/emain.ts | 1 + frontend/app/store/contextmenu.ts | 1 + frontend/types/custom.d.ts | 6 ++++-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/emain/emain.ts b/emain/emain.ts index 50de420bd..29a7ee68f 100644 --- a/emain/emain.ts +++ b/emain/emain.ts @@ -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); diff --git a/frontend/app/store/contextmenu.ts b/frontend/app/store/contextmenu.ts index fac411cf1..6b8e1c2d9 100644 --- a/frontend/app/store/contextmenu.ts +++ b/frontend/app/store/contextmenu.ts @@ -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); diff --git a/frontend/types/custom.d.ts b/frontend/types/custom.d.ts index be830c0d6..eccc5caa7 100644 --- a/frontend/types/custom.d.ts +++ b/frontend/types/custom.d.ts @@ -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" | "radio"; submenu?: ElectronContextMenuItem[]; + checked?: boolean; }; type ContextMenuItem = { label?: string; - type?: "separator" | "normal" | "submenu"; + type?: "separator" | "normal" | "submenu" | "checkbox" | "radio"; role?: string; // electron role (optional) click?: () => void; // not required if role is set submenu?: ContextMenuItem[]; + checked?: boolean; }; type KeyPressDecl = {