How to cancel paste operation

Hi Walter,

When the paste transaction is completed, we have some check. If the check fails we would like cancel the paste operation.

How to achieve this functionality? Is there any built in support for this at your level?

Thanks

Are you doing the check in a Diagram.ClipboardPasted event handler?

If so, perhaps you could call CommandHandler.Delete, because all of the new Parts are now selected. Or just call PartManager.DeleteParts on the Diagram.SelectedParts collection, which is the same but without the additional Diagram events and nested transaction.

We have built the application in a model driven architecture. We subscribe to Diagram.Model.Changed event to get the updates.
When we paste, we get notified in the handler of the above mentioned event. We could see the transaction is completed when we get notified. At certain scenario, we want to cancel the paste operation.
If we call CommandHandler.Delete or PartManager.DeleteParts , would it create a new transaction? If yes, would it impact the undo/redo operation?
We are looking for a more graceful way of handling the scenario. Is it possible to cancel the whole paste operation or revert to the transaction without impacting the undo/redo operation?

That is why I was asking when you are detecting and deciding to cancel the paste.

If it is in the paste’s transaction, such as in a Diagram.ClipboardPasted event handler, then the transaction is still ongoing, so you can just remove those extra Parts.

If you are doing it after the paste has completed, outside of any transaction, then you could just undo it.

In our application, we handle the paste operation after the completion of paste transaction.
We tried with commandhandler’s undo. When we did redo it got pasted again. How to get rid of the complete transaction from undoredo manager?

Remove the last item from the UndoManager.CompoundEdits list. Maybe something like:

var mgr = model.UndoManager;
if (mgr.CanUndo()) {
  mgr.Undo();
  var edit = mgr.EditToRedo;
  if (edit != null) {
    edit.Clear();
    mgr.CompoundEdits.Remove(edit);
  }
}

I hope this does what you want.