示例#1
0
 public static IEnumerable <MenuBase> ExpandMenuGroups(IEnumerable <MenuBase> items, MenuUtilities.MenuBaseExpander groupExpander)
 {
     if (items == null)
     {
         throw new ArgumentNullException("items");
     }
     if (groupExpander == null)
     {
         throw new ArgumentNullException("groupExpander");
     }
     foreach (MenuBase menuBase1 in items)
     {
         MenuGroup group = menuBase1 as MenuGroup;
         if (group != null)
         {
             foreach (MenuBase menuBase2 in MenuUtilities.ExpandMenuGroups(groupExpander(group), groupExpander))
             {
                 yield return(menuBase2);
             }
         }
         else
         {
             yield return(menuBase1);
         }
     }
 }
示例#2
0
        public static IEnumerable <MenuBase> MergeMenuGroups(MenuUtilities.MenuBaseEnumerator rootItemEnumerator)
        {
            List <MenuBase> list = new List <MenuBase>();
            Dictionary <string, MenuGroup> dictionary = new Dictionary <string, MenuGroup>();

            foreach (MenuBase menuBase in rootItemEnumerator())
            {
                MenuGroup groupToMergeIn = menuBase as MenuGroup;
                if (groupToMergeIn != null)
                {
                    string key = groupToMergeIn.Name + groupToMergeIn.HasDropDown.ToString();
                    if (dictionary.ContainsKey(key))
                    {
                        MenuGroup existingGroup = dictionary[key];
                        int       index         = list.IndexOf((MenuBase)existingGroup);
                        if (index >= 0)
                        {
                            list.RemoveAt(index);
                        }
                        if (index < list.Count)
                        {
                            list.Insert(index, (MenuBase)MenuUtilities.MergeGroups(existingGroup, groupToMergeIn));
                        }
                        else
                        {
                            list.Add((MenuBase)MenuUtilities.MergeGroups(existingGroup, groupToMergeIn));
                        }
                    }
                    else
                    {
                        dictionary.Add(key, groupToMergeIn);
                        list.Add((MenuBase)groupToMergeIn);
                    }
                }
                else
                {
                    list.Add(menuBase);
                }
            }
            return((IEnumerable <MenuBase>)list);
        }
示例#3
0
        private static MenuGroup MergeGroups(MenuGroup existingGroup, MenuGroup groupToMergeIn)
        {
            MenuGroup menuGroup1 = new MenuGroup(existingGroup.Name, existingGroup.DisplayName);

            menuGroup1.HasDropDown = existingGroup.HasDropDown;
            Dictionary <string, MenuGroup> dictionary = new Dictionary <string, MenuGroup>();

            foreach (MenuBase menuBase in (Collection <MenuBase>)existingGroup.Items)
            {
                MenuGroup menuGroup2 = menuBase as MenuGroup;
                if (menuGroup2 != null)
                {
                    string key = menuGroup2.Name + menuGroup2.HasDropDown.ToString();
                    dictionary.Add(key, menuGroup2);
                }
                menuGroup1.Items.Add(menuBase);
            }
            foreach (MenuBase menuBase in (Collection <MenuBase>)groupToMergeIn.Items)
            {
                MenuGroup groupToMergeIn1 = menuBase as MenuGroup;
                if (groupToMergeIn1 != null)
                {
                    string key = groupToMergeIn1.Name + groupToMergeIn1.HasDropDown.ToString();
                    if (dictionary.ContainsKey(key))
                    {
                        menuGroup1.Items.Remove((MenuBase)dictionary[key]);
                        menuGroup1.Items.Add((MenuBase)MenuUtilities.MergeGroups(dictionary[key], groupToMergeIn1));
                    }
                    else
                    {
                        menuGroup1.Items.Add(menuBase);
                    }
                }
                else
                {
                    menuGroup1.Items.Add(menuBase);
                }
            }
            return(menuGroup1);
        }