コード例 #1
0
        ToolStripMenuItem IUIMenuTreeVisitor <ToolStripMenuItem> .VisitElement(UIMenuNode.Element element)
        {
            if (element.TextProvider == null && element.IconProvider == null)
            {
                return(null);
            }

            UIActionState currentActionState = ActionHandler.TryPerformAction(element.Action, false);

            if (!currentActionState.Visible)
            {
                return(null);
            }

            var menuItem = UIActionToolStripMenuItem.CreateFrom(element);

            menuItem.Update(currentActionState);

            var actionHandler = ActionHandler;

            menuItem.Click += (_, __) =>
            {
                try
                {
                    actionHandler.TryPerformAction(element.Action, true);
                }
                catch (Exception exc)
                {
                    MessageBox.Show(exc.Message);
                }
            };

            return(menuItem);
        }
コード例 #2
0
        private void MainMenuItem_DropDownOpening(object sender, EventArgs e)
        {
            var mainMenuItem = (ToolStripDropDownItem)sender;

            // Use DefaultForeColor rather than titleBarForeColor when dropped down.
            mainMenuItem.ForeColor = DefaultForeColor;

            // Remember last toolstrip separator before a developer tool item with FirstInGroup set.
            ToolStripSeparator lastSeparator = null;

            foreach (ToolStripItem toolStripItem in mainMenuItem.DropDownItems)
            {
                if (toolStripItem is UIActionToolStripMenuItem menuItem)
                {
                    UIActionState actionState = mainMenuActionHandler.TryPerformAction(menuItem.Action, false);
                    menuItem.Update(actionState);

                    if (Session.IsDeveloperTool(menuItem.Action))
                    {
                        // Hide instead of disable developer tool items.
                        bool visible = actionState.UIActionVisibility == UIActionVisibility.Enabled;
                        menuItem.Visible = visible;
                        if (lastSeparator != null)
                        {
                            lastSeparator.Visible = visible;
                        }
                    }
                }

                lastSeparator = toolStripItem as ToolStripSeparator;
            }
        }
コード例 #3
0
        private bool UpdateMenu()
        {
            bool atLeastOneItemEnabled = false;

            foreach (var menuItem in MenuItem.DropDownItems.OfType <UIActionToolStripMenuItem>())
            {
                var state = DropDownItemsActionHandler.TryPerformAction(menuItem.Action, false);
                menuItem.Update(state);
                atLeastOneItemEnabled |= state.Enabled;
            }

            return(atLeastOneItemEnabled);
        }