Change flyout menu labels on-the-fly

Hello.

How can I change the labels of the flyout menu entries on-the-fly?

Hi, have you watched this video?

Flyout menus & Entrypoints

PS : the whole series is definitely recommended :wink:

1 Like

Yeah. Watched it several times. This is a crucial addition to the lackluster documentation. But I’ll watch it one more time. Maybe I have overseen something.

EDIT: I can get around it be reloading the panel. It would be interesting to know if the changes are possible on-the-fly as well.

Around playtime 11:45 of the video you might find what you’re looking for…

1 Like

Dang - oversaw that. Cheers.

You’re most welcome :blush:

1 Like

Somehow I can’t change that label of the submenu parent (the one labeled “Languages”). The other menuitems work fine. Any ideas?

Here’s the code snippet, dealing with the issue …

// Change language of menu items
        const{ menuItems } = entrypoints.getPanel("mainpanel");
        menuItems.getItem("restorepresets").label = await getLanguageString("menuitems_restorepresets");
        menuItems.getItem("exportpresets").label = await getLanguageString("menuitems_exportpresets");
        menuItems.getItem("importpresets").label = await getLanguageString("menuitems_importpresets");
        menuItems.getItem("appendpresets").label = await getLanguageString("menuitems_appendpresets");
        menuItems.getItem("languages").label = await getLanguageString("menuitems_appendpresets");;
      },
      menuItems: [
        {id: "restorepresets", label: "Restore Default Presets"},
        {id: "exportpresets", label: "Export Presets"},
        {id: "importpresets", label: "Import Presets"},
        {id: "appendpresets", label: "Append Presets"},
        {id: "spacer", label: "-"}, // SPACER
        {id: "languages", label: "Languages", submenu: [
          {id: "lang_en", label: "English"},
          {id: "lang_de", label: "Deutsch"}
        ]},
      ],

Maybe because your languages id are nested in submenu, and the way you target them?

1 Like

It obviously has to do with the “Languages” entry being a submenu. The question is, how to get around it?

How do you change other labels? You’d mentioned that all others work.

1 Like

Here is the code snippet again …

// Change language of menu items
        const{ menuItems } = entrypoints.getPanel("mainpanel");
        menuItems.getItem("restorepresets").label = await getLanguageString("menuitems_restorepresets");
        menuItems.getItem("exportpresets").label = await getLanguageString("menuitems_exportpresets");
        menuItems.getItem("importpresets").label = await getLanguageString("menuitems_importpresets");
        menuItems.getItem("appendpresets").label = await getLanguageString("menuitems_appendpresets");
        menuItems.getItem("languages").label = await getLanguageString("menuitems_languages");
      },
      menuItems: [
        {id: "restorepresets", label: "Restore Default Presets"},
        {id: "exportpresets", label: "Export Presets"},
        {id: "importpresets", label: "Import Presets"},
        {id: "appendpresets", label: "Append Presets"},
        {id: "spacer", label: "-"}, // SPACER
        {id: "languages", label: "Languages", submenu: [
          {id: "lang_en", label: "English"},
          {id: "lang_de", label: "Deutsch"}
        ]},

The first 4 changes work.

What happens if you use
menuItems.getItem("lang_en").label=…

1 Like

That works as well as expected.