Values, PropertyComponents and UndoManagers


#1

When using PropertyComponents with Values, there doesn’t appear to currently be any way to handle transactions, which strikes me as being a bit of a hindrance to their otherwise super-swishy usefulness.

Currently, I’m subclassing the PropertyComponents, and overriding the ‘set’ so I can do whatever else I need with the UndoManager before the user’s changes are applied. Of course, though the undoable act of actually changing the Value can be handled by the value itself (if it came from a ValueTree), the UndoManager it uses is hidden, so I just have to hope that the propertyComponent and Value objects are using the same one.

Is there a neater/existing way to handle this sort of business?


#2

The way I’ve been doing it so far in the new jucer is by having a 1 second timer, triggered by a change anywhere the valuetree, which starts a new transaction when it gets called. So if the user’s performing a continuous stream of changes, the timer will keep getting restarted and not fire, but when they pause for a second, it fires and a new transaction starts. Not sure if this is the best possible way to do it, but seems ok so far…


#3

I was wondering the same, first so I can make a set of changes happen at once, and also thinking of doing what Hayden is to do ‘snapshots’ or similar.

In my case, I may have 20 or so values that I want to change in one action, so that I can efficiently package them as one TCP/IP command (for instance). I’d think the UndoManager approach would work, since the time I really need to package is when it’s a snapshot recall.

Jules, maybe the UndoManager should actually be a ‘ValueManager’ that can be subclassed? Then it implies we can do more clever things with the flow of value sets and gets (such as saving them to a file).

So, I guess I would request the Undo/ValueManager have a light transaction system? Or at least some kind of markers, like a special action (undo back to last marker, etc.).

Bruce


#4

Actually, for the purposes of property components (where one tweak = one action), I’ve realised (doh) that I can simply wrap the Values in a new UndoTransactionWrappingValueSource. This takes a Value, a String and an UndoManager, and simply begins a new transaction when the value is set, and then sets the value of the target. It also has to listen to changes in the target, so it can rebroadcast them (otherwise the property component would not update with the undo).

It’d probably be worth giving it a timer too, so it only starts a new transaction if the last transaction has a different name or a certain amount of time has passed since it last set it. Or something… none of my current controls can be adjusted that fast anyway so I’m not too concerned about that yet! :slight_smile: