How do we normally implement "Undo"/"Redo" function?

  • Thread starter Thread starter babylon
  • Start date Start date
B

babylon

any facilities in csharp that can help me implmenting undo/redo in my
application?
thx
 
If you break down the problem, it's really easy to implement undo/redo based
on your application's common functionality.

Basically, there are two stacks Undo stack and Redo stack. The Redo stack
gets pushed with items that are popped from the Undo Stack. Whenever an
item is pushed to the Undo stack, the redo stack is cleared.

Depending on the operations, you can define classes that encapsulate the
action and the data associated with the action. For example, if you are
moving a control from one location to another, you'll store the control's
old and new location and the action is "move".

Hope this helps you get started on your own Undo/Redo stack.
-vJ
 
thanks everyone
so basically i can create something called "command", e.g. cut, copy, paste
and store the commands that the user has performed

and each command itself knows how to undo

so, e.g. if the user cut a section of text
a CutCommand (inherit from Command) is created and the text is stored in the
CutCommand
and the CutCommand itself is store on a Undo stack

when user choose undo, we retrive the command from the top of the stack and
ask it to redo
in this case, as the CutCommand stored the text that was cut, so i can paste
back the text

thank!
 
Back
Top