Skip to content

Color picker undo fix - #7813

Merged
mjkkirschner merged 7 commits into
DynamoDS:masterfrom
mjkkirschner:ColorPickerundofix
Apr 26, 2017
Merged

mjkkirschner merged 7 commits into
DynamoDS:masterfrom
mjkkirschner:ColorPickerundofix

Conversation

@mjkkirschner

Copy link
Copy Markdown
Member

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

  • The code base is in a better state after this PR
  • Is documented according to the standards
  • The level of testing this PR includes is appropriate
  • User facing strings, if any, are extracted into *.resx files
  • All tests pass using the self-service CI.
  • Snapshot of UI changes, if any.
  • Changes to the API follow Semantic Versioning, and are documented in the API Changes document.

Reviewers

@QilongTang

FYIs

@kronz @Gytaco

Gytaco and others added 4 commits April 10, 2017 23:08
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
@QilongTang QilongTang self-assigned this Apr 24, 2017
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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@mjkkirschner mjkkirschner Apr 24, 2017 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, will go with that or something close.

set
{
{
if (dscolor.Equals(value) ||prevColor.Equals(value))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also curious why do we need to compare with the prevColor here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got you. Make sense

public ColorPalette()
{
{
//this.PropertyChanged += RaisePropertyChanged;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's delete this

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do.

/// </summary>
public override bool IsInputNode
{
get { return false; }

@QilongTang QilongTang Apr 24, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought if we remove this we are allowing customizer to display color picker node?

@mjkkirschner mjkkirschner Apr 24, 2017 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, not sure why this was removed, I'll add it back - THOUGH, now that we have UI nodes 🃏

@QilongTang QilongTang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few questions

add IsInputNode property back.
@mjkkirschner

Copy link
Copy Markdown
Member Author

@QilongTang made the changes, PTAL

if (ShouldRecordForUndo)
{
//If undo recorder is not being used updates the undorecorder stack with new value
ShouldRecordForUndo = true;

@QilongTang QilongTang Apr 25, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 QilongTang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@mjkkirschner

Copy link
Copy Markdown
Member Author

@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.

@mjkkirschner

Copy link
Copy Markdown
Member Author

@QilongTang - the builds are failing due to a public nuget outage.

@QilongTang

Copy link
Copy Markdown
Contributor

@mjkkirschner LGTM

@mjkkirschner
mjkkirschner merged commit 42c36ea into DynamoDS:master Apr 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants