/// <summary> /// Performs an undo action. /// </summary> /// <returns> /// Returns true if the undo action succeeds; otherwise, returns false. /// </returns> public bool Undo() { bool flag = true; if (AllowUndo && CanUndo) { IUndo undo = UndoList.Peek() as IUndo; try { if ((undo != null) && undo.CanUndo) { flag = undo.Undo(Context); } } catch { flag = false; } if (Context is Excel excel) { excel.ResumeInvalidate(); } if (flag) { RedoList.Push(UndoList.Pop()); RaiseChanged(UndoRedoOperation.Undo, undo.ToString()); } } return(flag); }
/// <summary> /// Undo the last entity change /// </summary> public void Undo() { _IsInUndoRedoOperation = true; if (UndoList.Count > 0) { // Extract the item from the undo list. int undoActionId = UndoList.Last().ActionId; UndoRedoEntityInfo <TEntity> item; for (int i = UndoList.Count - 1; i >= 0; i--) { item = UndoList.Last(); if (item.ActionId == undoActionId) { UndoList.RemoveAt(UndoList.Count - 1); List <UndoRedoEntityInfo <TEntity> > copyRedoList = RedoList.ToList(); copyRedoList.Add(item); // We need to copy the undo list here. List <UndoRedoEntityInfo <TEntity> > copyUndoList = UndoList.ToList(); FuncUndo(item); // Now repopulate the undo and redo lists. UpdateRedoList(copyRedoList); UndoList.Clear(); UndoList.AddRange(copyUndoList); } } SetActionId(_ActionId - 1); } _IsInUndoRedoOperation = false; }
/// <summary> /// Redo the last undone entity change /// </summary> /// <remarks> /// Unlike the undo operation, we don't need to copy the undo list out /// because we want the item we're redoing being added back to the redo /// list. /// </remarks> public void Redo() { _IsInUndoRedoOperation = true; if (RedoList.Count > 0) { // Extract the item from the redo list. int redoActionId = RedoList.Last().ActionId; UndoRedoEntityInfo <TEntity> item; for (int i = RedoList.Count - 1; i >= 0; i--) { item = RedoList.Last(); if (item.ActionId == redoActionId) { // Now, remove it from the list. RedoList.RemoveAt(RedoList.Count - 1); // Here we need to copy the redo list out because // we will clear the list when the Add is called and // the Redo is cleared there. List <UndoRedoEntityInfo <TEntity> > redoList = RedoList.ToList(); //Redo actionId should be the same as undo action id SetActionId(item.ActionId); // Redo the last operation. FuncRedo(item); // Add the last redo item into undo list AddUndo(item.ChangedEntity, item.PropertyName, item.OldValue, item.NewValue, item.MessageType); // Now reset the redo list. UpdateRedoList(redoList); } } } _IsInUndoRedoOperation = false; }
/// <summary> /// Adds an operation to <see cref="RedoList"/> but without performing it. /// </summary> public virtual void AddOperation(IReversibleOperation operation) { Assert.ValidateReference(operation); RedoList.Clear(); UndoList.Insert(0, operation); LastOperation = null; }
/// <summary> /// Adds an operation to <see cref="RedoList"/> and performs it. /// </summary> public virtual void AddAndExecuteOperation(IReversibleOperation operation) { Assert.ValidateReference(operation); RedoList.Clear(); UndoList.Insert(0, operation); operation.Redo(); LastOperation = operation; }
/// <summary> /// Adds an operation to <see cref="RedoList"/> but without performing it. /// </summary> /// <param name="operation">The operation to add.</param> public virtual void AddOperation(IReversibleOperation operation) { if (operation == null) { throw new ArgumentNullException(nameof(operation)); } RedoList.Clear(); UndoList.Insert(0, operation); LastOperation = IdentityOperation.Default; }
public void Redo() { if (CanRedo == false) { return; } UndoList.Push(_value); _value = RedoList.Pop(); OnPropertyChanged("Value"); OnPropertyChanged("CanUndo"); OnPropertyChanged("CanRedo"); }
public bool Undo() { if (UndoSize == 0) { return(false); } var action = UndoList.Pop(); action.PerformRevertAction(); RedoList.Push(action); return(true); }
/// <summary> /// Removes the first operation in <see cref="UndoList"/>, reverse its effect and adds it to <see cref="RedoList"/>. /// </summary> public virtual void Undo() { Assert.CheckCondition(UndoList.Count > 0); IReversibleOperation Operation = UndoList[0]; UndoList.RemoveAt(0); RedoList.Insert(0, Operation); Operation.Undo(); LastOperation = Operation; }
/// <summary> /// Removes the first operation in <see cref="RedoList"/>, perform it again and adds it to <see cref="UndoList"/>. /// </summary> public virtual void Redo() { Debug.Assert(RedoList.Count > 0); IReversibleOperation Operation = RedoList[0]; RedoList.RemoveAt(0); UndoList.Insert(0, Operation); Operation.Redo(); LastOperation = Operation; }
/// <summary> /// Adds an operation to <see cref="RedoList"/> and performs it. /// </summary> /// <param name="operation">The operation to add and execute.</param> public virtual void AddAndExecuteOperation(IReversibleOperation operation) { if (operation == null) { throw new ArgumentNullException(nameof(operation)); } RedoList.Clear(); UndoList.Insert(0, operation); operation.Redo(); LastOperation = operation; }
public bool Redo() { if (RedoSize == 0) { return(false); } var action = RedoList.Pop(); action.PerformAction(); UndoList.Push(action); return(true); }
public void Redo() { if (RedoList.Count > 0) { IUndoRedo item = RedoList.First(); RedoList.RemoveFirst(); LinkedList <IUndoRedo> cpyRedo = new LinkedList <IUndoRedo>(RedoList.ToList()); item.Redo(); RedoList = new LinkedList <IUndoRedo>(cpyRedo); RaisePropertyChanged("RedoDescription"); RaisePropertyChanged("UndoDescription"); } }
/// <summary> /// Performs a redo action. /// </summary> /// <returns> /// Returns true if the redo action succeeds; otherwise, returns false. /// </returns> public bool Redo() { bool flag = true; if (AllowUndo && CanRedo) { ICommand command = RedoList.Peek(); try { command.Execute(Context); } catch { flag = false; } if (flag) { UndoList.Push(RedoList.Pop()); RaiseChanged(UndoRedoOperation.Redo, command.ToString()); } } return(flag); }
/// <summary> /// Performs an <see cref="T:Action" /> and adds it to the undo list if the <see cref="T:Action" /> can be undone. /// </summary> /// <param name="action"> /// The <see cref="T:Action" />. /// </param> public bool Do(ICommand action) { if (action == null) { return(false); } bool flag = true; try { action.Execute(Context); } catch { flag = false; } if (Context is Excel excel) { excel.ResumeInvalidate(); } if (AllowUndo) { IUndo undo = action as IUndo; if (!flag || (undo == null)) { return(flag); } if ((MaxLength > 0) && (UndoList.Count >= MaxLength)) { ShrinkUndoList((UndoList.Count - MaxLength) + 1); } UndoList.Push(action); RedoList.Clear(); RaiseChanged(UndoRedoOperation.Do, action.ToString()); } return(flag); }
/// <summary> /// Adds a property from the view to the undo list /// </summary> /// <param name="entityHashCode">Hash code of the property instance</param> /// <param name="propertyName">Name of the property</param> /// <param name="oldValue">Old value of the property</param> /// <param name="newValue">New value of the property</param> /// <param name="actionId">Undo/Redo action id</param> /// <param name="messageType">Action to take when undoing/redoing</param> public void AddUndo(TEntity changedEntity, string propertyName, object oldValue, object newValue, EntityMessageType messageType) { UndoList.Add(new UndoRedoEntityInfo <TEntity>(changedEntity, propertyName, oldValue, newValue, ActionId, messageType)); RedoList.Clear(); }
public void Clear() { UndoList.Clear(); RedoList.Clear(); }
/// <summary> /// Refreshes the redo list with new entries /// </summary> /// <param name="redoList"></param> private void UpdateRedoList(List <UndoRedoEntityInfo <TEntity> > redoList) { RedoList.Clear(); RedoList.AddRange(redoList); }
/// <summary> /// Returns the manager to a state with no operation that can be performed or reversed. /// </summary> public virtual void Reset() { UndoList.Clear(); RedoList.Clear(); LastOperation = null; }
/// <summary> /// Returns all redo commands. /// </summary> public ICommand[] GetRedoList() { return(RedoList.ToArray()); }
/// <summary> /// Returns the manager to a state with no operation that can be performed or reversed. /// </summary> public virtual void Reset() { UndoList.Clear(); RedoList.Clear(); LastOperation = IdentityOperation.Default; }
public void ResetUndo() { UndoList.Clear(); RedoList.Clear(); }