1

Closed

UndoRedo Command created even when no changes are made

description

In my application I start an undo/redo action (UndoRedoArea.Start) when the user grabs a figure (left mouse button), and commit it (UndoRedoArea.Commit) when they let go. If the user does not change the properties of the figure (eg. by dragging it) the commit still creates an undo/redo action. It would be nice if no undo/redo action was created if no changes were made.
Closed Jul 15, 2011 at 5:18 AM by SergeiArhipenko
Released in v1.0

comments

djpnewton wrote Jan 15, 2008 at 8:09 PM

My solution is as follows:
  • Add a property to the Command class "HasChanges":
    public bool HasChanges
    {
        get { return changes.Count > 0; }
    }
  • Change the Commit function of the UndoRedoArea class so that it checks the HasChanges property of the "currentCommand":
    public void Commit()
    {
        AssertCurrentCommand();
        if (currentCommand.HasChanges)
        {
            currentCommand.Commit();
    
            // add command to history (all redo records will be removed)
            int count = history.Count - currentPosition - 1;
            history.RemoveRange(currentPosition + 1, count);
    
            history.Add(currentCommand);
            currentPosition++;
            TruncateHistory();
    
            OnCommandDone(CommandDoneType.Commit);
        }
        currentCommand = null;
    }

wrote Feb 4, 2008 at 7:38 PM

wrote Feb 10, 2008 at 2:01 PM

wrote Jul 15, 2011 at 5:18 AM

wrote Feb 13, 2013 at 10:58 PM

wrote May 16, 2013 at 4:53 AM