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);
            }
        }
        public MarginCommand(CommandManager commandManager)
            : base(CommandId.MarginsGroup)
        {
            RepresentativeString = Res.Get(StringId.SpinnerPixelRepresentativeString);
            FormatString = Res.Get(StringId.SpinnerPixelFormatString);

            // @RIBBON TODO: Have a way to initialize this.
            marginValue = new Padding(Convert.ToInt32(MinMargin));

            commandManager.BeginUpdate();

            commandLeftMargin = new SpinnerCommand(CommandId.AdjustLeftMargin, MinMargin, MaxMargin, MinMargin, Increment, DecimalPlaces, RepresentativeString, FormatString);
            commandManager.Add(commandLeftMargin, commandMargin_ExecuteWithArgs);

            commandTopMargin = new SpinnerCommand(CommandId.AdjustTopMargin, MinMargin, MaxMargin, MinMargin, Increment, DecimalPlaces, RepresentativeString, FormatString);
            commandManager.Add(commandTopMargin, commandMargin_ExecuteWithArgs);

            commandRightMargin = new SpinnerCommand(CommandId.AdjustRightMargin, MinMargin, MaxMargin, MinMargin, Increment, DecimalPlaces, RepresentativeString, FormatString);
            commandManager.Add(commandRightMargin, commandMargin_ExecuteWithArgs);

            commandBottomMargin = new SpinnerCommand(CommandId.AdjustBottomMargin, MinMargin, MaxMargin, MinMargin, Increment, DecimalPlaces, RepresentativeString, FormatString);
            commandManager.Add(commandBottomMargin, commandMargin_ExecuteWithArgs);

            commandManager.EndUpdate();
        }
        /// <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;
        }
        /// <summary>
        /// Show the menu (modally) and return the type of the command that was chosen
        /// </summary>
        /// <param name="commandTypes">command types to include in the menu</param>
        /// <param name="point">point to show the menu at</param>
        /// <param name="parentControl">parent control for menu</param>
        /// <param name="menuTextParams">substitution parameters for the menu text</param>
        /// <returns>Type of the command that was chosen (null if no command chosen)</returns>
        public static Type ShowModal(CommandManager commandManager, Control parentWindow, Point position, Type[] commandTypes)
        {
            //	Dynamically construct the collection of commands to be shown.
            CommandCollection commandCollection = new CommandCollection();

            foreach (Type commandType in commandTypes)
            {
                // verify that the type is correct
                if (!typeof(Command).IsAssignableFrom(commandType))
                {
                    throw new ArgumentException(
                              "Type passed is not a subclass of Command!");
                }

                // create an instance of the command and add it to the collection of commands to be shown.
                Command command = Activator.CreateInstance(commandType) as Command;
                commandCollection.Add(command);
            }

            //	Add the commands to the system command manager.
            commandManager.Add(commandCollection);

            //	Show the context menu modally.
            Command commandSelected = ShowModal(parentWindow, position, commandCollection, false);
            Type    type            = commandSelected == null ? null : commandSelected.GetType();

            commandSelected = null;

            //	Remove the commands from the system command manager.
            commandManager.Remove(commandCollection);

            //	Done!
            return(type);
        }
        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 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 SizeCommand(CommandManager commandManager, CommandId widthId, CommandId heightId, int width, int height)
            {
                _widthId = widthId;
                _heightId = heightId;

                sizeValue = new Size(width, height);

                commandManager.BeginUpdate();

                commandManager.Add(
                    new SpinnerCommand(_widthId, MinSize.Width, MaxSize.Width, width, Increment, DecimalPlaces, RepresentativeString, FormatString),
                    command_ExecuteWithArgs);

                commandManager.Add(
                    new SpinnerCommand(_heightId, MinSize.Height, MaxSize.Height, height, Increment, DecimalPlaces, RepresentativeString, FormatString),
                    command_ExecuteWithArgs);

                commandManager.EndUpdate();
            }
        public HyperlinkForm(CommandManager commandManager, bool showAllOptions)
        {
            _slimOptions = !showAllOptions;
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            CommandManager = commandManager;
            buttonInsert.Text = Res.Get(StringId.InsertButtonText);
            buttonCancel.Text = Res.Get(StringId.CancelButton);
            label1.Text = Res.Get(StringId.UrlLabel);
            labelLinkText.Text = Res.Get(StringId.LinkTextLabel);
            labelTitle.Text = Res.Get(StringId.LinkTitleLabel);
            labelRel.Text = Res.Get(StringId.LinkRelLabel);
            ckboxNewWindow.Text = Res.Get(StringId.LinkNewWindowLabel);
            btnOptions.Text = " " + Res.Get(StringId.LinkLinkTo);
            btnOptions.AccessibleName = ControlHelper.ToAccessibleName(Res.Get(StringId.LinkLinkTo));
            btnOptionsToolTip.SetToolTip(this.btnOptions, Res.Get(StringId.LinkOptionsTooltip));
            btnRemove.Text = Res.Get(StringId.LinkRemoveLink);
            ckBoxGlossary.Text = Res.Get(StringId.LinkAddToGlossary);
            this.Text = Res.Get(StringId.LinkFormTitle);

            CommandManager.BeginUpdate();

            CommandManager.Add(new CommandGlossary());

            CommandManager.EndUpdate();

            textBoxAddress.GotFocus += new EventHandler(textBoxAddress_GotFocus);
            textBoxAddress.RightToLeft = System.Windows.Forms.RightToLeft.No;
            if (BidiHelper.IsRightToLeft)
                textBoxAddress.TextAlign = HorizontalAlignment.Right;
        }
        public PostPropertiesBandControl(CommandManager commandManager)
        {
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.DoubleBuffer, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.ResizeRedraw, true);

            InitializeComponent();

            categoryContext = new CategoryContext();

            controller = new SharedPropertiesController(this, null, categoryDropDown,
                null, textTags, labelPageOrder, textPageOrder, labelPageParent, comboPageParent, null,
                datePublishDate, fields, categoryContext);

            SimpleTextEditorCommandHelper.UseNativeBehaviors(commandManager,
                textTags, textPageOrder);

            postPropertiesForm = new PostPropertiesForm(commandManager, categoryContext);
            if (components == null)
                components = new Container();
            components.Add(postPropertiesForm);

            postPropertiesForm.Synchronize(controller);

            commandManager.Add(CommandId.PostProperties, PostProperties_Execute);
            commandManager.Add(CommandId.ShowCategoryPopup, ShowCategoryPopup_Execute);

            linkViewAll.KeyDown += (sender, args) =>
                                   {
                                       if (args.KeyValue == ' ')
                                           linkViewAll_LinkClicked(sender, new LinkLabelLinkClickedEventArgs(null));
                                   };

            // WinLive 180287: We don't want to show or use mnemonics on labels in the post properties band because
            // they can steal focus from the canvas.
            linkViewAll.Text = TextHelper.StripAmpersands(Res.Get(StringId.ViewAll));
            linkViewAll.UseMnemonic = false;
            labelPageParent.Text = TextHelper.StripAmpersands(Res.Get(StringId.PropertiesPageParent));
            labelPageParent.UseMnemonic = false;
            labelPageOrder.Text = TextHelper.StripAmpersands(Res.Get(StringId.PropertiesPageOrder));
            labelPageOrder.UseMnemonic = false;
        }
        /// <summary>
        /// Show the menu (modally) and return the type of the command that was chosen
        /// </summary>
        /// <param name="commandTypes">command types to include in the menu</param>
        /// <param name="point">point to show the menu at</param>
        /// <param name="parentControl">parent control for menu</param>
        /// <param name="menuTextParams">substitution parameters for the menu text</param>
        /// <returns>Type of the command that was chosen (null if no command chosen)</returns>
        public static Type ShowModal(CommandManager commandManager, Control parentWindow, Point position, Type[] commandTypes)
        {
            //	Dynamically construct the collection of commands to be shown.
            CommandCollection commandCollection = new CommandCollection();
            foreach (Type commandType in commandTypes)
            {
                // verify that the type is correct
                if (!typeof(Command).IsAssignableFrom(commandType))
                    throw new ArgumentException(
                        "Type passed is not a subclass of Command!");

                // create an instance of the command and add it to the collection of commands to be shown.
                Command command = Activator.CreateInstance(commandType) as Command;
                commandCollection.Add(command);
            }

            //	Add the commands to the system command manager.
            commandManager.Add(commandCollection);

            //	Show the context menu modally.
            Command commandSelected = ShowModal(parentWindow, position, commandCollection, false);
            Type type = commandSelected == null ? null : commandSelected.GetType();
            commandSelected = null;

            //	Remove the commands from the system command manager.
            commandManager.Remove(commandCollection);

            //	Done!
            return type;
        }