Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undo/Redo cleanup #1510

Merged
merged 10 commits into from
Feb 8, 2021
Merged

Undo/Redo cleanup #1510

merged 10 commits into from
Feb 8, 2021

Conversation

corranwebster
Copy link
Contributor

@corranwebster corranwebster commented Jan 30, 2021

This PR does a number of things:

  • adds comprehensive tests for most of the classes in traits.undo
  • makes AbstractUndoItem inherit from AbstractCommand (the interfaces were almost identical)
    • updates the code so that it uses the AbstractCommand interface which permits the use of arbitrary Pyface commands in the TraitsUI history interface.
    • add backward compatibility shims so in the event that third parties are using the AbstractUndoItem API then everything should still work.
    • recommends removal of the AbstractUndoItem.merge_undo method in TraitUI 8 (in fact we can probably remove AbstractUndoItem as well.
  • fixes Bug merging strings in UndoItem #1506
  • fixes Adding a mergeable UndoItem to middle of UndoHistory does not fire redoable event #1509
  • adds some stub documentation about how the Undo/Redo system works.

This PR should be backward compatible, so can be included in the next minor release.

This is a safe first step for #1060.

Copy link
Contributor

@rahulporuri rahulporuri left a comment

Choose a reason for hiding this comment

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

LGTM with a few comments/questions.

docs/source/traitsui_user_manual/handler.rst Outdated Show resolved Hide resolved
docs/source/traitsui_user_manual/handler.rst Outdated Show resolved Hide resolved
Comment on lines +318 to 321
#: List of accumulated undo changes. Each item is a list of
#: AbstractUndoItems that should be done or undone as a group.
#: This trait should be considered private.
history = List()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#: List of accumulated undo changes. Each item is a list of
#: AbstractUndoItems that should be done or undone as a group.
#: This trait should be considered private.
history = List()
#: List of accumulated undo changes. Each item is a list of
#: AbstractUndoItems that should be done or undone as a group.
#: This trait should be considered private.
history = List(List(Instance(AbstractUndoItem)))

Is ^ the right trait definition - based on the docstring you added.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should probably be List(List(Instance(ICommand))).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But I am hesitant to over-specify it as I would like to replace this state with an UndoManager, so UndoHistory is essentially just a wrapper around UndoManager. Still investigating how much that actually breaks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have decided to not make ths change for now.

removed=removed.copy(),
)

result = undo_item.merge(next_undo_item)
Copy link
Contributor

Choose a reason for hiding this comment

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

i don't fully understand why this behavior exists - why merging identical values (does that mean the same id) is accepted but equal values doesn't work as expected. Is this a bug which was reported recently?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is testing declared behaviour from this comment:

traitsui/traitsui/undo.py

Lines 242 to 244 in 79b66f5

# Discard undo items that are identical to us. This is to eliminate
# the same undo item being created by multiple listeners monitoring the
# same list for changes:

Since it is declared it should be tested that the code does what it says; if we feel that relaxing to equality is desirable, we should modify the code and the comment, but I don't have enough insight into whether that would be a problem.

@corranwebster
Copy link
Contributor Author

Ah - just realized there is a missing piece in this. If we accept arbitrary ICommand instances in the history, then we need to call do() somewhere, and we should add a test for this.

@rahulporuri
Copy link
Contributor

Ah - just realized there is a missing piece in this. If we accept arbitrary ICommand instances in the history, then we need to call do() somewhere, and we should add a test for this.

Just so i'm clear, this PR is on hold until ^ changes are made?

@corranwebster
Copy link
Contributor Author

That plus the suggested doc fixes - this one is a spare-time effort.

@corranwebster
Copy link
Contributor Author

@rahulporuri I think this is good to go.

This now:

  • fixes the issue I mentioned with the do method
  • adds a deprecation warning for the old API
  • adds tests for these
  • adds hyperlinks and a but of clean-up to the new documentation.

Copy link
Contributor

@rahulporuri rahulporuri left a comment

Choose a reason for hiding this comment

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

Still LGTM

Comment on lines +70 to +71
"'merge_undo' is deprecated and will be removed in TraitsUI 8, "
"use 'merge' instead",
Copy link
Contributor

Choose a reason for hiding this comment

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

It'll be useful to track this in an issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@corranwebster corranwebster merged commit 23f17d1 into master Feb 8, 2021
@corranwebster corranwebster deleted the enh/undo-cleanup branch February 8, 2021 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants