Class PropValueState

java.lang.Object
com.iizigo.editor.PropValueState

public final class PropValueState extends Object
The state of one property that a value operation puts back at undo and redo: the value, detached from the property, and the flags of the property that a value set alters.

The value is kept in a clone of the property (GProp.clone()): every property class copies there a value that it changes in place - the map of a StringMapProp, the list of a StringArrayProp, the set of a StringSetProp, the KString Value of a ValueProp - so a value changed in place after the capture does not change what an undo or a redo puts back. Every restore sets a new copy taken from that clone, so the property never holds the copy kept here. A container is the exception: its value is its children, which are put back as the same instances in a copy of the array, as the operations always did. So is a property that cannot be cloned: its value is kept as it is. So is a read-only property, which is not cloned at all: it cannot be set, so an operation refuses it and never restores its state - and a read-only property that holds a KString cannot be cloned (its clone sets the value anew, on a property that carries the read-only flag).

The flags that a value set alters (CC-FIX-PROPVALUE-UNDO-FLAGS, at r21877):

  • The "validated" mark of a KStringProp (KStringProp.isUserValidated()): every value set clears it (KStringProp.onPropValueSet).
  • The provenance mark of a plain property, i.e. one that is not a container (GProp.hasPropProvenance()): the operations of the Designer set or clear it after a value set (PropProvenance). It is put back without an event, and the property is marked changed when the mark changed. The mark of a container is not kept here: no value set changes it, and it is never cleared.
A restore sets the value first and then the flags as they were captured, through the property's own API. The changed state of the transaction framework (GProp.hasChanged) is not restored: it says the property must be sent again, which is true after an undo as well. Nor is the error of a property: it is the verifier's verdict on a value, made again for the value put back. A flag that a value set alters in the future is added here, to capture(GProp) and restore(GProp).
Author:
Christopher Mindus
  • Method Details

    • capture

      public static PropValueState capture(GProp<?> gp)
      Captures the state of a property: its value, detached, and the flags that a value set alters.
      Parameters:
      gp - The property.
      Returns:
      The state.
    • restore

      public boolean restore(GProp<?> gp) throws PropException
      Restores the state on a property: sets a new copy of the value, then the flags as they were captured.
      Parameters:
      gp - The property: the one captured, or the one that took its place in the tree.
      Returns:
      true if the value changed.
      Throws:
      PropException - If the value cannot be set.
    • toString

      public String toString()
      Formats to string.
      Overrides:
      toString in class Object