ComboBox && AsyncUpdater

Hi Jules,

I’m using a ComboBox and running into some issues with the AsyncUpdater.

I have a ComboBox, and at times I need to clear it contents, repopulate it and set the selected item by giving it the item’s index. When I call clear(), it calls setSelectedItemIndex (-1) which results in triggerAsyncUpdate () being called.

Immediately after I have repopulated my ComboBox, I call setSelectedItemIndex(itemIndex, true) which should result in triggerAsyncUpdate () not being called.

But, the ComboBox::handleAsyncUpdate () is called (as a result of calling clear ()) after I’ve called setSelectedItemIndex (). This results in my listeners callback being called and me obtaining itemIndex which I just set with setSelectedItemIndex, which I do not want.

Would it be reasonable to change the clear method to add a dontSendChangeMessage = false parameter?

void clear(const bool dontSendChangeMessage = false);

void ComboBox::clear(const bool dontSendChangeMessage)
{
    items.clear();
    separatorPending = false;

    if (! label->isEditable())
        setSelectedItemIndex (-1, dontSendChangeMessage);
}

Philip

yes, that makes sense! I’ll add it.

can i add a personal thought on this ?
i would clearly avoid the double negation thing on the boolean flag, i’ve seen only the combo box have this, and would be sure better to have a sendMessage variable, not dontSendMessage which being is much more criptic (and different to the ones in the slider or textbox for example).

just to be more clear and along the lines of the other components !!

Yes, I agree, but in this case it needs to match the other methods in the class. What I really ought to do is use an enum like “dontSendChangeMessage” for that parameter, to make the calls to it more readable.