PopupMenu::addItem().setAction() issue

The new PopupMenu::Item helper functions, especially the one that lets you set a lambda to be called when you choose a menu item, are pretty cool. However, that lambda is never called if you’re setting the popup menu for a combobox like as follows:

struct Foo
{
    Foo();
private:
    ComboBox cb;
};

Foo::Foo()
{
    int menuID = 1;
    auto* popupMenu = cb.getRootMenu();
    popupMenu->addItem(PopupMenu::Item("test")
                       .setTicked(false)
                       .setAction([this]()
    {
        DBG( "you clicked test" );
    })
                       .setID(menuID++));
    
    cb.setSelectedId(1);  //does not invoke the action
}

I believe way down here in MenuWindow void hide (const PopupMenu::Item* item, bool makeInvisible) is where the action is invoked:

           if (resultID != 0
                 && item != nullptr
                 && item->action != nullptr)
                MessageManager::callAsync (item->action);
        }

Just ran into this. Very annoying. There’s no triggerActionForSelectedItem() or any other way to easily perform the selection of an item programmatically.

I’m currently writing complicated recursive lambdas to try and find the correct menu item inside submenus inside submenus… and trigger its action.

I won’t even start ranting about the perennial confusion I suffer with ID vs Index.

Oh a FTR:
We can’t use the ChangeListener callbacks because they don’t get called when the user re-selects the item already selected. This is a very common scenario in (for example) a preset menu where the settings have changed but the user wants to reselect the preset to get back to it’s correct settings.

For the “re-selection” problem:

I think it should be a default behaviour, just for the reasons you mentioned.