public MenuBase(string menuName) { MenuDropList = new DropDownMenu(menuName.ToUpper(), Direction.Down, pointSize: 10); MenuDropList.TextColor = ActiveTheme.Instance.PrimaryTextColor; MenuDropList.Margin = new BorderDouble(0); MenuDropList.Padding = new BorderDouble(4, 4, 0, 4); MenuDropList.MenuItemsPadding = new BorderDouble(8, 4); MenuDropList.DrawDirectionalArrow = false; MenuDropList.MenuAsWideAsItems = false; menuActions = new List<MenuItemAction>(GetMenuActions()); //Add the menu items to the menu itself foreach (MenuItemAction item in menuActions) { if (item.Title.StartsWith("-----")) { MenuDropList.AddHorizontalLine(); } else { MenuItem newItem = MenuDropList.AddItem(item.Title, pointSize: 11); if (item.Action == null) { newItem.Enabled = false; } } } AddChild(MenuDropList); this.Width = GetChildrenBoundsIncludingMargins().Width; this.Height = 22 * GuiWidget.DeviceScale; this.Margin = new BorderDouble(0); this.Padding = new BorderDouble(0); this.VAnchor = Agg.UI.VAnchor.ParentCenter; this.MenuDropList.SelectionChanged += MenuDropList_SelectionChanged; this.MenuDropList.OpenOffset = new Vector2(0, 0); }
private void CreateActionMenuItems(DropDownMenu actionMenu) { actionMenu.SelectionChanged += (sender, e) => { string menuSelection = ((DropDownMenu)sender).SelectedValue; foreach (var menuItem in menuItems) { if (menuItem.Title == menuSelection) { menuItem.Action?.Invoke(null, null); } } }; // edit menu item menuItems.Add(new PrintItemAction() { Title = "Edit".Localize(), Action = (s, e) => editButton_Click(s, null) }); actionMenuEnableData.Add(new MenuEnableData( actionMenu.AddItem(menuItems[menuItems.Count - 1].Title), false, false, false)); actionMenu.AddHorizontalLine(); // rename menu item menuItems.Add(new PrintItemAction() { Title = "Rename".Localize(), Action = (s, e) => renameFromLibraryButton_Click(s, null) }); actionMenuEnableData.Add(new MenuEnableData(actionMenu.AddItem(menuItems[menuItems.Count - 1].Title), false, false, true)); // move menu item menuItems.Add(new PrintItemAction() { Title = "Move".Localize(), Action = (s, e) => moveInLibraryButton_Click(s, null) }); //actionMenuEnableData.Add(new MenuEnableData(actionMenu.AddItem(menuItems[menuItems.Count - 1].Title), true, false, true)); // remove menu item menuItems.Add(new PrintItemAction() { Title = "Remove".Localize(), Action = (s, e) => deleteFromLibraryButton_Click(s, null) }); actionMenuEnableData.Add(new MenuEnableData( actionMenu.AddItem(menuItems[menuItems.Count - 1].Title), true, false, true)); actionMenu.AddHorizontalLine(); // add to queue menu item menuItems.Add(new PrintItemAction() { Title = "Add to Queue".Localize(), Action = (s, e) => addToQueueButton_Click(s, null) }); actionMenuEnableData.Add(new MenuEnableData( actionMenu.AddItem(menuItems[menuItems.Count - 1].Title), true, true, false)); // export menu item menuItems.Add(new PrintItemAction() { Title = "Export".Localize(), Action = (s, e) => exportButton_Click(s, null) }); actionMenuEnableData.Add(new MenuEnableData( actionMenu.AddItem(menuItems[menuItems.Count - 1].Title), false, false, false)); // share menu item menuItems.Add(new PrintItemAction() { Title = "Share".Localize(), Action = (s, e) => shareFromLibraryButton_Click(s, null) }); actionMenuEnableData.Add(new MenuEnableData( actionMenu.AddItem(menuItems[menuItems.Count - 1].Title), false, false, false, true)); SetActionMenuStates(); }