Exemplo n.º 1
0
        /// <summary>
        /// Creates the tool strip item for specified action.
        /// </summary>
        /// <param name="visualToolAction">The visual tool action.</param>
        /// <param name="createToolStripButton">A value indicating whether the tool strip button must be created.</param>
        /// <returns>
        /// The tool strip item
        /// </returns>
        private ToolStripItem CreateToolStripItem(
            VisualToolAction visualToolAction,
            bool createToolStripButton)
        {
            // if tool strip separator must be created
            if (visualToolAction is SeparatorToolStripAction)
            {
                return(new ToolStripSeparator());
            }

            ToolStripItem toolStripItem;

            // if tool strip button must be created
            if (createToolStripButton)
            {
                // if action has subactions
                if (visualToolAction.HasSubactions)
                {
                    // create tool strip split button
                    toolStripItem = new CheckedToolStripSplitButton();
                }
                else
                {
                    // create tool strip button
                    toolStripItem = new ToolStripButton();
                }
            }
            else
            {
                // create tool strip menu item
                toolStripItem = new ToolStripMenuItem();
            }

            // set tool strip item text
            toolStripItem.Text = visualToolAction.Text;
            // set tool strip item tooltip
            toolStripItem.ToolTipText = visualToolAction.ToolTip;

            // if tool strip items is button
            if (createToolStripButton)
            {
                toolStripItem.DisplayStyle = ToolStripItemDisplayStyle.Image;
            }
            else
            {
                toolStripItem.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
            }

            // set tool strip item icon
            toolStripItem.Image        = visualToolAction.Icon;
            toolStripItem.ImageScaling = ToolStripItemImageScaling.None;

            return(toolStripItem);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Updates the check state the specified tool strip item of action.
        /// </summary>
        /// <param name="visualToolAction">The visual tool action.</param>
        /// <param name="toolStripItem">The tool strip item.</param>
        private void UpdateToolStripItemCheckState(VisualToolAction visualToolAction, ToolStripItem toolStripItem)
        {
            // get tool strip button
            ToolStripButton button = toolStripItem as ToolStripButton;

            // if tool strip item is tool strip button
            if (button != null)
            {
                // update check state
                button.Checked = visualToolAction.IsActivated;
            }
            else
            {
                // get tool strip split button
                CheckedToolStripSplitButton splitButton = toolStripItem as CheckedToolStripSplitButton;

                // if tool strip item is tool strip split button
                if (splitButton != null)
                {
                    // update check state
                    splitButton.Checked = visualToolAction.IsActivated;
                }
                else
                {
                    // get tool strip menu item
                    ToolStripMenuItem menuItem = toolStripItem as ToolStripMenuItem;

                    // if tool strip item is tool strip menu item
                    if (menuItem != null)
                    {
                        // update check state
                        menuItem.Checked = visualToolAction.IsActivated;
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds the specified visual tool action to the specified collection.
        /// </summary>
        /// <param name="toolStripItemCollection">The item collection of toolstrip.</param>
        /// <param name="visualToolAction">The visual tool action.</param>
        /// <param name="visualToolActionsDictionary">A dictionary, which contains links between visual tool actions and buttons.</param>
        private void AddVisualToolActionToToolstrip(
            ToolStripItemCollection toolStripItemCollection,
            VisualToolAction visualToolAction,
            VisualToolActionButtonsDictionary visualToolActionsDictionary)
        {
            ToolStripItem toolStripItem;

            // if new toolstrip item must be added to the collection of this toolstrip
            if (toolStripItemCollection == Items)
            {
                // create the toolstip item for visual tool action
                toolStripItem = CreateToolStripItem(visualToolAction, true);
            }
            // if new toolstrip item must be added to the collection of other toolstrip
            else
            {
                // create the toolstip item for visual tool action
                toolStripItem = CreateToolStripItem(visualToolAction, false);
            }

            // if action is not separator
            if (!(visualToolAction is SeparatorToolStripAction))
            {
                // save information about link between action and toolstrip item
                visualToolActionsDictionary.Add(visualToolAction, toolStripItem);

                // update action check state
                UpdateActionCheckState(visualToolAction);

                // if toolstrip item is split button
                if (toolStripItem is CheckedToolStripSplitButton)
                {
                    CheckedToolStripSplitButton button = (CheckedToolStripSplitButton)toolStripItem;
                    // subscribe to the button click event
                    button.ButtonClick += new EventHandler(ActionItem_Click);
                }
                else
                {
                    // subscribe to the item click event
                    toolStripItem.Click += new EventHandler(ActionItem_Click);
                }

                // if visual tool action contains sub-actions
                if (visualToolAction.HasSubactions)
                {
                    ToolStripItemCollection subActions = null;

                    if (toolStripItem is CheckedToolStripSplitButton)
                    {
                        CheckedToolStripSplitButton checkedToolStripSplitButton = (CheckedToolStripSplitButton)toolStripItem;
                        checkedToolStripSplitButton.DropDownOpened += Button_DropDownOpened;
                        subActions = checkedToolStripSplitButton.DropDownItems;
                    }
                    else if (toolStripItem is ToolStripMenuItem)
                    {
                        ToolStripMenuItem toolStripMenuItem = (ToolStripMenuItem)toolStripItem;
                        toolStripMenuItem.DropDownOpened += Button_DropDownOpened;
                        subActions = toolStripMenuItem.DropDownItems;
                    }

                    // for each sub-action
                    foreach (VisualToolAction subAction in visualToolAction.SubActions)
                    {
                        AddVisualToolActionToToolstrip(subActions, subAction, visualToolActionsDictionary);
                    }
                }
            }

            // add the toolstrip item to the toolstrip
            toolStripItemCollection.Add(toolStripItem);
        }