Пример #1
0
        /// <summary>
        /// Delegate called when a command is undone.
        /// </summary>
        /// <param name="pSource">The source command.</param>
        /// <param name="pEventArgs">The event arguments.</param>
        protected virtual void CustomOnCommandUndone(IUserCommand pSource, CommandExecutionEventArgs pEventArgs)
        {
            // Updating the current command index.
            int lCommandIndex = this.CommandsList.IndexOf(pEventArgs.Command);

            this.CurrentCommandIndex = --lCommandIndex;
        }
Пример #2
0
        /// <summary>
        /// Delegate called when a command is done.
        /// </summary>
        /// <param name="pSource">The source command.</param>
        /// <param name="pEventArgs">The event arguments.</param>
        protected virtual void CustomOnCommandDone(IUserCommand pSource, CommandExecutionEventArgs pEventArgs)
        {
            // Verifying if the context must be changed.
            if (pEventArgs.Command.State == UserCommandState.SwitchContext)
            {
                ISwitchContextCommand lCommand = pEventArgs.Command as ISwitchContextCommand;
                if (lCommand != null)
                {
                    string lNewContextId = lCommand.SwitchContext(this.Id);
                    this.mParentManager.SwitchContext(lNewContextId);
                }
            }

            // Evaluating if the new command must be added in the context list.
            bool lAddCommand = true;

            if (this.CommandsList.Any() && this.LastExecutedCommand != null && pEventArgs.Command.State == UserCommandState.Undoable)
            {
                lAddCommand = this.LastExecutedCommand.TryMerge(pEventArgs.Command) == false;
            }
            if (pEventArgs.Command.State != UserCommandState.Undoable)
            {
                lAddCommand = false;
            }

            // Adding the command in the list if wanted.
            if (lAddCommand)
            {
                this.CommandsList.Add(pEventArgs.Command);
                this.CurrentCommandIndex = this.CommandsList.Count - 1;
            }
        }
Пример #3
0
        /// <summary>
        /// Delegate called when a command is undoing.
        /// </summary>
        /// <param name="pSource">The source command.</param>
        /// <param name="pEventArgs">The event arguments.</param>
        private void OnCommandUndoing(IUserCommand pSource, CommandExecutionEventArgs pEventArgs)
        {
            // Custom process.
            this.CustomOnCommandUndoing(pSource, pEventArgs);

            // Internal notification.
            if (this.CommandUndoing != null)
            {
                this.CommandUndoing(this, pEventArgs);
            }

            // Manager notification.
            this.mParentManager.NotifyCommandExecution(UserCommandManager.CommandExecutionType.Undoing, pEventArgs);
        }
Пример #4
0
        /// <summary>
        /// Delegate called when a command is done.
        /// </summary>
        /// <param name="pSource">The source command.</param>
        /// <param name="pEventArgs">The event arguments.</param>
        protected override void CustomOnCommandDone(IUserCommand pSource, CommandExecutionEventArgs pEventArgs)
        {
            // Evaluating if the new command must be added in the context list.
            bool lAddCommand = true;

            if (this.CommandsList.Any() && this.LastExecutedCommand != null)
            {
                lAddCommand = this.LastExecutedCommand.TryMerge(pEventArgs.Command) == false;
            }

            // Adding the command in the list if wanted.
            if (lAddCommand)
            {
                this.CommandsList.Add(pEventArgs.Command);
                this.CurrentCommandIndex = this.CommandsList.Count - 1;
            }
        }
Пример #5
0
        /// <summary>
        /// Delegate called when a command is redone.
        /// </summary>
        /// <param name="pSource">The source command.</param>
        /// <param name="pEventArgs">The event arguments.</param>
        private void OnCommandRedone(IUserCommand pSource, CommandExecutionEventArgs pEventArgs)
        {
            // Unregistering form events.
            pEventArgs.Command.Doing  -= this.OnCommandDoing;
            pEventArgs.Command.Done   -= this.OnCommandRedone;
            pEventArgs.Command.Failed -= this.OnCommandFailed;

            // Custom process.
            this.CustomOnCommandRedone(pSource, pEventArgs);

            // Unlocking the command execution.
            this.mIsExecutingCommand = false;

            // Internal notification.
            if (this.CommandDone != null)
            {
                this.CommandDone(this, pEventArgs);
            }

            // Manager notification.
            this.mParentManager.NotifyCommandExecution(UserCommandManager.CommandExecutionType.Done, pEventArgs);
        }
Пример #6
0
 /// <summary>
 /// Delegate called when a command execution failed.
 /// </summary>
 /// <param name="pSource">The source command.</param>
 /// <param name="pEventArgs">The event arguments.</param>
 protected virtual void CustomOnCommandFailed(IUserCommand pSource, CommandExecutionEventArgs pEventArgs)
 {
     // Nothing to do.
 }
Пример #7
0
        /// <summary>
        /// Notifies a context changed.
        /// </summary>
        /// <param name="pType">The type of notification.</param>
        /// <param name="pEventArgs">The event arguments.</param>
        internal void NotifyCommandExecution(CommandExecutionType pType, CommandExecutionEventArgs pEventArgs)
        {
            switch (pType)
            {
            case CommandExecutionType.Doing:
            {
                if (this.mCommandDoingHandler != null)
                {
                    this.mCommandDoingHandler(this, pEventArgs);
                }

                if (this.CommandDoing != null)
                {
                    this.CommandDoing(this, pEventArgs);
                }
            }
            break;

            case CommandExecutionType.Done:
            {
                if (this.mCommandDoneHandler != null)
                {
                    this.mCommandDoneHandler(this, pEventArgs);
                }

                if (this.CommandDone != null)
                {
                    this.CommandDone(this, pEventArgs);
                }
            }
            break;

            case CommandExecutionType.Failed:
            {
                if (this.mCommandFailedHandler != null)
                {
                    this.mCommandFailedHandler(this, pEventArgs);
                }

                if (this.CommandFailed != null)
                {
                    this.CommandFailed(this, pEventArgs);
                }
            }
            break;

            case CommandExecutionType.Undoing:
            {
                if (this.mCommandUndoingHandler != null)
                {
                    this.mCommandUndoingHandler(this, pEventArgs);
                }

                if (this.CommandUndoing != null)
                {
                    this.CommandUndoing(this, pEventArgs);
                }
            }
            break;

            case CommandExecutionType.Undone:
            {
                if (this.mCommandUndoneHandler != null)
                {
                    this.mCommandUndoneHandler(this, pEventArgs);
                }

                if (this.CommandUndone != null)
                {
                    this.CommandUndone(this, pEventArgs);
                }
            }
            break;
            }
        }