/// <summary> /// Manages the Redo Stack. /// </summary> /// <param name="index">The index to be used as the SelectionStart attribute.</param> /// <returns>RTF string.</returns> public string RedoCommand(out int index) { if (_redoStack.IsEmpty()) { index = 0; return(null); } string rtf = _redoStack.Pop(out index); //avoid repeating the insertion if _lastRemovedRtf when Redo is clicked multiple times if (!_lastUndoActionName.Equals("Redo") && !string.IsNullOrEmpty(_lastRemovedRtf) && !_undoStack.Top().Equals(_lastRemovedRtf)) { _undoStack.Push(_lastRemovedRtf, _lastIndex); } //avoid inserting the same value two times to the top of the stack if (!_undoStack.Top().Equals(rtf)) { _undoStack.Push(rtf, index); } _lastUndoActionName = "Redo"; return(rtf); }
/// <summary> /// Manages the Undo Stack. /// </summary> /// <param name="index">The index to be used as the SelectionStart attribute.</param> /// <param name="canRedo">Identifies if the command can be redone.</param> /// <returns>RTF string.</returns> public string RemoveCommand(out int index, bool canRedo) { string removedRtf = _undoStack.Pop(out index); if (_lastUndoActionName.Equals("Undo") && canRedo && !string.IsNullOrEmpty(_lastRemovedRtf) && !_undoStack.IsEmpty() && !_redoStack.Top().Equals(_lastRemovedRtf)) { _redoStack.Push(_lastRemovedRtf, _lastIndex); } else if (canRedo && !string.IsNullOrEmpty(removedRtf.Trim())) { _redoStack.Push(removedRtf, index); } else if (!string.IsNullOrEmpty(removedRtf.Trim())) { _redoStack.Push(removedRtf, index); } if (_undoStack.IsEmpty()) { _undoStack.Push(string.Empty, 0); } _lastUndoActionName = "Undo"; _lastRemovedRtf = removedRtf; _lastIndex = index; return(_lastRemovedRtf); }