Exemplo n.º 1
0
        public CommandLoader(CommandManager commandManager, params CommandId[] commandIds)
        {
            if (commandManager == null)
                throw new ArgumentNullException("commandManager");

            this._commandManager = commandManager;
            try
            {
                _commandManager.BeginUpdate();
                foreach (CommandId commandId in commandIds)
                {
                    Command command = new Command(commandId);
                    commandManager.Add(command);
                    _loadedCommands.Add(command);
                }
            }
            catch (Exception)
            {
                Dispose();
                throw;
            }
            finally
            {
                _commandManager.EndUpdate();
            }
        }
        public DraftPostItemsGalleryCommand(IBlogPostEditingSite postEditingSite, CommandManager commandManager, bool isPost)
            : base((isPost ? CommandId.OpenPostSplit : CommandId.OpenDraftSplit))
        {
            this.postEditingSite = postEditingSite;
            _isPost = isPost;
            if (isPost)
            {
                draftCmdStart = (int)CommandId.OpenPostMRU0;
            }
            lock (_commandsLock)
            {
                // initialize commands
                for (int i = 0; i < _commands.Length; i++)
                {
                    _commands[i] = new Command((CommandId)(i + draftCmdStart));
                    _commands[i].Execute += new EventHandler(DraftPostItemsGalleryCommand_Execute);
                    _commands[i].CommandBarButtonStyle = CommandBarButtonStyle.Provider;
                    _commands[i].On = false;
                }

                // add them to the command manager
                commandManager.Add(new CommandCollection(_commands));
                commandManager.Add(this);
            }
        }
 /// <summary>
 /// Gets an array of objects containing the specified collection.
 /// </summary>
 /// <param name="editValue">The collection to edit.</param>
 /// <returns>An array containing the collection objects.</returns>
 protected override object[] GetItems(object editValue)
 {
     CommandCollection commandCollection = (CommandCollection)editValue;
     Command[] commands = new Command[commandCollection.Count];
     if (commandCollection.Count > 0)
         commandCollection.CopyTo(commands, 0);
     return commands;
 }
Exemplo n.º 4
0
 public GroupCommand(CommandId commandId, Command representativeCommand) : base(commandId)
 {
     Debug.Assert(representativeCommand != null, "Unexpected null command");
     _representativeCommand = representativeCommand;
     UpdateInvalidationState(PropertyKeys.SmallImage, InvalidationState.Pending);
     UpdateInvalidationState(PropertyKeys.SmallHighContrastImage, InvalidationState.Pending);
     UpdateInvalidationState(PropertyKeys.LargeImage, InvalidationState.Pending);
     UpdateInvalidationState(PropertyKeys.LargeHighContrastImage, InvalidationState.Pending);
 }
        /// <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);
        }
        /// <summary>
        /// Adds a command to the CommandContextManager.
        /// </summary>
        /// <param name="command">The Command to add.</param>
        /// <param name="commandContext">The context in which the command is added to the CommandManager.</param>
        public void AddCommand(Command command, CommandContext commandContext)
        {
            //	Ensure that the command is not null.
            Debug.Assert(command != null, "Command cannot be null");
            if (command == null)
                return;

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

            //	Handle the command, adding it to the appropriate command collection.
            switch (commandContext)
            {
                //	Normal commands.
                case CommandContext.Normal:
                    normalCommandCollection.Add(command);
                    commandManager.Add(command);
                    break;

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

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

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

            //	Add the command to the command context table.
            commandContextTable[command] = commandContext;
        }
Exemplo n.º 7
0
 public ProxyCommand(CommandId commandId, Command command) : base(commandId)
 {
     _command = command;
 }
 /// <summary>
 /// Searches for the specified Command and returns the zero-based index of the first
 /// occurrence within the entire CommandCollection.
 /// </summary>
 /// <param name="value">The Command to locate in the CommandCollection.</param>
 /// <returns>The zero-based index of the first occurrence of value within the entire CommandCollection, if found; otherwise, -1.</returns>
 public int IndexOf(Command value)
 {
     return List.IndexOf(value);
 }
        private void InitializeCommands()
        {
            commandContextManager = new CommandContextManager(CommandManager);
            commandContextManager.BeginUpdate();

            for (int i = 0; i < ImageDecoratorGroups.Length; i++)
            {
                ImageDecoratorGroup imageDecoratorGroup = ImageDecoratorGroups[i];
                foreach (ImageDecorator imageDecorator in imageDecoratorGroup.ImageDecorators)
                {
                    Command ImageDecoratorApplyCommand = new Command(CommandId.ImageDecoratorApply);
                    ImageDecoratorApplyCommand.Identifier += imageDecorator.Id;
                    ImageDecoratorApplyCommand.Text = imageDecorator.DecoratorName;
                    ImageDecoratorApplyCommand.MenuText = imageDecorator.DecoratorName;
                    imageDecorator.SetCommand(ImageDecoratorApplyCommand);
                    commandContextManager.AddCommand(ImageDecoratorApplyCommand, CommandContext.Normal);

                    ImageDecoratorApplyCommand.Execute += new EventHandler(imageDecoratorCommand_Execute);
                    ImageDecoratorApplyCommand.Tag = imageDecorator.Id;
                }
            }

            commandContextManager.EndUpdate();
        }
 /// <summary>
 /// Determines whether the CommandCollection contains a specific element.
 /// </summary>
 /// <param name="value">The Command to locate in the CommandCollection.</param>
 /// <returns>true if the CommandCollection contains the specified value; otherwise, false.</returns>
 public bool Contains(Command value)
 {
     return List.Contains(value);
 }
 /// <summary>
 /// Adds the specified array of Command values to the end of the CommandCollection.
 /// </summary>
 /// <param name="value">The array of Command values to be added to the end of the CommandCollection.</param>
 public void AddRange(Command[] value)
 {
     foreach (Command command in value)
         Add(command);
 }
 /// <summary>
 /// Adds the specified command to the end of the command collection.
 /// </summary>
 /// <param name="value">The command to be added to the end of the command collection.</param>
 /// <returns>The index at which the command has been added.</returns>
 public int Add(Command value)
 {
     return List.Add(value);
 }
 /// <summary>
 /// Initializes a new instance of the CommandCollection class.
 /// </summary>
 /// <param name="value">Array of commands to initializes this command collection with.</param>
 public CommandCollection(Command[] value)
 {
     AddRange(value);
 }
 /// <summary>
 /// Removes the first occurrence of a specific Command from the CommandCollection.
 /// </summary>
 /// <param name="value">The Command to remove.</param>
 public void Remove(Command value)
 {
     List.Remove(value);
 }
 /// <summary>
 /// Inserts an element into the CommandCollection at the specified index.
 /// </summary>
 /// <param name="index">The zero-based index at which value should be inserted.</param>
 /// <param name="value">The Command to insert.</param>
 public void Insert(int index, Command value)
 {
     List.Insert(index, value);
 }
 public static void ApplyResources(Command command)
 {
     _resourcedPropertyLoader.ApplyResources(command, command.Identifier);
 }
 internal void SetCommand(Command command)
 {
     _command = command;
 }
 /// <summary>
 /// Copies the entire CommandCollection to a one-dimensional Array, starting at the
 /// specified index of the target array.
 /// </summary>
 /// <param name="array">The one-dimensional Array that is the destination of the elements copied from CommandCollection. The Array must have zero-based indexing.</param>
 /// <param name="index">The zero-based index in array at which copying begins.</param>
 public void CopyTo(Command[] array, int index)
 {
     List.CopyTo(array, index);
 }