/// <summary> /// Perform the redo operation. If an undo handler is specified, it /// will be used to perform the actual operation. Otherwise, the command /// instance is asked to perform the redo. /// </summary> public void Redo() { if (!CanRedo()) { return; } // Remove newest entry from the redo stack. UndoInfo info = (UndoInfo)m_redoStack.Pop(); // Perform the redo. Debug.Assert(info.m_undoCommand != null); if (info.m_undoHandler != null) { info.m_undoHandler.Redo(info.m_undoCommand); info.m_undoHandler.refreshHistory(m_undoList); } else { info.m_undoCommand.Redo(); } // Now the command is available for undo again. Put it back // into the undo list. m_undoList.Add(info); }
/// <summary> /// Perform the undo operation. If an undo handler is specified, it /// will be used to perform the actual operation. Otherwise, the command /// instance is asked to perform the undo. /// </summary> public void Undo() { if (!CanUndo()) { return; } // Remove newest entry from the undo list. UndoInfo info = (UndoInfo)m_undoList[m_undoList.Count - 1]; m_undoList.RemoveAt(m_undoList.Count - 1); // Perform the undo. Debug.Assert(info.m_undoCommand != null); if (info.m_undoHandler != null) { info.m_undoHandler.Undo(info.m_undoCommand); info.m_undoHandler.refreshHistory(m_undoList); } else { info.m_undoCommand.Undo(); } // Now the command is available for redo. Push it onto // the redo stack. m_redoStack.Push(info); }
/// <summary> /// Register a new undo command. Use this method after your /// application has performed an operation/command that is /// undoable. /// </summary> /// <param name="cmd">New command to add to the manager.</param> public void AddUndoCommand(UndoCommand cmd) { Debug.Assert(cmd != null); Debug.Assert(m_undoList.Count <= m_maxUndoLevel); if (m_maxUndoLevel == 0) { return; } UndoInfo info = null; if (m_undoList.Count == m_maxUndoLevel) { // Remove the oldest entry from the undo list to make room. info = (UndoInfo)m_undoList[0]; m_undoList.RemoveAt(0); } // Insert the new undoable command into the undo list. if (info == null) { info = new UndoInfo(); } info.m_undoCommand = cmd; info.m_undoHandler = null; m_undoList.Add(info); // Clear the redo stack. ClearRedo(); }
/// <summary> /// Clear the contents of the redo stack. /// </summary> private void ClearRedo() { while (m_redoStack.Count > 0) { UndoInfo info = (UndoInfo)m_redoStack.Pop(); info.m_undoCommand = null; info.m_undoHandler = null; } }
/// <summary> /// Clear the contents of the undo list. /// </summary> private void ClearUndo() { while (m_undoList.Count > 0) { UndoInfo info = (UndoInfo)m_undoList[m_undoList.Count - 1]; m_undoList.RemoveAt(m_undoList.Count - 1); info.m_undoCommand = null; info.m_undoHandler = null; } }
/// <summary> /// Get the next redo command. This is like a "Peek" /// method. It does not remove the command from the redo stack. /// </summary> /// <returns>The next redo command.</returns> public UndoCommand GetNextRedoCommand() { if (m_redoStack.Count == 0) { return(null); } UndoInfo info = (UndoInfo)m_redoStack.Peek(); return(info.m_undoCommand); }
/// <summary> /// Get the next (or newest) undo command. This is like a "Peek" /// method. It does not remove the command from the undo list. /// </summary> /// <returns>The next undo command.</returns> public UndoCommand GetNextUndoCommand() { if (m_undoList.Count == 0) { return(null); } UndoInfo info = (UndoInfo)m_undoList[m_undoList.Count - 1]; return(info.m_undoCommand); }
/// <summary> /// Register a new undo command along with an undo handler. The /// undo handler is used to perform the actual undo or redo /// operation later when requested. /// </summary> /// <param name="cmd">New command to add to the manager.</param> /// <param name="undoHandler">Undo handler to perform the actual undo/redo operation.</param> public void AddUndoCommand(UndoCommand cmd, IUndoHandler undoHandler) { AddUndoCommand(cmd); if (m_undoList.Count > 0) { UndoInfo info = (UndoInfo)m_undoList[m_undoList.Count - 1]; Debug.Assert(info != null); info.m_undoHandler = undoHandler; undoHandler.refreshHistory(m_undoList); } }
/// <summary> /// Retrieve all of the redo commands. Useful for debugging, /// to analyze the contents of the redo stack. /// </summary> /// <returns>Array of commands for redo.</returns> public UndoCommand[] GetRedoCommands() { if (m_redoStack.Count == 0) { return(null); } UndoCommand[] cmdList = new UndoCommand[m_redoStack.Count]; object[] objList = m_redoStack.ToArray(); for (int i = 0; i < objList.Length; i++) { UndoInfo info = (UndoInfo)objList[i]; cmdList[i] = info.m_undoCommand; } return(cmdList); }
/// <summary> /// Register a new undo command. Use this method after your /// application has performed an operation/command that is /// undoable. /// </summary> /// <param name="cmd">New command to add to the manager.</param> public void AddUndoCommand(UndoCommand cmd) { Debug.Assert(cmd != null); Debug.Assert(m_undoList.Count <= m_maxUndoLevel); if (m_maxUndoLevel == 0) return; UndoInfo info = null; if (m_undoList.Count == m_maxUndoLevel) { // Remove the oldest entry from the undo list to make room. info = (UndoInfo)m_undoList[0]; m_undoList.RemoveAt(0); } // Insert the new undoable command into the undo list. if (info == null) info = new UndoInfo(); info.m_undoCommand = cmd; info.m_undoHandler = null; m_undoList.Add(info); // Clear the redo stack. ClearRedo(); }