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); }
/// <summary> /// Creates a new menu item with the caption and icon from the menu node. /// </summary> /// <param name="element"> /// The <see cref="UIMenuNode.Element"/> to initialize from. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="element"/> is null. /// </exception> public static UIActionToolStripMenuItem CreateFrom(UIMenuNode.Element element) { if (element == null) { throw new ArgumentNullException(nameof(element)); } return(new UIActionToolStripMenuItem(element)); }
private UIActionToolStripMenuItem(UIMenuNode.Element element) : base(element.TextProvider, element.IconProvider, element.ShortcutKeyDisplayTextProviders, element.OpensDialog) { Action = element.Action; }