caretaker.cs

来自「c#设计模式随书源码 c#设计模式随书源码」· CS 代码 · 共 53 行

CS
53
字号
using System;
using System.Collections ;
namespace Memento
{
	/// <summary>
	/// Summary description for CareTaker.
	/// </summary>
	public class CareTaker
	{
		private ArrayList drawings, undoList;
		private Memento mem;
		private VisRectangle[] draw_ings; //used only to make UML clearer
		public CareTaker(ArrayList dcol)
		{
			clear(dcol);
		}
		public void rememberPosition(VisRectangle vr) {
			mem = new Memento (vr);
			undoList.Add (mem);
		}
		public void clear(ArrayList drw) {
			drawings = drw;
			undoList = new ArrayList();
		}
		public void Add(int intg) {
			undoList.Add (intg);
		}
		public void removeDrawing() {
			drawings.RemoveAt (drawings.Count -1);
		}
		public void remove(Memento mem) {
			mem.restore ();
		}
		public void remove(int intg) {
			removeDrawing();
		}
		public void undo() {
			if(undoList.Count > 0) {
				int last = undoList.Count -1;
				object obj = undoList[last];
				try{
					Memento mem = (Memento)obj;
					remove(mem);
				}
				catch (Exception) {
					removeDrawing();
				}
				undoList.RemoveAt (last);
			}
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?