/// <summary>
        /// Helper to make a separator menu item.
        /// </summary>
        /// <returns>A MenuItem that is a separator MenuItem.</returns>
        private static MenuItem MakeSeparatorMenuItem(MenuType menuType)
        {
            //	Instantiate the separator menu item.
            MenuItem separatorMenuItem = new OwnerDrawMenuItem(menuType, SEPARATOR_CHAR.ToString());

            return(separatorMenuItem);
        }
Beispiel #2
0
        /// <summary>
        /// Helper to make a separator menu item.
        /// </summary>
        /// <returns>A MenuItem that is a separator MenuItem.</returns>
        private MenuItem MakeSeparatorMenuItem(MenuType menuType)
        {
            //	Instantiate the separator menu item.
            MenuItem separatorMenuItem = new OwnerDrawMenuItem(menuType, "-");

            return(separatorMenuItem);
        }
        /// <summary>
        /// Gets the MenuItem for this MenuDefinitionEntry.
        /// </summary>
        /// <param name="commandManager">The CommandManager to use.</param>
        /// <param name="menuType">The MenuType.</param>
        /// <returns>The menu item for this MenuDefinitionEntry.</returns>
        protected override MenuItem GetMenuItem(CommandManager commandManager, MenuType menuType)
        {
            //	Instantiate the placeholder OwnerDrawMenuItem.
            OwnerDrawMenuItem ownerDrawMenuItem = new OwnerDrawMenuItem(menuType, menuPath);

            //	Build child MenuItems.
            MenuItem[] menuItems = MenuBuilder.CreateMenuItems(commandManager, menuType, Entries);
            if (menuItems != null)
            {
                ownerDrawMenuItem.MenuItems.AddRange(menuItems);
            }

            //	Done.
            return(ownerDrawMenuItem);
        }
        /// <summary>
        /// Gets the MenuItem for this MenuDefinitionEntry.
        /// </summary>
        /// <param name="commandManager">The CommandManager to use.</param>
        /// <param name="menuType">The MenuType.</param>
        /// <returns>The menu item for this MenuDefinitionEntry.</returns>
        protected override MenuItem GetMenuItem(CommandManager commandManager, MenuType menuType)
        {
            //	Instantiate the placeholder OwnerDrawMenuItem.
            OwnerDrawMenuItem ownerDrawMenuItem = new OwnerDrawMenuItem(menuType, menuPath);

            //	Build child MenuItems.
            MenuItem[] menuItems = MenuBuilder.CreateMenuItems(commandManager, menuType, Entries);
            if (menuItems != null)
                ownerDrawMenuItem.MenuItems.AddRange(menuItems);

            //	Done.
            return ownerDrawMenuItem;
        }
        /// <summary>
        /// Creates and returns a set of menu items from the child merge menu entries in this merge
        /// menu entry.
        /// </summary>
        /// <param name="mainMenu">The level at which the MenuItems will appear.</param>
        /// <returns>Array of menu items.</returns>
        public MenuItem[] CreateMenuItems()
        {
            //	If this merge menu entry has no child merge menu entries, return null.
            if (childMergeMenuEntries.Count == 0)
            {
                return(null);
            }

            //	Construct an array list to hold the menu items being created.
            ArrayList menuItemArrayList = new ArrayList();

            //	Enumerate the child merge menu entries of this merge menu entry.
            foreach (CommandMenuBuilderEntry mergeMenuEntry in childMergeMenuEntries.Values)
            {
                //	Get the text of the merge menu entry.
                string text = mergeMenuEntry.Text;

                //	Create the menu item for this child merge menu entry.
                MenuItem menuItem;
                bool     separatorBefore, separatorAfter;
                if (commandMenuBuilder.MenuType == MenuType.Main && mergeMenuEntry.level == 0)
                {
                    //	Level zero of a main menu.
                    menuItem        = new OwnerDrawMenuItem(commandMenuBuilder.MenuType, text);
                    separatorBefore = separatorAfter = false;
                }
                else
                {
                    //	Determine whether a separator before and a separator after the menu item
                    //	should be inserted.
                    separatorBefore = text.StartsWith(SEPARATOR_CHAR.ToString());
                    separatorAfter  = text.EndsWith(SEPARATOR_CHAR.ToString());
                    if (separatorBefore || separatorAfter)
                    {
                        text = text.Trim(SEPARATOR_CHAR);
                    }

                    //	Instantiate the menu item.
                    if (mergeMenuEntry.Command == null)
                    {
                        menuItem = new OwnerDrawMenuItem(commandMenuBuilder.MenuType, text);
                    }
                    else
                    {
                        menuItem = new CommandOwnerDrawMenuItem(commandMenuBuilder.MenuType, mergeMenuEntry.Command, text);
                    }
                }

                //	Set the menu item text.
                // menuItem.Text = text;

                //	If this child merge menu entry has any child merge menu entries, recursively
                //	create their menu items.
                MenuItem[] childMenuItems = mergeMenuEntry.CreateMenuItems();
                if (childMenuItems != null)
                {
                    menuItem.MenuItems.AddRange(childMenuItems);
                }

                //	Add the separator menu item, as needed.
                if (separatorBefore)
                {
                    menuItemArrayList.Add(MakeSeparatorMenuItem(commandMenuBuilder.MenuType));
                }

                //	Add the menu item to the array of menu items being returned.
                menuItemArrayList.Add(menuItem);

                //	Add the separator menu item, as needed.
                if (separatorAfter)
                {
                    menuItemArrayList.Add(MakeSeparatorMenuItem(commandMenuBuilder.MenuType));
                }
            }

            // remove leading, trailing, and adjacent separators
            for (int i = menuItemArrayList.Count - 1; i >= 0; i--)
            {
                if (((MenuItem)menuItemArrayList[i]).Text == "-")
                {
                    if (i == 0 ||                                         // leading
                        i == menuItemArrayList.Count - 1 ||               // trailing
                        ((MenuItem)menuItemArrayList[i - 1]).Text == "-") // adjacent
                    {
                        menuItemArrayList.RemoveAt(i);
                    }
                }
            }

            //	Done.  Convert the array list into a MenuItem array and return it.
            return((MenuItem[])menuItemArrayList.ToArray(typeof(MenuItem)));
        }
 /// <summary>
 /// Helper to make a separator menu item.
 /// </summary>
 /// <returns>A MenuItem that is a separator MenuItem.</returns>
 private MenuItem MakeSeparatorMenuItem(MenuType menuType)
 {
     //	Instantiate the separator menu item.
     MenuItem separatorMenuItem = new OwnerDrawMenuItem(menuType, "-");
     return separatorMenuItem;
 }
 /// <summary>
 /// Helper to make a separator menu item.
 /// </summary>
 /// <returns>A MenuItem that is a separator MenuItem.</returns>
 private static MenuItem MakeSeparatorMenuItem(MenuType menuType)
 {
     //	Instantiate the separator menu item.
     MenuItem separatorMenuItem = new OwnerDrawMenuItem(menuType, SEPARATOR_CHAR.ToString());
     return separatorMenuItem;
 }
        /// <summary>
        /// Creates and returns a set of menu items from the child merge menu entries in this merge
        /// menu entry.
        /// </summary>
        /// <param name="mainMenu">The level at which the MenuItems will appear.</param>
        /// <returns>Array of menu items.</returns>
        public MenuItem[] CreateMenuItems()
        {
            //	If this merge menu entry has no child merge menu entries, return null.
            if (childMergeMenuEntries.Count == 0)
                return null;

            //	Construct an array list to hold the menu items being created.
            ArrayList menuItemArrayList = new ArrayList();

            //	Enumerate the child merge menu entries of this merge menu entry.
            foreach (CommandMenuBuilderEntry mergeMenuEntry in childMergeMenuEntries.Values)
            {
                //	Get the text of the merge menu entry.
                string text = mergeMenuEntry.Text;

                //	Create the menu item for this child merge menu entry.
                MenuItem menuItem;
                bool separatorBefore, separatorAfter;
                if (commandMenuBuilder.MenuType == MenuType.Main && mergeMenuEntry.level == 0)
                {
                    //	Level zero of a main menu.
                    menuItem = new OwnerDrawMenuItem(commandMenuBuilder.MenuType, text);
                    separatorBefore = separatorAfter = false;
                }
                else
                {
                    //	Determine whether a separator before and a separator after the menu item
                    //	should be inserted.
                    separatorBefore = text.StartsWith(SEPARATOR_CHAR.ToString());
                    separatorAfter = text.EndsWith(SEPARATOR_CHAR.ToString());
                    if (separatorBefore || separatorAfter)
                        text = text.Trim(SEPARATOR_CHAR);

                    //	Instantiate the menu item.
                    if (mergeMenuEntry.Command == null)
                        menuItem = new OwnerDrawMenuItem(commandMenuBuilder.MenuType, text);
                    else
                        menuItem = new CommandOwnerDrawMenuItem(commandMenuBuilder.MenuType, mergeMenuEntry.Command, text);
                }

                //	Set the menu item text.
                // menuItem.Text = text;

                //	If this child merge menu entry has any child merge menu entries, recursively
                //	create their menu items.
                MenuItem[] childMenuItems = mergeMenuEntry.CreateMenuItems();
                if (childMenuItems != null)
                    menuItem.MenuItems.AddRange(childMenuItems);

                //	Add the separator menu item, as needed.
                if (separatorBefore)
                    menuItemArrayList.Add(MakeSeparatorMenuItem(commandMenuBuilder.MenuType));

                //	Add the menu item to the array of menu items being returned.
                menuItemArrayList.Add(menuItem);

                //	Add the separator menu item, as needed.
                if (separatorAfter)
                    menuItemArrayList.Add(MakeSeparatorMenuItem(commandMenuBuilder.MenuType));
            }

            // remove leading, trailing, and adjacent separators
            for (int i = menuItemArrayList.Count - 1; i >= 0; i--)
            {
                if (((MenuItem)menuItemArrayList[i]).Text == "-")
                {
                    if (i == 0 ||  // leading
                        i == menuItemArrayList.Count - 1 ||  // trailing
                        ((MenuItem)menuItemArrayList[i - 1]).Text == "-")  // adjacent
                    {
                        menuItemArrayList.RemoveAt(i);
                    }
                }
            }

            //	Done.  Convert the array list into a MenuItem array and return it.
            return (MenuItem[])menuItemArrayList.ToArray(typeof(MenuItem));
        }