Example #1
0
        public FlowLayoutWidget CreateMenuItems(PopupMenu popupMenu, IEnumerable <NamedAction> menuActions, bool emptyMenu = true)
        {
            // Retain past behavior, where menu is cleared each call. More recent callers many pass in a newly populated menu and
            // not require the clear
            if (emptyMenu)
            {
                popupMenu.CloseAllChildren();
            }

            // Create menu items in the DropList for each element in this.menuActions
            foreach (var menuAction in menuActions)
            {
                if (menuAction is ActionSeparator)
                {
                    popupMenu.CreateSeparator();
                }
                else
                {
                    PopupMenu.MenuItem menuItem;

                    if (menuAction is NamedBoolAction boolAction)
                    {
                        menuItem = popupMenu.CreateBoolMenuItem(menuAction.Title, boolAction.GetIsActive, boolAction.SetIsActive);
                    }
                    else
                    {
                        menuItem = popupMenu.CreateMenuItem(menuAction.Title, menuAction.Icon, menuAction.Shortcut);
                    }

                    menuItem.Name = $"{menuAction.Title} Menu Item";

                    menuItem.Enabled = menuAction.Action != null &&
                                       menuAction.IsEnabled?.Invoke() != false;

                    menuItem.ClearRemovedFlag();

                    if (menuItem.Enabled)
                    {
                        menuItem.Click += (s, e) =>
                        {
                            menuAction.Action();
                        };
                    }
                }
            }

            return(popupMenu);
        }
Example #2
0
        public FlowLayoutWidget CreateMenuItems(PopupMenu popupMenu, IEnumerable <NamedAction> menuActions)
        {
            // Create menu items in the DropList for each element in this.menuActions
            popupMenu.CloseAllChildren();
            foreach (var menuAction in menuActions)
            {
                if (menuAction.Title == "----")
                {
                    popupMenu.CreateHorizontalLine();
                }
                else
                {
                    PopupMenu.MenuItem menuItem;

                    if (menuAction is NamedBoolAction boolAction)
                    {
                        menuItem = popupMenu.CreateBoolMenuItem(menuAction.Title, boolAction.GetIsActive, boolAction.SetIsActive);
                    }
                    else
                    {
                        menuItem = popupMenu.CreateMenuItem(menuAction.Title, menuAction.Icon, menuAction.Shortcut);
                    }

                    menuItem.Name = $"{menuAction.Title} Menu Item";

                    menuItem.Enabled = menuAction.Action != null &&
                                       menuAction.IsEnabled?.Invoke() != false;

                    menuItem.ClearRemovedFlag();

                    if (menuItem.Enabled)
                    {
                        menuItem.Click += (s, e) =>
                        {
                            menuAction.Action();
                        };
                    }
                }
            }

            return(popupMenu);
        }