다음을 통해 공유


Differentiating between Cut-Copy-Paste/Undo-Redo/Drag-Drop/Move

A couple of customers have asked this one, as they work with the Programming Model, how do I know if an activity has been drag-dropped vs Copy-Pasted vs an Undo-Redo happened.

How do the customers use it? Well, for one of them they wanted to change the name of the activity if it is a Copy-Paste as against a Undo_Redo. For example. In case of a Copy-Pasted activity, the new name should be Sequence2. While for a Undo-Redo, the name should still be Sequence1.

The bad news is there is no simple way to recognize the differenced. However, with certain bit of work, we can certainly differentiate between them.

Undo-Redo: Through the UndoEngine.IsUndoRedoInProgress

Copy-Paste vs a Move: This is the tricky one. There is no easy way to recognize this one. Hence we need to use the ModelService.ItemAdded and ModelService.ItemRemoved events. So in case a copy-paste happens we would only get the ModelService.ItemAdded event. However if a move happens we will get the ModelService.ItemRemoved and then the ModelService.ItemAdded events. Just ensure both the items are the same one and you have differentiated between the two.

Finally for a drag drop from the toolbox, simply have a property within the activity where its value is null and once instantiated, have the property value to be non-null. That way you would know for sure that it is not a drag-drop in the subsequent times.

 Thanks,

Kushal.

Comments

  • Anonymous
    December 22, 2009
    Thanks for the blog post Kushal!  Much appreciated. Notre

  • Anonymous
    February 16, 2010
    Hi Kushal I don't quite get how you differentiate between move and copy/paste.  When you move the modelService_Changed event fires twice.  Once for the remove, and once for the add.  As these are separate you can never compare the two lists together. Also, just to make things trickier, Moving within an activity fires “remove” then “add”, but a move between activities fires a “add” before the “remove”