Skip to main content

HistoryManager<T>

A class in Root.Township, the global namespace.

Undo and redo history in a fixed size ring buffer. The oldest action is released and dropped when it fills up.

Constructors​

MemberWhat it is
HistoryManager(int maxCount)Creates a HistoryManager from maxCount.

Fields​

5 private and internal fields
MemberWhat it is
private T[] actionsThe ring buffer of actions.
private int firstIndexSlot of the oldest action.
private bool isModifyingTrue while an undo or redo is running.
private int lastIndexSlot after the newest action, the redo limit.
private int nextIndexCursor: slot where the next action goes.

Properties​

MemberWhat it is
bool IsPushPossible { get; }False while an undo or redo is running, so actions made by it aren't recorded.
bool IsRedoPossible { get; }True if there is an undone action to redo.
bool IsUndoPossible { get; }True if there is an action to undo.

Events​

MemberWhat it is
event Action ItemPushedRaised after an action is added.

Methods​

MemberWhat it is
void Clear()Releases every stored action and empties the history.
void Push(T item)Adds an action at the cursor, dropping any redo history; ignored during undo or redo.
void Redo()Redoes the action at the cursor and moves forward.
void Undo()Moves back and undoes that action.
2 private and internal methods
MemberWhat it is
private void Back()Moves the cursor back one slot, wrapping around.
private void Forward()Moves the cursor forward one slot, wrapping around.