/// <summary> ///// Add new menu item wrapper as child /// </summary> /// <param name="item"></param> /// <param name="path"></param> public void PlaceNewItem(MenuItemWrapper item, Queue <string> path) { if (this.IsClickable) { throw new Exception("Cannot add item to a clickable item"); } string location = path.Dequeue(); if (path.Count == 0) { //this is last part of path, child of this Children[location] = item; } else { if (Children.ContainsKey(location)) { var child = Children[location]; child.PlaceNewItem(item, path); } else { var child = new MenuItemWrapper() { Name = location, Priority = MenuItemWrapper.PRIORITY_RECALC }; Children[location] = child; child.PlaceNewItem(item, path); } } }
private MenuItemWrapper AddActiveViewMenuItems(MenuItemWrapper root, object view) { var type = view.GetType(); foreach (var mi in type.GetMethods(BindingFlags.Public | BindingFlags.Instance)) { var attr = mi.GetCustomAttribute <MenuItemHandlerAttribute>(); if (attr == null) { continue; } var menuItem = new MenuItemWrapper(attr, (Action)Delegate.CreateDelegate(typeof(Action), view, mi)); menuItem.IsEnabled = GetMenuItemEnabled(attr.Path, attr.DefaultEnabled); root.PlaceNewItem(menuItem, attr.Path); } return(root); }
private MenuItemWrapper GetStaticMenu() { var root = new MenuItemWrapper(); (string name, int priority)[] rootItemTitles = new (string, int)[]
/// <summary> /// Add new menu item wrapper as child /// </summary> /// <param name="item"></param> /// <param name="path"></param> public void PlaceNewItem(MenuItemWrapper item, string path) { var queue = new Queue <string>(path.Split('/')); PlaceNewItem(item, queue); }