Exemplo n.º 1
0
        public void Perform(OgmoAction action)
        {
            if (action == null)
            {
                return;
            }

            //If a batch is in progress, stop it!
            EndBatch();

            //If you're over the undo limit, chop off an action
            while (UndoStack.Count >= Properties.Settings.Default.UndoLimit)
            {
                UndoStack.RemoveFirst();
            }

            //If the level is so-far unchanged, change it and store that fact
            if (!Level.Changed)
            {
                action.LevelWasChanged = false;
                Level.Changed          = true;
            }

            //Add the action to the undo stack and then do it!
            UndoStack.AddLast(action);
            action.Do();

            //Clear the redo stack
            RedoStack.Clear();
        }
Exemplo n.º 2
0
        public void Redo()
        {
            if (RedoStack.Count == 0)
            {
                return;
            }

            var operationNode        = RedoStack.Last;
            var currentTransactionId = operationNode.Value.TransactionId;

            while (operationNode != null && operationNode.Value.TransactionId == currentTransactionId)
            {
                var prev      = operationNode.Previous;
                var operation = RedoStack.Last.Value;
                operation.Redo();

                // Add operation into Undo stack.
                UndoStack.AddLast(operation);

                // Remove from redo stack.
                RedoStack.RemoveLast();

                operationNode = prev;
            }

            ++ActiveTransactionIdCount;
        }
Exemplo n.º 3
0
        private void AddOperationToUndoStack(IUndoRedoOperation operation)
        {
            if (ActiveTransactionIdCount >= Constants.UndoRedoTransactionCapacity)
            {
                var transactionIdToRemove = UndoStack.First?.Value.TransactionId;
                while (UndoStack.First?.Value.TransactionId == transactionIdToRemove)
                {
                    UndoStack.RemoveFirst();
                }

                --ActiveTransactionIdCount;
            }

            UndoStack.AddLast(operation);
        }
Exemplo n.º 4
0
        /// <summary>
        /// execute and store a command
        /// </summary>
        /// <param name="myAction">the command to be executed</param>
        /// <returns>bool: whether or not it was able to execute the command</returns>
        private bool Execute(ICommand myAction)
        {
            //Check if the command can be stacked with the previous one
            if (StackCommand(myAction))
            {
                return(true);
            }

            if (myAction.Execute())
            {
                UndoStack.AddLast(myAction);
                return(true);
            }

            return(false);
        }
Exemplo n.º 5
0
        public void StartBatch()
        {
            batch = new ActionBatch();

            if (!Level.Changed)
            {
                batch.LevelWasChanged = false;
                Level.Changed         = true;
            }

            while (UndoStack.Count >= Properties.Settings.Default.UndoLimit)
            {
                UndoStack.RemoveFirst();
            }
            UndoStack.AddLast(batch);
            RedoStack.Clear();
        }
Exemplo n.º 6
0
        public void Redo()
        {
            if (RedoStack.Count > 0)
            {
                //Remove it
                OgmoAction action = RedoStack.Last.Value;
                RedoStack.RemoveLast();

                //Redo it
                action.Do();

                //Mark level as changed
                Level.Changed = true;

                //Add it to the undo stack
                UndoStack.AddLast(action);
            }
        }