Пример #1
0
            /// <summary>
            /// Removes a command instance.
            /// </summary>
            /// <param name="command">The command to remove.</param>
            public void Remove(Command command)
            {
                //	Ensure that the command instance has been added and is not active.
                Debug.Assert(commandInstanceCollection.Contains(command), String.Format(CultureInfo.InvariantCulture, "Command instance {0} not found.", command.Identifier));

                //	Remove the command instance.
                if (commandInstanceCollection.Contains(command))
                {
                    commandInstanceCollection.Remove(command);
                }
            }
        /// <summary>
        /// Removes a command from the CommandContextManager.
        /// </summary>
        /// <param name="command">The Command to remove.</param>
        /// <param name="commandContext">The context in which the command is added to the CommandManager.</param>
        public void RemoveCommand(Command command)
        {
            //	Ensure that the command is not null.
            Debug.Assert(command != null, "Command cannot be null");
            if (command == null)
            {
                return;
            }

            //	Ensure the the command has been added.
            if (!commandContextTable.Contains(command))
            {
                Debug.Fail("Command " + command.Identifier + " was not added.");
                return;
            }

            //	Handle the command, removing it from the appropriate command collection.
            switch ((CommandContext)commandContextTable[command])
            {
            //	Normal commands.
            case CommandContext.Normal:
                normalCommandCollection.Remove(command);
                commandManager.Remove(command);
                break;

            //	Activated commands.
            case CommandContext.Activated:
                activatedCommandCollection.Remove(command);
                if (activated)
                {
                    commandManager.Remove(command);
                }
                break;

            //	Entered commands.
            case CommandContext.Entered:
                enteredCommandCollection.Remove(command);
                if (entered)
                {
                    commandManager.Remove(command);
                }
                break;

            //	Can't happen.
            default:
                Debug.Fail("Unknown CommandContext");
                return;
            }

            //	Remove the command from the command context table.
            commandContextTable.Remove(command);
        }