views:

618

answers:

3

Can anyone give an idea of how should I implement undo/redo of files (dirs, subdirs) mapped in a treeview - C#?

Would be great some code samples

+3  A: 

Undo / redo is typically implemented using the so-called "command pattern". Search with Google or read the following article:

http://blogs.vbcity.com/jspano/articles/198.aspx

0xA3
+1 for a Good answer, but no idea if it answers the question :)
Robert Gould
I also have no idea whether it answers the question ;-)
0xA3
with the new subject, do you understand the question?
Cornel
No. What are the actions that you want to do/undo?
0xA3
P.S.: Your subject simply repeats now what was already written in the first sentence.
0xA3
The TreeView can Cut/Copy/Paste mapped files. Undo/Redo should also be supported. Understood?
Cornel
+4  A: 

Consider implementing Command pattern (GoF):

  • Put your actions logic into classes which implement common ICommand {Do(); Undo();} interface.
  • On each user action you create object of command requested and initialize it with context parameters like new and old filename.
  • Call Do(), put object into stack of completed commands.
  • Each command is supplied with context, so by calling Undo() it can reverse changes.
  • Consider moving files into temporary folder instead of removals.
Ihar Voitka
A: 

For a quick linear undo/redo, you can use Memento pattern using zip of file as memento.

eed3si9n