# ValueTree::setPropertyExcludingListener & Redo/Undo

**URL:** <https://forum.juce.com/t/valuetree-setpropertyexcludinglistener-redo-undo/31813>\
**Category:** General JUCE discussion\
**Created:** [February 17, 2019, 8:36pm UTC](https://forum.juce.com/t/valuetree-setpropertyexcludinglistener-redo-undo/31813 "2019-02-17T20:36:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alatar](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@alatar](https://forum.juce.com/u/alatar)\
**Post date:** [February 17, 2019, 8:36pm UTC](https://forum.juce.com/t/valuetree-setpropertyexcludinglistener-redo-undo/31813/1 "2019-02-17T20:36:01Z")

</div>

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 :

```auto
        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.

---

<div class="post-metadata">

**Author:** ![alatar](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@alatar](https://forum.juce.com/u/alatar)\
**Post date:** [February 20, 2019, 10:01am UTC](https://forum.juce.com/t/valuetree-setpropertyexcludinglistener-redo-undo/31813/2 "2019-02-20T10:01:14Z")

</div>

Hey @t0m or any one else from the JUCE team.  
Kind of interested to hear your point on this behaviour.

---

<div class="post-metadata">

**Author:** ![juan1979](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@juan1979](https://forum.juce.com/u/juan1979)\
**Post date:** [August 26, 2021, 7:20am UTC](https://forum.juce.com/t/valuetree-setpropertyexcludinglistener-redo-undo/31813/3 "2021-08-26T07:20:15Z")

</div>

I have the same problem. I only want to exclude a listener for a single call (to avoid convert to var and then from var a big block), but I don’t want to exclude it for undo/redo.

Since these listener are synchronous I placed a temporal bool flag to exclude instead using `setPropertyExcludingListener`. It seems it works fine.

My set function:

```auto
            avoidCallbackThisTime = true;
            parentTree.setProperty(id, ruleSetter.toVar(newVal), undoManager);

```

My `valueTreePropertyChanged` function:

```
     if (avoidCallbackThisTime == false)
     {
        // I do my data conversion / calls, here
     }
     else
     {
        avoidCallbackThisTime = false;
     }
```

---

<div class="post-metadata">

**Author:** ![blackhawkbravo1](https://avatars.discourse-cdn.com/v4/letter/b/c5a1d2/32.png) [@blackhawkbravo1](https://forum.juce.com/u/blackhawkbravo1)\
**Post date:** [April 22, 2023, 4:34pm UTC](https://forum.juce.com/t/valuetree-setpropertyexcludinglistener-redo-undo/31813/4 "2023-04-22T16:34:36Z")

</div>

I have the same issue, and had to work round as you describe

---

<div class="post-metadata">

**Author:** ![fravezAt](https://avatars.discourse-cdn.com/v4/letter/f/2bfe46/32.png) [@fravezAt](https://forum.juce.com/u/fravezAt)\
**Post date:** [February 29, 2024, 5:05pm UTC](https://forum.juce.com/t/valuetree-setpropertyexcludinglistener-redo-undo/31813/5 "2024-02-29T17:05:03Z")

</div>

Bumb. It would be nice to be able to still keep track of undoable actions when calling `ValueTree::setPropertyExcludingListener`
