public void AddAction(HistoryElement newAction) // добавить действие в историю { lock (this) { if (m_historyCurrent == m_capacity - 1) { // увеличение емкости истории при переполнении m_capacity += m_capacity; HistoryElement[] increaseHistory = new HistoryElement[m_capacity]; Array.Copy(m_actionsArray, increaseHistory, m_actionsArray.Length); m_actionsArray = increaseHistory; } m_actionsArray[m_historyCurrent + 1] = newAction; m_historyCurrent++; m_historyLength = m_historyCurrent + 1; // зажигание события возможности отмены HistoryAllowedEventArgs undoEvargs = new HistoryAllowedEventArgs(true); OnUndoAllowed(undoEvargs); // зажигание события отсутсвия повтора HistoryAllowedEventArgs redoEvargs = new HistoryAllowedEventArgs(false); OnRedoAllowed(redoEvargs); } }
public HistoryElement Redo() // повтор действия из истории { if (!isRedo()) { return(null); } m_historyCurrent++; HistoryAllowedEventArgs historyEvargs = null; // зажигание события возможности повтора if (isRedo()) { historyEvargs = new HistoryAllowedEventArgs(true); OnRedoAllowed(historyEvargs); } else { historyEvargs = new HistoryAllowedEventArgs(false); OnRedoAllowed(historyEvargs); } // зажигание события возможности отмены historyEvargs = new HistoryAllowedEventArgs(true); OnUndoAllowed(historyEvargs); return(m_actionsArray[m_historyCurrent]); }
public HistoryElement Undo() // откат действия { if (!isUndo()) { return(null); } m_historyCurrent--; HistoryAllowedEventArgs historyEvargs = null; // зажигание события возможности отмены if (isUndo()) { historyEvargs = new HistoryAllowedEventArgs(true); OnUndoAllowed(historyEvargs); } else { historyEvargs = new HistoryAllowedEventArgs(false); OnUndoAllowed(historyEvargs); } // зажигание события возможности повтора historyEvargs = new HistoryAllowedEventArgs(true); OnRedoAllowed(historyEvargs); return(m_actionsArray[m_historyCurrent + 1]); }
protected virtual void OnRedoAllowed(HistoryAllowedEventArgs args) { if (RedoAllowed != null) { RedoAllowed(this, args); } }
public void Clear() // очистка истории (например сохранили все) { m_historyCurrent = -1; m_historyLength = 0; HistoryAllowedEventArgs historyEvargs = new HistoryAllowedEventArgs(false); OnUndoAllowed(historyEvargs); OnRedoAllowed(historyEvargs); }