Repository navigation
Color picker undo fix - #7813
Conversation
Here is the correct branch with the Colorpicker undo functionality
Since I am using the DsColor class for the node there is no need to have the override since it's being controlled there anyway and has been removed.
This fixes the double up of value stores, however it still requires to do an initial undo twice.
add undo test
| public DSColor dsColor | ||
| private DSColor dscolor = DSColor.ByARGB(255, 0, 0, 0); | ||
| private DSColor prevColor = DSColor.ByARGB(255, 0, 0, 0); | ||
| private bool Isundo = false; |
There was a problem hiding this comment.
In what case do you expect this Isundo to be used? I only see it used in the setter. Also the naming is a bit confusing, can we make it more clearer by renaming to HasUndoableChange or IsUndoable, or something else
There was a problem hiding this comment.
IsUndo gets used when an Undo or Redo command is actually doing the property setting - when an Undo or Redo is effecting the property state we want to ignore this state, and not propagate an update, as this will get recorded as an undo state... which is not how the undo recorder works.
What about calling it - DoNotRecordForUndo
There was a problem hiding this comment.
to maybe clarify a bit more - we don't want undo's and redo's to alter the undo stack - just move up and down it.
There was a problem hiding this comment.
@mjkkirschner Thanks for the explaination. Generally for boolean, we come up with a name starting with is has can should, so in this case maybe ShouldRecordForUndo?
There was a problem hiding this comment.
sure, will go with that or something close.
| set | ||
| { | ||
| { | ||
| if (dscolor.Equals(value) ||prevColor.Equals(value)) |
There was a problem hiding this comment.
Also curious why do we need to compare with the prevColor here?
There was a problem hiding this comment.
we need to compare with previous color because if the value is same as the previous value or the current value we're potentially in an undo or a redo.
imagine undoing and redoing back and forth
| public ColorPalette() | ||
| { | ||
| { | ||
| //this.PropertyChanged += RaisePropertyChanged; |
| /// </summary> | ||
| public override bool IsInputNode | ||
| { | ||
| get { return false; } |
There was a problem hiding this comment.
Thought if we remove this we are allowing customizer to display color picker node?
There was a problem hiding this comment.
good point, not sure why this was removed, I'll add it back - THOUGH, now that we have UI nodes 🃏
add IsInputNode property back.
|
@QilongTang made the changes, PTAL |
| if (ShouldRecordForUndo) | ||
| { | ||
| //If undo recorder is not being used updates the undorecorder stack with new value | ||
| ShouldRecordForUndo = true; |
There was a problem hiding this comment.
When if satisfied, we do not need to set the boolean right? I feel like we can move this set to the else of the if above
QilongTang
left a comment
There was a problem hiding this comment.
One last question then LGTM
only set the undo state when the color picker window closes - this is closer to what is done with slider update tests
|
@QilongTang - after thinking about this and the flaw you identified for a while I decided to use a different approach. I got rid of the two way binding and handle the updates between the UI and model manually - this way when the color picker window closes we still have the old nodeModel state to save into the undo recorder - then we manually convert the color and update the model. We also bind to the property change event on the model manually and update the UI when the model changes, if the color is different than the one we already have selected. Another test is added. |
|
@QilongTang - the builds are failing due to a public nuget outage. |
|
@mjkkirschner LGTM |
Purpose
This PR enables undo/redo for the color picker - it finishes up changes initiated in this PR:
#7769
Because the xceed color picker provides no event before the color changes we use the property change event on the model to record the state of the model for undo, and save the state before we set the field to the new value.
As a consequence of this the undo action actually can set values into the undo redo stack... not good! So to avoid that another property Update is used to define when a redo/ undo should be recorded - An undo state should only be recorded when the new value is not equal to the current value or previous value - otherwise we are in an undo or redo.
There is also a test added - to facilitate this test I implemented UpdateValueCore for the color picker node.
Declarations
Check these if you believe they are true
*.resxfilesReviewers
@QilongTang
FYIs
@kronz @Gytaco