public void Push(UndoAction action) { // Remove any "redo" actions from the history. // +---+ +---+ +---+ +---+ +---+ // | 0 | > | 1 | > | 2 | > | 3 | > | 4 | // +---+ +---+ +---+ +---+ +---+ // ^current // count = 5; current = 2; // Remove the last 2 items. int nCount = m_history.Count; if (nCount > m_nCurrent + 1) { m_history.RemoveRange(m_nCurrent + 1, nCount - (m_nCurrent + 1)); if (m_owner != null) { m_owner.RemoveUndoRange(m_id, m_nCurrent + 1, nCount - (m_nCurrent + 1)); } } // Add the new item at the end. // +---+ +---+ +---+ +---+ // | 0 | > | 1 | > | 2 | > | N | // +---+ +---+ +---+ +---+ // ^old ^current m_history.Add(action); m_nCurrent++; if (m_owner != null) { m_owner.AddUndo(m_id, action); m_owner.SetCurrentUndo(m_id, m_nCurrent); } // Remove the oldest action if the stack is too large. // +---+ +---+ +---+ // | 1 | > | 2 | > | N | // +---+ +---+ +---+ // ^current if (m_history.Count > k_nMaxUndoHistory) { m_history.RemoveAt(0); m_nCurrent--; if (m_owner != null) { m_owner.RemoveUndo(m_id, 0); m_owner.SetCurrentUndo(m_id, m_nCurrent); } } }
public void Add(TabMgr.TabId id, UndoAction action) { ListBox lb = GetListbox(id); lb.Items.Add(action.Description); }
public void AddUndo(TabMgr.TabId id, UndoAction action) { m_undoHistory.Add(id, action); }