예제 #1
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;
        }
예제 #2
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;
        }
예제 #3
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");
            }
        }