Skip to content

Commit

Permalink
add: menu manager menuitem type
Browse files Browse the repository at this point in the history
  • Loading branch information
windingwind committed Nov 18, 2024
1 parent ed4fe5e commit 6ddef73
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/managers/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ export class MenuManager extends ManagerTool {
listener: menuitemOption.commandListener!,
});
}
if (menuitemOption.tag === "menuitem") {
elementOption.attributes!.type = menuitemOption.type || "";
elementOption.attributes!.checked = menuitemOption.checked || false;
}
const menuItem = this.ui.createElement(
doc,
menuitemOption.tag,
Expand All @@ -135,6 +139,9 @@ export class MenuManager extends ManagerTool {
if (menuitemOption.getVisibility) {
popup?.addEventListener("popupshowing", (ev: Event) => {
const showing = menuitemOption.getVisibility!(menuItem as any, ev);
if (typeof showing === "undefined") {
return;
}
if (showing) {
menuItem.removeAttribute("hidden");
} else {
Expand Down Expand Up @@ -189,12 +196,14 @@ type MenuitemTagDependentOptions =
| {
tag: "menuitem";
/* return true to show and false to hide current element */
getVisibility?: (elem: XUL.MenuItem, ev: Event) => boolean;
getVisibility?: (elem: XUL.MenuItem, ev: Event) => boolean | undefined;
type?: "" | "checkbox" | "radio";
checked?: boolean;
}
| {
tag: "menu";
/* return true to show and false to hide current element */
getVisibility?: (elem: XUL.Menu, ev: Event) => boolean;
getVisibility?: (elem: XUL.Menu, ev: Event) => boolean | undefined;
/* Attributes below are used when type === "menu" */
popupId?: string;
onpopupshowing?: string;
Expand All @@ -207,7 +216,10 @@ type MenuitemTagDependentOptions =
| {
tag: "menuseparator";
/* return true to show and false to hide current element */
getVisibility?: (elem: XUL.MenuSeparator, ev: Event) => boolean;
getVisibility?: (
elem: XUL.MenuSeparator,
ev: Event,
) => boolean | undefined;
};

interface MenuitemCommonOptions {
Expand Down

0 comments on commit 6ddef73

Please sign in to comment.