protected EditorTextField(int maxLength, bool multiline, bool isPasswordField, char maskChar) : base(maxLength, multiline, isPasswordField, maskChar) { ContextualMenu contextualMenu = new ContextualMenu(); contextualMenu.AddAction("Cut", new GenericMenu.MenuFunction(this.Cut), new ContextualMenu.ActionStatusCallback(this.CutCopyActionStatus)); contextualMenu.AddAction("Copy", new GenericMenu.MenuFunction(this.Copy), new ContextualMenu.ActionStatusCallback(this.CutCopyActionStatus)); contextualMenu.AddAction("Paste", new GenericMenu.MenuFunction(this.Paste), new ContextualMenu.ActionStatusCallback(this.PasteActionStatus)); base.AddManipulator(contextualMenu); }
protected override void DoDisplayMenu(ContextualMenu menu, EventBase triggerEvent) { var genericMenu = new GenericMenu(); foreach (var item in menu.MenuItems()) { var action = item as ContextualMenu.MenuAction; if (action != null) { if ((action.status & ContextualMenu.MenuAction.StatusFlags.Hidden) == ContextualMenu.MenuAction.StatusFlags.Hidden) { continue; } bool isChecked = (action.status & ContextualMenu.MenuAction.StatusFlags.Checked) == ContextualMenu.MenuAction.StatusFlags.Checked; if ((action.status & ContextualMenu.MenuAction.StatusFlags.Disabled) == ContextualMenu.MenuAction.StatusFlags.Disabled) { genericMenu.AddDisabledItem(new GUIContent(action.name)); } else { genericMenu.AddItem(new GUIContent(action.name), isChecked, () => { action.Execute(); }); } } else { var separator = item as ContextualMenu.Separator; if (separator != null) { genericMenu.AddSeparator(separator.subMenuPath); } } } Vector2 position = Vector2.zero; if (triggerEvent is IMouseEvent) { position = ((IMouseEvent)triggerEvent).mousePosition; } else if (triggerEvent.target is VisualElement) { position = ((VisualElement)triggerEvent.target).layout.center; } genericMenu.DropDown(new Rect(position, Vector2.zero)); }
protected override void DoDisplayMenu(ContextualMenu menu, EventBase triggerEvent) { GenericMenu genericMenu = new GenericMenu(); foreach (ContextualMenu.MenuItem current in menu.MenuItems()) { ContextualMenu.MenuAction action = current as ContextualMenu.MenuAction; if (action != null) { if ((action.status & ContextualMenu.MenuAction.StatusFlags.Hidden) != ContextualMenu.MenuAction.StatusFlags.Hidden) { bool on = (action.status & ContextualMenu.MenuAction.StatusFlags.Checked) == ContextualMenu.MenuAction.StatusFlags.Checked; if ((action.status & ContextualMenu.MenuAction.StatusFlags.Disabled) == ContextualMenu.MenuAction.StatusFlags.Disabled) { genericMenu.AddDisabledItem(new GUIContent(action.name)); } else { genericMenu.AddItem(new GUIContent(action.name), on, delegate { action.Execute(triggerEvent); }); } } } else { genericMenu.AddSeparator(string.Empty); } } Vector2 position = Vector2.zero; if (triggerEvent is IMouseEvent) { position = ((IMouseEvent)triggerEvent).mousePosition; } else if (triggerEvent.target is VisualElement) { position = ((VisualElement)triggerEvent.target).layout.center; } genericMenu.DropDown(new Rect(position, Vector2.zero)); }