public override void Awake() { base.Awake(); _button = GetComponent <Button>(); _audioSource = GetComponent <AudioSource>(); _image = GetComponent <Image>(); _handler = FindObjectOfType <UIActionHandler>(); _savedFontSize = MINTEXTSIZE; }
public UIMenuStrip(TUIActionControl ownerControl) { ActionHandler = ownerControl.ActionHandler; // Add a dummy item, or else no context menu strip will be opened even if the opening event is fired. Items.Add(dummyItem); // Dispose when the action provider is disposed. this.ownerControl = ownerControl; this.ownerControl.Disposed += Parent_Disposed; }
/// <summary> /// Dynamically adds menu items to a <see cref="ToolStripItemCollection"/> /// given the set of <see cref="IContextMenuUIActionInterface"/>s which are defined in a <see cref="UIActionHandler"/>. /// </summary> /// <param name="actionHandler"> /// The <see cref="UIActionHandler"/> which performs actions and defines the <see cref="IContextMenuUIActionInterface"/>s. /// </param> /// <param name="destination"> /// The <see cref="ToolStripItemCollection"/> in which to generate the menu items. /// </param> public static void BuildMenu(UIActionHandler actionHandler, ToolStripItemCollection destination) { var rootMenuNodes = new List <UIMenuNode>(); // Extract all ContextMenuUIActionInterfaces from the handler. foreach (var(interfaceSet, action) in actionHandler.InterfaceSets) { if (interfaceSet.TryGet(out IContextMenuUIActionInterface contextMenuInterface)) { rootMenuNodes.Add(new UIMenuNode.Element(action, contextMenuInterface)); } } BuildMenu(actionHandler, rootMenuNodes, destination); }
internal UIAutoHideMainMenuItem(UIAutoHideMainMenu owner, UIMenuNode.Container containerNode) { Owner = owner; ContainerNode = containerNode; DropDownItemsActionHandler = new UIActionHandler(); }
UIMenuBuilder(UIActionHandler actionHandler) { ActionHandler = actionHandler; }
/// <summary> /// Dynamically adds menu items to a <see cref="ToolStripItemCollection"/>. /// </summary> /// <param name="actionHandler"> /// The <see cref="UIActionHandler"/> which performs actions and defines the blueprint <see cref="UIMenuNode"/>. /// </param> /// <param name="rootMenuNodes"> /// Collection of the menu items to generate. /// </param> /// <param name="destination"> /// The <see cref="ToolStripItemCollection"/> in which to generate the menu items. /// </param> public static void BuildMenu(UIActionHandler actionHandler, IEnumerable <UIMenuNode> rootMenuNodes, ToolStripItemCollection destination) => new UIMenuBuilder(actionHandler).BuildMenu(rootMenuNodes, destination);
private protected MenuCaptionBarForm() { SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.UserMouse | ControlStyles.OptimizedDoubleBuffer | ControlStyles.FixedHeight | ControlStyles.FixedWidth | ControlStyles.ResizeRedraw | ControlStyles.Opaque, true); minimizeButton = CreateCaptionButton(); minimizeButton.Click += (_, __) => WindowState = FormWindowState.Minimized; maximizeButton = CreateCaptionButton(); maximizeButton.Click += (_, __) => { inRestoreCommand = WindowState == FormWindowState.Maximized; try { WindowState = WindowState == FormWindowState.Maximized ? FormWindowState.Normal : FormWindowState.Maximized; } finally { inRestoreCommand = false; } UpdateMaximizeButtonIcon(); }; // Specialized save button which binds on the SaveToFile UIAction. saveButton = CreateCaptionButton(); saveButton.Visible = false; saveButton.Click += (_, __) => { try { ActionHandler.TryPerformAction(SharedUIAction.SaveToFile.Action, true); } catch (Exception exc) { MessageBox.Show(exc.Message); } }; ActionHandler.UIActionsInvalidated += _ => { // Update the save button each time the handler is invalidated. // Some kind of checked state doesn't seem to be supported, so ignore UIActionState.Checked. UIActionState currentActionState = ActionHandler.TryPerformAction(SharedUIAction.SaveToFile.Action, false); saveButton.Visible = currentActionState.Visible; saveButton.Enabled = currentActionState.Enabled; if (!saveButton.Enabled) { saveButton.FlatAppearance.BorderColor = ObservableStyle.BackColor; } }; closeButton = CreateCaptionButton(); closeButton.Click += (_, __) => Close(); MainMenuStrip = new MenuStrip(); SuspendLayout(); Controls.Add(minimizeButton); Controls.Add(maximizeButton); Controls.Add(saveButton); Controls.Add(closeButton); Controls.Add(MainMenuStrip); ResumeLayout(); ToolTip = new ToolTip(); UpdateToolTips(); ObservableStyle.NotifyChange += ObservableStyle_NotifyChange; AllowTransparency = true; TransparencyKey = ObservableStyle.SuggestedTransparencyKey; mainMenuActionHandler = new UIActionHandler(); this.BindActions(StandardUIActionBindings); Session.Current.CurrentLocalizerChanged += CurrentLocalizerChanged; }