I have a ValueTree object, which I use with an UndoManager. It has a strange Undo/Redo behaviour, when using ValueTree::setPropertyExcludingListener
I set the properties of my ValueTree using ValueTree::setPropertyExcludingListener
. Because I do not want a certain listener to get informed. But I still want my ValueTree::Listener to get notified, when Undo or Redo happens.
So here is the thing: Undo is working fine - my listener gets informed. But Redo is not good. If I execute Redo, my listener is not informed.
The reason for this is in the ValueTree::SetPropertyAction class.
It behaves differently for Undo and for Redo. For Undo it will do a normal setProperty. But for Redo it is doing a setProperty, with Listener excluded.
Here is a code excerpt from ValueTree::SetPropertyAction :
bool perform() override
{
jassert (! (isAddingNewProperty && target->hasProperty (name)));
if (isDeletingProperty)
target->removeProperty (name, nullptr);
else
target->setProperty (name, newValue, nullptr, excludeListener);
return true;
}
bool undo() override
{
if (isAddingNewProperty)
target->removeProperty (name, nullptr);
else
target->setProperty (name, oldValue, nullptr);
return true;
}
(Note that “Redo” will isue a call to “perform”).
On first glance, this seems inconsistent to me. Could it be a bug?
Why should it exclude the listener for Redo, but not for Undo?
And more so, why only if you set a property, but not if you remove one?
Or is there a good explanation for this?
Ideally, I would like it to not exclude any listeners att all. Neither for Undo nor for Redo.
I am working on JUCE 5.4.2, develop branch from last week.