@laserware/hoverboard
Version:
Better context menus for Electron.
81 lines (61 loc) • 2.15 kB
text/typescript
import type { MenuItemConstructorOptions } from "electron";
import type { ContextMenuItemRole } from "../renderer/types.js";
import {
type BooleanAttribute,
type ContextMenuItemAttributes,
ContextMenuItemElement,
property,
} from "./ContextMenuItemElement.js";
export interface RoleMenuItemAttributes extends ContextMenuItemAttributes {
accelerator: string | null;
"accelerator-works-when-hidden": BooleanAttribute;
enabled: BooleanAttribute;
icon: string | null;
of: ContextMenuItemRole | null;
"register-accelerator": BooleanAttribute;
tooltip: string | null;
}
export class RoleMenuItemElement extends ContextMenuItemElement<RoleMenuItemAttributes> {
constructor() {
super(undefined);
}
({ type: String })
public accelerator: string | undefined;
({ attribute: "accelerator-works-when-hidden", type: Boolean })
public acceleratorWorksWhenHidden: boolean | undefined;
({ type: Boolean })
public enabled: boolean | undefined;
({ type: String })
public icon: string | undefined;
({ type: String })
public of: ContextMenuItemRole | undefined;
({ attribute: "register-accelerator", type: Boolean })
public registerAccelerator: boolean | undefined;
({ attribute: "tooltip", type: String })
public toolTip: string | undefined;
public toTemplate(): MenuItemConstructorOptions {
const template = super.toTemplate();
if (this.accelerator !== undefined) {
template.accelerator = this.accelerator;
}
if (this.acceleratorWorksWhenHidden !== undefined) {
template.acceleratorWorksWhenHidden = this.acceleratorWorksWhenHidden;
}
if (this.enabled !== undefined) {
template.enabled = this.enabled;
}
if (this.icon !== undefined) {
template.icon = this.icon;
}
if (this.of !== undefined) {
template.role = this.of;
}
if (this.registerAccelerator !== undefined) {
template.registerAccelerator = this.registerAccelerator;
}
if (this.toolTip !== undefined) {
template.toolTip = this.toolTip;
}
return template;
}
}