Ejemplo n.º 1
0
        private void UpdateToolbarItems()
        {
            foreach (DockedToolStrip toolStrip in _dockedToolStrips.Values)
            {
                /*
                 * Go through each button in the toolbars and add a
                 * separator after every item with the 'IncludeSeparator'
                 * flag set.
                 */

                for (int i = 0; i < toolStrip.ToolStrip.Items.Count; i++)
                {
                    ToolStripItem item = toolStrip.ToolStrip.Items[i];

                    ToolStripItemTag tag = item.Tag as ToolStripItemTag;
                    if (tag != null && tag.IncludeSeparator)
                    {
                        ToolStripSeparator sep =
                            MenuTools.CreateSeparator(item.Name + "_SEP");

                        /*
                         * Toolbar separator occurs before the button.
                         */

                        int j = toolStrip.ToolStrip.Items.IndexOf(item);
                        if (j != -1)
                        {
                            toolStrip.ToolStrip.Items.Insert(j, sep);
                            i++;  // increment i to skip button
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void UpdateMenuDropDownItems(ToolStripMenuItem menu)
        {
            for (int i = 0; i < menu.DropDownItems.Count; i++)
            {
                ToolStripItem item = menu.DropDownItems[i];

                ToolStripItemTag tag = item.Tag as ToolStripItemTag;
                if (tag != null && tag.IncludeSeparator)
                {
                    ToolStripSeparator sep =
                        MenuTools.CreateSeparator(item.Name + "_SEP");

                    int j = menu.DropDownItems.IndexOf(item);

                    /*
                     * Menu separator occurs after the menu.
                     */

                    if (j != -1)
                    {
                        menu.DropDownItems.Insert(j + 1, sep);
                        i++; // increment i to skip new item
                    }
                }

                /*
                 * If the item is a menu recurse into any submenus.
                 */

                if (item is ToolStripMenuItem)
                {
                    ToolStripMenuItem menuItem = item as ToolStripMenuItem;

                    if (menuItem.DropDownItems.Count > 0)
                    {
                        UpdateMenuDropDownItems(menuItem);
                    }
                }
            }

            /*
             * The rule is that evey menu item group should end on a
             * separator. In some cases this will mean the last item
             * is a separator so we go through each menu and remove them.
             */

            int count = menu.DropDownItems.Count;

            if (count > 0)
            {
                ToolStripItem lastItem = menu.DropDownItems[count - 1];
                if (lastItem is ToolStripSeparator)
                {
                    menu.DropDownItems.RemoveAt(count - 1);
                }
            }
        }