/// <summary> /// Create a new MenuFilter based on an other. /// </summary> /// <param name="InputMenu">The MenuFilter to create content in.</param> /// <param name="CopyMenu">The MenuFilter used to copy content.</param> /// <param name="ParentKey">The parent key used to merge with a new MenuFilter.</param> private static void CopyMenuFilter(ref MenuFilter InputMenu, MenuFilter CopyMenu, string ParentKey = "") { ToolStripMenuItem tsiItems = new ToolStripMenuItem(); MenuFilter ActiveMenu; MenuFilter NewMenu; for (int i = 0; i < CopyMenu.ListMenu.Count; i++) { ActiveMenu = CopyMenu.ListMenu.ElementAt(i).Value; NewMenu = new MenuFilter(); if (ActiveMenu.ListItem != null) { InputMenu.ListMenu.Add(ParentKey + CopyMenu.ListMenu.ElementAt(i).Key, NewMenu);//Filter name + Item Name. } //Asign the new MenuFilter content. CopyMenuFilter(ref NewMenu, ActiveMenu, ParentKey + " " + CopyMenu.ListMenu.ElementAt(i).Key); } if (CopyMenu.ListItem != null) { InputMenu.ListItem = new Dictionary <string, string>(); foreach (KeyValuePair <string, string> Item in CopyMenu.ListItem) { InputMenu.ListItem.Add(Item.Key, Item.Value); } } }
private static void CreateListMenuRoot(ref MenuFilter cmsRoot, ref MenuFilter RootMenu, bool IsSubFilter, string MenuKey) { MenuFilter ActiveMenu; MenuFilter NewMenu; //Add the sub menus. for (int i = 0; i < RootMenu.ListMenu.Count; i++) { ActiveMenu = RootMenu.ListMenu.ElementAt(i).Value; //If there is multiple sub MenuFilter. if (RootMenu.MenuCount > 1) { if (ActiveMenu.ListItem != null) { NewMenu = new MenuFilter(); cmsRoot.ListMenu.Add(RootMenu.ListMenu.ElementAt(i).Key + " ", NewMenu);//Filter name + Item Name. //Asign the new MenuFilter content. CopyMenuFilter(ref NewMenu, ActiveMenu, RootMenu.ListMenu.ElementAt(i).Key + " "); } else { CreateListMenuRoot(ref cmsRoot, ref ActiveMenu, true, RootMenu.ListMenu.ElementAt(i).Key); } } else { if (ActiveMenu.ListItem != null && IsSubFilter) { NewMenu = new MenuFilter(); cmsRoot.ListMenu.Add(MenuKey + " " + RootMenu.ListMenu.ElementAt(i).Key, NewMenu);//Filter name + Item Name. //Asign the new MenuFilter content. CopyMenuFilter(ref NewMenu, ActiveMenu, RootMenu.ListMenu.ElementAt(i).Key + " "); } else { CreateListMenuRoot(ref cmsRoot, ref ActiveMenu, false, null); } } } //Add the items. if (RootMenu.ListItem != null) { foreach (KeyValuePair <string, string> Item in RootMenu.ListItem) { cmsRoot.ListItem.Add(Item.Key, Item.Value); } } }
private static void UpdatePath(ref MenuFilter Item) { MenuFilter ItemRef; for (int i = 0; i < Item.ListMenu.Count; i++) { ItemRef = Item.ListMenu.ElementAt(i).Value; UpdatePath(ref ItemRef); if (ItemRef.MenuCount > 0)//If the sub-Menuthing have items, increment the ItemCount. { Item.MenuCount++; } } }
private static string GetItemPathInRoot(MenuFilter OutMenu, string ItemPath) { if (OutMenu.ListItem != null && OutMenu.ListItem.ContainsKey(ItemPath)) { return(OutMenu.ListItem[ItemPath]); } foreach (MenuFilter Menu in OutMenu.ListMenu.Values) { string Output = GetItemPathInRoot(Menu, ItemPath); if (Output != null) { return(Output); } } return(null); }
public void AddMenu(MenuFilter Items, ListViewGroup ActiveNode = null) { ListViewGroup NewGroup; if (Items.ListItem != null) { foreach (KeyValuePair <string, string> Item in Items.ListItem) { ListViewItem NewItem = new ListViewItem(Item.Key); NewItem.Group = ActiveNode; NewItem.Tag = Item.Value; lvItems.Items.Add(NewItem); } } for (int M = 0; M < Items.ListMenu.Count; M++) { NewGroup = new ListViewGroup(Items.ListMenu.ElementAt(M).Key); lvItems.Groups.Add(NewGroup); AddMenu(Items.ListMenu.ElementAt(M).Value, NewGroup); } }
private static void GetMenuItemsFromRoot(string RootPath, out MenuFilter OutMenu) { IEnumerable <ItemContainer> Items = GetItemsByRoot(RootPath); if (Items == null) { OutMenu = null; return; } MenuFilter RootMenu = new MenuFilter(); MenuFilter ActiveMenuThing = RootMenu; OutMenu = new MenuFilter(); OutMenu.ListItem = new Dictionary <string, string>(); string[] SubString; //Create the List of paths to use. foreach (ItemContainer ActiveItem in Items) { ActiveMenuThing = RootMenu; SubString = ActiveItem.ContainerGUIPath.Split('\\'); for (int s = 0; s < SubString.Count(); s++) { if (!ActiveMenuThing.ListMenu.ContainsKey(SubString[s])) { ActiveMenuThing.ListMenu.Add(SubString[s], new MenuFilter()); } ActiveMenuThing = ActiveMenuThing.ListMenu[SubString[s]]; } ActiveMenuThing.ListItem = ActiveItem.ListItem;//Assign the ListItem to last part of the path list. ActiveMenuThing.MenuCount = 1; } //Count sub MenuFilters UpdatePath(ref RootMenu); CreateListMenuRoot(ref OutMenu, ref RootMenu, false, null); }
public ItemSelector(MenuFilter Items, bool MutipleSelection = true) : this() { AddMenu(Items); lvItems.MultiSelect = MutipleSelection; }