+ 11
How to use undo redo in my code?
Can someone show me with simplest example. Example : 2+1; 2+3 ... I prefer c#. You are welcome with java and c++.
1 Odpowiedź
+ 3
Try something similiar like:
public class Rectangle
{
private Stack _stack;
private int height = 10;
private int width = 10;
public void BeginEdit()
{
if (_stack == null)
{
_stack = new Stack();
}
Hashtable state = new Hashtable(4);
state["height"] = height;
state["width"] = height;
_stack.Push(state);
}
public void CommitEdit()
{
Hashtable editState = (Hashtable) _stack.Pop();
editState.Clear();
editState = null;
if (_stateStack.Count == 0)
{
_stateStack = null;
}
}
public void RollbackEdit()
{
Type type = this.GetType();
Hashtable editState = (Hashtable)_stateStack.Pop();
this.height = (int) editState["height"];
this.width = (int) editState["width"];
editState.Clear();
editState = null;
if (_stateStack.Count == 0)
{
_stateStack = null;
}
}
}