using System.Collections.Generic; using Microsoft.VisualBasic.CompilerServices; namespace Pilz.Collections.SimpleHistory { public class HistoryStack { private Stack stackPast = new Stack(); private Stack stackFuture = new Stack(); /// /// Gets the count of history points. /// /// public bool ChangesCount { get { return Conversions.ToBoolean(stackPast.Count); } } /// /// Checks if the History has past changes. /// /// public bool HasChanges() { return stackPast.Count > 0; } /// /// Patch Object States and call Undo Actions. /// public HistoryPoint Undo() { HistoryPoint ret; if (stackPast.Count > 0) { var hp = stackPast.Pop(); hp.Undo(); stackFuture.Push(hp); ret = hp; } else { ret = null; } return ret; } /// /// Patch Object States and call Redo Actions. /// public HistoryPoint Redo() { HistoryPoint ret; if (stackFuture.Count > 0) { var hp = stackFuture.Pop(); hp.Redo(); stackPast.Push(hp); ret = hp; } else { ret = null; } return ret; } /// /// Clear the History. /// public void Clear() { stackPast.Clear(); stackFuture.Clear(); } /// /// Store a History Point. /// /// The History Point to add to the past changes. /// The name to set for the History Point. public void Store(HistoryPoint point, string newName) { point.Name = newName; Store(point); } /// /// Store a History Point. /// /// The History Point to add to the past changes. public void Store(HistoryPoint point) { stackPast.Push(point); stackFuture.Clear(); } } }