Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        /// <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;
        }
Exemplo n.º 3
0
        /// <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;
        }
Exemplo n.º 4
0
        /// <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;
        }
Exemplo n.º 5
0
        /// <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;
        }
Exemplo n.º 6
0
        /// <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;
        }
Exemplo n.º 7
0
 public void Redo()
 {
     if (CanRedo == false)
     {
         return;
     }
     UndoList.Push(_value);
     _value = RedoList.Pop();
     OnPropertyChanged("Value");
     OnPropertyChanged("CanUndo");
     OnPropertyChanged("CanRedo");
 }
Exemplo n.º 8
0
        public bool Undo()
        {
            if (UndoSize == 0)
            {
                return(false);
            }
            var action = UndoList.Pop();

            action.PerformRevertAction();
            RedoList.Push(action);
            return(true);
        }
Exemplo n.º 9
0
        /// <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;
        }
Exemplo n.º 10
0
        /// <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;
        }
Exemplo n.º 11
0
        /// <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;
        }
Exemplo n.º 12
0
        public bool Redo()
        {
            if (RedoSize == 0)
            {
                return(false);
            }

            var action = RedoList.Pop();

            action.PerformAction();
            UndoList.Push(action);
            return(true);
        }
Exemplo n.º 13
0
        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");
            }
        }
Exemplo n.º 14
0
        /// <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);
        }
Exemplo n.º 15
0
        /// <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);
        }
Exemplo n.º 16
0
 /// <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();
 }
Exemplo n.º 17
0
 public void Clear()
 {
     UndoList.Clear();
     RedoList.Clear();
 }
Exemplo n.º 18
0
 /// <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);
 }
Exemplo n.º 19
0
 /// <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;
 }
Exemplo n.º 20
0
 /// <summary>
 /// Returns all redo commands.
 /// </summary>
 public ICommand[] GetRedoList()
 {
     return(RedoList.ToArray());
 }
Exemplo n.º 21
0
 /// <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;
 }
Exemplo n.º 22
0
 public void ResetUndo()
 {
     UndoList.Clear();
     RedoList.Clear();
 }