AbortTransaction doesn't undo the changes

The application i’m writing has some property pages that modifiy the underlying document as the changes are made. This allows the user to see the effects of what they are doing in the dialog directly on the document view.



The only problem is that if I press the cancel button on my property page, then calling AbortTransaction does not replay the edits made to the document to undo the changes and restore the document to the state it was in before the dialog was invoked.



I can’t call GoUndoManagerCompoundEdit.Undo because the transaction isn’t complete, and I don’t want to complete it in order to call Undo because that will affect the Undo/Redo stack.



Is there anyone who can suggest another way of doing this, other than enumerating the individual edits and replaying them myself somehow?



Thanks

Ian

Yes, GoUndoManager.AbortTransaction is not supposed to undo any of the changes that may have happened during the transaction, just as FinishTransaction isn’t supposed to do them (again!).
I haven’t tried this, but you could try using:
public class CustomUndoManager : GoUndoManager {
public CustomUndoManager() {}
public void Unwind() {
GoUndoManagerCompoundEdit cedit = this.CurrentEdit;
if (this.TransactionLevel > 0 && cedit != null && !myPretendUndo) {
myPretendUndo = true;
cedit.IsComplete = true;
cedit.Undo();
cedit.Clear();
myPretendUndo = false;
}
}
public override bool IsUndoing {
get { return myPretendUndo || base.IsUndoing; }
}
private bool myPretendUndo = false;
}

thanks Walter



I guess this is a case of the solution staring me right in the face and I just didn’t see it. I never even considered subclassing the undo manager.

Well, you still got pretty close on your own.
I still haven’t tried it, but I suspect the compound edit isn’t really usable afterwards, and should be replaced instead of calling Clear() on it.
Maybe this functionality is an interesting extension to GoUndoManager. Although with nested transactions, it would need to be somewhat more sophisticated…