private void InternalAddCommand(ICommand command) { Debug.Assert(MaxUndoLevel != 0); _undoStack.Push(command); _redoStack.Clear(); }
public void Clear_WithNonEmptyUndoAndRedoStacks_CanUndoIsFalse() { _undoRedoStack.AddAndExecute(new TestCommand()); _undoRedoStack.AddAndExecute(new TestCommand()); _undoRedoStack.Undo(); _undoRedoStack.Clear(); Assert.AreEqual(false, _undoRedoStack.CanUndo); }
public void NewCommand(string undoActionName, string rtf, string text, int index) { int popIndex; switch (undoActionName) { case "Typing": if (!"Typing".Equals(_lastUndoActionName)) { if (!string.IsNullOrEmpty(text) && _undoStack.Count == 1 && !string.IsNullOrEmpty(_lastUndoActionName)) { //this is an special case where we have emptied the stack (because an undo), there is some text in the editor //and we start typing again, then we save the current status (previously removed by undo) and //then we start saving the new status. if (!string.IsNullOrEmpty(_lastRemovedRtf)) { _undoStack.Push(_lastRemovedRtf, _lastIndex); } _undoStack.Push(rtf, index); _lastUndoActionName = undoActionName; } else { //normal case _undoStack.Push(rtf, index); _lastUndoActionName = undoActionName; } } else { //here we have 2 cases (one for typing and one for backspace) if (text.Length > _lastSavedText.Length) { //if (!_undoStack.IsEmpty()) _undoStack.Pop(out popIndex); _undoStack.Push(rtf, index); _lastUndoActionWasBackspace = false; } else { _undoStack.Push(rtf, index); _lastUndoActionWasBackspace = true; } } _redoStack.Clear(); _lastSavedText = text; break; case "Cut": case "Paste": case "Delete": UndoStackManipulation(undoActionName, rtf, text, index, out popIndex); break; } }
/// <summary>Clears all information from the undo redo buffer.</summary> public void ClearUndo() { _undoUnitCommands.Clear(); _undoStack.Clear(); _redoStack.Clear(); RefreshCanUndoCanRedo(); }
public void Push(List <UndoRedoInstance> instance) { if (!StackValid(_undoStack)) { return; } _undoStack.Push(instance); _redoStack.Clear(); UndoStackChanged?.Invoke(this, new EventArgs()); }
private void Clear(UndoRedoStack stack, bool silent = false) { if (!StackValid(stack)) { return; } stack.Clear(); if (!silent) { UndoStackChanged?.Invoke(this, new EventArgs()); } }
private void CloseDocument() { UndoRedoStack.Clear(); Pages.Clear(); }