public IUndoRedoAction Execute()
        {
            var ii = Collection as ISupportInitialize;

            if (ii != null)
            {
                ii.BeginInit();
            }
            IUndoRedoAction result = null;

            if (Args.Action == NotifyCollectionChangedAction.Add)
            {
                Collection.RemoveAt(Collection.Count - 1);
                result = new CollectionChangeUndoRedoAction(Collection, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, Args.NewItems));
            }
            if (Args.Action == NotifyCollectionChangedAction.Remove)
            {
                foreach (var i in Args.OldItems)
                {
                    Collection.Add(i);
                }
                result = new CollectionChangeUndoRedoAction(Collection, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, Args.OldItems));
            }
            if (ii != null)
            {
                ii.EndInit();
            }
            return(result);
        }
Exemplo n.º 2
0
 private void OnUndoRedoEnd(IUndoRedoAction action)
 {
     if (action is PostObjectTransformsChangedAction)
     {
         RefreshPositionAndRotation();
     }
 }
Exemplo n.º 3
0
 private void OnUndoRedoEnd(IUndoRedoAction action)
 {
     if (action is PostObjectTransformsChangedAction)
     {
         FitBoxToTargetHierarchy();
     }
 }
Exemplo n.º 4
0
        public static IUndoRedoAction Pop(List <IUndoRedoAction> list)
        {
            IUndoRedoAction topAction = list[0];

            list.RemoveAt(0);
            return(topAction);
        }
Exemplo n.º 5
0
        public void RecordAction(IUndoRedoAction action)
        {
            if (!_isEnabled)
            {
                return;
            }

            // We must handle a special scenario which can occur when the user has been undoing
            // actions and effectively moving the stack pointer somewhere in the middle of the
            // stack. In that case, when a new action is recorded, this action will invalidate
            // all actions which follow.
            if (_actionGroupStack.Count != 0 &&
                _stackPointer < _actionGroupStack.Count - 1)
            {
                // Calculate the index of the first action to be removed and the number of actions to remove
                // and then use these values to remove the correct range of actions from the stack.
                int removeStartIndex = _stackPointer + 1;
                int removeCount      = _actionGroupStack.Count - removeStartIndex;
                RemoveGroups(removeStartIndex, removeCount);
            }

            _actionGroupStack.Add(new ActionGroup(action));

            // The last step is to check if the current number of recorded actions is bigger than the
            // allowed maximum. If it is, we need to remove the action from the bottom of the stack.
            // Finally, we set the stack pointer to point to the last recorded action.
            if (_actionGroupStack.Count > _actionLimit)
            {
                RemoveGroups(0, 1);
            }
            _stackPointer = _actionGroupStack.Count - 1;
        }
Exemplo n.º 6
0
 private void OnUndoRedoEnd(IUndoRedoAction action)
 {
     if (action is ObjectExtrudeGizmoDragEnd)
     {
         FitBoxToTargets();
     }
 }
Exemplo n.º 7
0
    public void AddUndoRedoAction(IUndoRedoAction action)
    {
        if (enableUndoRedo == 0)
        {
            if (isInApplyUndo)
            {
                Message.Show("Nested ApplyDoUndo calls! This is bad!", "Undo Redo borked", "Ok");
                action.Do();
                return;
            }

            isInApplyUndo = true;

            action.Do();

            RedoStack.Clear();

            if (UndoStack.Count > 0)
            {
                var lastGroup = UndoStack.Peek();

                var currentTime = DateTime.Now;
                var diff        = (currentTime - lastGroup.LastActionTime).TotalMilliseconds;

                if (diff <= GroupingMS)
                {
                    lastGroup.Actions.Add(action);
                    lastGroup.LastActionTime = currentTime;
                }
                else
                {
                    var group = new UndoRedoGroup();
                    group.Actions.Add(action);
                    group.LastActionTime = currentTime;
                    UndoStack.Push(group);
                }
            }
            else
            {
                var group = new UndoRedoGroup();
                group.Actions.Add(action);
                group.LastActionTime = DateTime.Now;
                UndoStack.Push(group);
            }

            RaisePropertyChangedEvent("IsModified");
            RaisePropertyChangedEvent("CanUndo");
            RaisePropertyChangedEvent("CanRedo");
            RaisePropertyChangedEvent("DescriptionStack");

            isInApplyUndo = false;
        }
        else
        {
            action.Do();
        }
    }
        /// <summary>
        /// Adds action to Undo stack
        /// </summary>
        /// <param name="action">Action to track</param>
        public static void TrackAction(IUndoRedoAction action)
        {
            if (UndoActions.Count >= Capacity)
            {
                UndoActions.RemoveFirst();
            }

            UndoActions.AddLast(action);
            RedoActions.Clear();
        }
Exemplo n.º 9
0
        /// <summary>
        /// Registers an undo redo action.
        /// </summary>
        /// <param name="action">The action to register. Cannot be null.</param>
        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
        public void RegisterExecutedAction(IUndoRedoAction action)
        {
            Guard.NotNull(action, nameof(action));

            undoStack.Push(action);
            redoStack.Clear();

            OnStateChanged(StateChangedReason.Register, new List <IUndoRedoAction> {
                action
            });
        }
Exemplo n.º 10
0
        /// <summary>
        /// Undoes commands
        /// </summary>
        /// <param name="levels">number of commands to undo</param>
        public static void Undo(int levels)
        {
            for (int i = 0; i < levels; i++)
            {
                if (UndoActions.Count != 0)
                {
                    IUndoRedoAction command = UndoActions.Last.Value;
                    UndoActions.RemoveLast();
                    command.UnExecute();

                    if (RedoActions.Count >= Capacity)
                    {
                        RedoActions.RemoveFirst();
                    }

                    RedoActions.AddLast(command);
                }
            }
        }
Exemplo n.º 11
0
 public void Add(IUndoRedoAction redoAction)
 {
     UndoStack.Push(redoAction);
     RedoStack.Clear();
     this.RaisePropertyChangedEvents();
 }
Exemplo n.º 12
0
 public static void Push(List <IUndoRedoAction> list, IUndoRedoAction action)
 {
     list.Insert(0, action);
 }
Exemplo n.º 13
0
 /// <summary>
 /// Do the given action for the first time.  This method will call the Do() method on he action.
 /// </summary>
 /// <param name="action">The action to do.  The Do() method will be called</param>
 public void Do(IUndoRedoAction action)
 {
     action.Do();
     Done(action);
 }
Exemplo n.º 14
0
 /// <summary>
 /// Записывает действие в очередь на отмену
 /// </summary>
 public void PushAction(IUndoRedoAction action)
 {
     undoActions.Push(action);
     FireChanged(action.Target);
 }
Exemplo n.º 15
0
 /// <summary>
 /// Do the given action for the first time.  This method will call the Do() method on he action.
 /// </summary>
 /// <param name="action">The action to do.  The Do() method will be called</param>
 public void Do(IUndoRedoAction action)
 {
     action.Do();
     undoStack.Push(action);
     redoStack.Clear();
 }
Exemplo n.º 16
0
 public void Done(IUndoRedoAction action)
 {
     undoStack.Push(action);
     redoStack.Clear();
     OnUndoRedoAction.Fire();
 }
Exemplo n.º 17
0
        /// <summary>
        /// Adds a action to the composite action.
        /// </summary>
        /// <param name="action">The action to add.</param>
        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
        public void Add(IUndoRedoAction action)
        {
            Guard.NotNull(action, nameof(action));

            actions.Add(action);
        }
Exemplo n.º 18
0
 public ActionGroup(IUndoRedoAction action)
 {
     Actions.Add(action);
 }
 private void OnUndoRedo(IUndoRedoAction action)
 {
     OnTargetObjectGroupUpdated();
 }
Exemplo n.º 20
0
 public void Add(IUndoRedoAction redoAction)
 {
     UndoStack.Push(redoAction);
     RedoStack.Clear();
     this.RaisePropertyChangedEvents();
 }
Exemplo n.º 21
0
 public void AddUndoRedoOperation(IUndoRedoAction operation)
 {
     _undoRedoActions.Insert(0, operation);
 }