-1

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

It would be great to have some code samples.

Beska
  • 12,445
  • 14
  • 77
  • 112
Cornel
  • 4,652
  • 15
  • 48
  • 57

3 Answers3

7

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
  • 549
  • 3
  • 8
5

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

Dirk Vollmar
  • 172,527
  • 53
  • 255
  • 316
1

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

Eugene Yokota
  • 94,654
  • 45
  • 215
  • 319