UndoRedoStack
๊ฐ์
UndoRedoStack์ ์คํ ์ทจ์์ ๋ค์ ์คํ์ ํ๊ธฐ ์ํด ๊ตฌํํ ๋์์ธ ํจํด์ด์์.
๋ค์ํ ์ํํธ์จ์ด์์ ๊ฐ์์ ๋ฐฉ๋ฒ์ผ๋ก ๊ตฌํ ๋์ด ์์ง๋ง, ์ ๋ ์กฐ๊ธ ๊ฐ๋จํ๊ฒ ํ์ํ ๊ธฐ๋ฅ๋ง ๊ตฌํํ์ฌ ๊ฐ ๊ธฐ๋ฅ๋ค์ ์ก์ (Action)์ผ๋ก ๋๋์ด ๋ณด์์ด์.
๊ทธ๋ฆฌ๊ณ ๊ฐ Action์ ๋ฌถ์ ActionBlock ํด๋์ค๋ฅผ ๋ง๋ค์ด Sequence๋ฅผ ๊ตฌํํ๋๋ก ํ์ด์.
์ด๋ฅผ ํตํด ๋ณต์กํ Undo ๋๋ Redo ์์ ์ ํ๋ฒ์ ์ฒ๋ฆฌ ํ ์ ์์ด์.
IUndoableAction
public interface IUndoableAction
{
void Do();
void Undo();
}ActionBlock
public class ActionBlock : IUndoableAction
{
private readonly IUndoableAction[] actionSequence;
public ActionBlock(params IUndoableAction[] actionSequence)
{
this.actionSequence = actionSequence;
}
public void Do()
{
foreach (var action in actionSequence)
action.Do();
}
public void Undo()
{
foreach (var action in actionSequence.Reverse())
action.Undo();
}
public override string ToString()
{
return string.Join(",", actionSequence.Select(a => a.ToString()));
}
}UndoRedoStack
Reference.
Last updated