Beispiel #1
0
        /// <summary>
        /// Executes the command and return a token that can be used to undo it.
        /// </summary>
        /// <param name="parameter">The command parameter.</param>
        /// <param name="createActionItem">Indicates whether to create an action item in the action stack. This should be false in case of a Redo operation.</param>
        /// <returns>An <see cref="UndoToken"/> that can be used to undo the command.</returns>
        public UndoToken ExecuteCommand(object parameter, bool createActionItem)
        {
            // TODO: Improve this - we're discarding any change made directly by the command invoke and create a CommandActionItem after.
            // NOTE: PickupAssetCommand is currently assuming that there's such a transaction in progress, be sure to check it if changing this.
            var transactionalActionStack = ActionStack as ITransactionalActionStack;

            if (transactionalActionStack != null)
            {
                transactionalActionStack.BeginTransaction();
            }

            UndoToken token = Redo(parameter, createActionItem);

            if (transactionalActionStack != null)
            {
                transactionalActionStack.DiscardTransaction();
            }

            if (token.CanUndo && createActionItem)
            {
                var actionItem = new CommandActionItem(this, parameter, token, Dirtiables);
                ActionStack.Add(actionItem);
            }
            return(token);
        }
        /// <summary>
        /// Executes the command and return a token that can be used to undo it.
        /// </summary>
        /// <param name="parameter">The command parameter.</param>
        /// <param name="createActionItem">Indicates whether to create an action item in the action stack. This should be false in case of a Redo operation.</param>
        /// <returns>An <see cref="UndoToken"/> that can be used to undo the command.</returns>
        public UndoToken ExecuteCommand(object parameter, bool createActionItem)
        {
            // TODO: Improve this - we're discarding any change made directly by the command invoke and create a CommandActionItem after.
            // NOTE: PickupAssetCommand is currently assuming that there's such a transaction in progress, be sure to check it if changing this.
            var transactionalActionStack = ActionStack as ITransactionalActionStack;
            if (transactionalActionStack != null)
                transactionalActionStack.BeginTransaction();

            UndoToken token = Redo(parameter, createActionItem);
            
            if (transactionalActionStack != null)
                transactionalActionStack.DiscardTransaction();
            
            if (token.CanUndo && createActionItem)
            {
                var actionItem = new CommandActionItem(this, parameter, token, Dirtiables);
                ActionStack.Add(actionItem);
            }
            return token;
        }
        /// <summary>
        /// Executes the command and return a token that can be used to undo it.
        /// </summary>
        /// <param name="parameter">The command parameter.</param>
        /// <param name="createActionItem">Indicates whether to create an action item in the action stack. This should be false in case of a Redo operation.</param>
        /// <returns>An <see cref="UndoToken"/> that can be used to undo the command.</returns>
        public UndoToken ExecuteCommand(object parameter, bool createActionItem)
        {
            // TODO: Improve this - we're discarding any change made directly by the command invoke and create a CommandActionItem after.
            var transactionalActionStack = actionStack as ITransactionalActionStack;

            if (transactionalActionStack != null)
            {
                transactionalActionStack.BeginTransaction();
            }

            UndoToken token = Redo(parameter, createActionItem);

            if (transactionalActionStack != null)
            {
                transactionalActionStack.DiscardTransaction();
            }

            if (token.CanUndo && createActionItem)
            {
                var actionItem = new CommandActionItem(this, parameter, token, dirtiables);
                actionStack.Add(actionItem);
            }
            return(token);
        }