Combo box issue when emtpy

I can confirm there is an issue when the user clicks on any ComboBox with no entry added yet, and then if he clicks again on the ComboBox after some entries have been added. The PopupMenu doesn’t show up then.

I have written a solution, which will solve also another problem my code had, which was the fact that the variable noChoicesMessage wasn’t used anymore… (see here ComboBox with sub menus in the JUCE code)

With that code, the PopupMenu problem is solved, and a PopupMenu displaying the content of noChoicesMessage appears when there is no item in the ComboBox :

void ComboBox::showPopup()
{
    if (currentMenu.getNumItems() == 0)
    {
        PopupMenu menu;
        menu.addItem(1, noChoicesMessage, false, false);
        
        menu.setLookAndFeel(&getLookAndFeel());
        menu.showMenuAsync(PopupMenu::Options().withTargetComponent(this)
            .withItemThatMustBeVisible(getSelectedId())
            .withMinimumWidth(getWidth())
            .withMaximumNumColumns(1)
            .withStandardItemHeight(label->getHeight()),
            ModalCallbackFunction::forComponent(comboBoxPopupMenuFinishedCallback, this));
    }
    else
    {
        PopupMenu::MenuItemIterator iterator(currentMenu, true);
        const int selectedId = getSelectedId();

        while (iterator.next())
        {
            PopupMenu::Item &item = iterator.getItem();

            if (item.itemID != 0)
                item.isTicked = (item.itemID == selectedId);
        }

        currentMenu.setLookAndFeel(&getLookAndFeel());
        currentMenu.showMenuAsync(PopupMenu::Options().withTargetComponent(this)
            .withItemThatMustBeVisible(getSelectedId())
            .withMinimumWidth(getWidth())
            .withMaximumNumColumns(1)
            .withStandardItemHeight(label->getHeight()),
            ModalCallbackFunction::forComponent(comboBoxPopupMenuFinishedCallback, this));
    }
}

Tell me guys if this can be added in the JUCE code and if the problems are solved now (for me it worked on a project where I have been able to reproduce the issue).

Sorry about the inconvenience !

2 Likes