Checkbox and Radio Context Menu Items (#861)

Expands the context menu to allow checkbox and radio button items.
This commit is contained in:
Sylvie Crowe 2024-09-25 20:53:32 -07:00 committed by GitHub
parent 3da79f80f4
commit de92e53c38
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 6 additions and 2 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

@ -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 = {