How to make ComboBox update its item list with Undo/Redo?

I use ComboBox with UndoManager.
The ComboBox selected item refers to ValueTree property, so Undo/Redo works automatically.

Things get problematic when something outside of the described above system needs to update the ComboBox item list content AND also has to work properly with UndoManager for proper Undo/Redo.

The problem is this:
Undo/Redo for that outside system might add or remove items from that ComboBox item list. The only way to do this is manually, instead of relying on UndoManager. To remove items you first need to clear the whole list and then add the remaining items back into the list. If the ComboBox selected item is referring to ValueTree property, that property will change during this operation. That messes up the Undo/Redo history as it suddenly adds new change to the UndoManager which wasn’t there before.

How to go around this issue? How do I make ComboBox update its item list with Undo/Redo?

TLDR:
Undo/Redo for X requires “manual” updates (done outside UndoManager) to ComboBox item list content, which adds new items to UndoManager history. This messes up the Undo/Redo history.

The exact use case scenario is that the Combobox is owned by a mixer audio channel Component, which should update the Combobox content every time output audio channel Components are added/deleted from the screen. I.e. the Combobox should list available output audio channels.

Anyone?

Is this an issue which has no solution?

Instead of using the Value exposed by the ComboBox directly, maybe you could add a new layer in between the ValueTree’s value and the ComboBox. This new layer would listen to the Value and update the ComboBox index as appropriate, and would also listen to the ComboBox to update the Value when the ComboBox is changed by the user. When you manually update the ComboBox, you can now do this without updating the ValueTree’s value.

1 Like

You could also just don’t use the ComboBox component, but a button that opens a PopupMenu. You can then populate the popup menu on the fly (when the button is clicked) with what’s available and remember the last selected value.

1 Like

Both Reuk’s and Rincewind’s suggestions seem viable. Rincewind’s suggestion might actually be easier to implement in my use-case. I’ll try that first and see what happens.

Thank you both!