Work with Menu

Hiding/showing menu options

You can hide and show menu items (one or several at once) with the help of the hide() / show() methods:


Related sample:  Menu. Show/Hide Menu Item

Both methods take one parameter - the ID of a menu item or an array with IDs of menu items.

Disabling/enabling menu options

You can disable one menu option or several options at a time with the disable() method:


To enable one menu option or several options at a time, use the enable() method:


Related sample:  Menu. Enable/Disable Menu Item

Both methods take one parameter: the ID of a menu item or an array of IDs.

Checking if a menu option is disabled

To check if an item of Menu is disabled, call the isDisabled() method. The method takes one parameter:

  • id - (string) an id of a menu item
menu.isDisabled("1"); // -> true/false

Related sample:  Menu. Enable/Disable Menu Item

Using Tree collection API

You can manipulate the controls of Menu with the help of the Tree collection API.

Adding menu items

You can add menu items with the add() method of tree collection:{
    value:"Open", items:[
        { value:"File", hotkey:"Ctrl+F" },
        { value:"Folder" }

Related sample:  Menu. Add/Remove Item

Rearranging menu items

You can move menu items to different positions with the move() method. For example, this is how you can move an item with ID "2" to the left edge of the menu:"2",0);

The ID should always be a string, even if in menu item configuration you set it as a number.

To get the current position, use the getIndex() method of TreeCollection:"id");

Indexes are counted from 0.

Iterating menu items

You can work with all (or some) menu items with the help of the map() method of TreeCollection:

// remove all icons from the menu{
    item.icon = "";

Setting item text

You can set text labels for any menu item. Access the needed item with the getItem() method of the TreeCollection:"id").value = "Open";

Setting item hotkey

You can add a shortcut to a menu option by accessing it with the help of the getItem() method. After you add a hotkey, a label with the keys will be added to the option."id").hotkey = "Ctrl+N";

Removing menu items

You can remove any item from a menu with the remove() method. The item will be removed with all its sub-items."id");

Related sample:  Menu. Add/Remove Item

To remove all items from Menu, call the removeAll() method. Afterwards, you can load other options.;;

Check the full list of Tree collection API.

Back to top