Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to have a dynamic context submenu menu on the collection menu? #74

Open
retorquere opened this issue Jan 13, 2025 · 9 comments

Comments

@retorquere
Copy link
Collaborator

I have a submenu that wants to display a variable set of menitems, dependent on the collection that was right-clicked. Is that possible?

@windingwind
Copy link
Owner

Yes. There is a isHidden property on the argument when creating a menu and by returning a boolean the column is displayed accordingly. Like this:

ztoolkit.Menu.register("collection", {
  "tag": "menu",
  "children": [
    {
      "tag": "menuitem",
      "isHidden": (elem, ev) => {
        return false;
      }
    }
  ]
})

@retorquere
Copy link
Collaborator Author

What are elem and ev?

@windingwind
Copy link
Owner

It's:

/**
* Dynamically hide/show the menu item
* @returns Whether the menu item should be hidden
*/
isHidden?: (elem: XUL.MenuItem, ev: Event) => boolean | undefined;

@windingwind
Copy link
Owner

It's called in the event popupshowing of its parent popup, and that's where the ev comes from

@retorquere
Copy link
Collaborator Author

Yes. There is a isHidden property on the argument when creating a menu and by returning a boolean the column is displayed accordingly. Like this:

ztoolkit.Menu.register("collection", {
  "tag": "menu",
  "children": [
    {
      "tag": "menuitem",
      "isHidden": (elem, ev) => {
        return false;
      }
    }
  ]
})

That will allow a set number of menu items to be shown or hidden I think, but I don't know in advance how many there will be, it's dynamic.

@retorquere
Copy link
Collaborator Author

Oh and the label would be dynamic too.

@windingwind
Copy link
Owner

Yes, you can always set the attributes on the elem

@retorquere
Copy link
Collaborator Author

But a fixed number of items then, correct?

@retorquere
Copy link
Collaborator Author

How do I get the selected collection inside isHidden?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants