From af8bf6f1d0dc266cc8b771fe9a0de92b03bbc1d2 Mon Sep 17 00:00:00 2001 From: Danil Alexeev Date: Thu, 26 Jan 2023 20:59:41 +0300 Subject: Fix `LineEdit` and `TextEdit` context menus not customizable --- doc/classes/LineEdit.xml | 89 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 67 insertions(+), 22 deletions(-) (limited to 'doc/classes/LineEdit.xml') diff --git a/doc/classes/LineEdit.xml b/doc/classes/LineEdit.xml index b8383aaed9..8ed8622030 100644 --- a/doc/classes/LineEdit.xml +++ b/doc/classes/LineEdit.xml @@ -61,6 +61,45 @@ Returns the [PopupMenu] of this [LineEdit]. By default, this menu is displayed when right-clicking on the [LineEdit]. + You can add custom menu items or remove standard ones. Make sure your IDs don't conflict with the standard ones (see [enum MenuItems]). For example: + [codeblocks] + [gdscript] + func _ready(): + var menu = get_menu() + # Remove all items after "Redo". + menu.item_count = menu.get_item_index(MENU_REDO) + 1 + # Add custom items. + menu.add_separator() + menu.add_item("Insert Date", MENU_MAX + 1) + # Connect callback. + menu.id_pressed.connect(_on_item_pressed) + + func _on_item_pressed(id): + if id == MENU_MAX + 1: + insert_text_at_caret(Time.get_date_string_from_system()) + [/gdscript] + [csharp] + public override void _Ready() + { + var menu = GetMenu(); + // Remove all items after "Redo". + menu.ItemCount = menu.GetItemIndex(LineEdit.MenuItems.Redo) + 1; + // Add custom items. + menu.AddSeparator(); + menu.AddItem("Insert Date", LineEdit.MenuItems.Max + 1); + // Add event handler. + menu.IdPressed += OnItemPressed; + } + + public void OnItemPressed(int id) + { + if (id == LineEdit.MenuItems.Max + 1) + { + InsertTextAtCaret(Time.GetDateStringFromSystem()); + } + } + [/csharp] + [/codeblocks] [b]Warning:[/b] This is a required internal node, removing and freeing it may cause a crash. If you wish to hide it or any of its children, use their [member Window.visible] property. @@ -296,70 +335,76 @@ Reverse the last undo action. - + + ID of "Text Writing Direction" submenu. + + Sets text direction to inherited. - + Sets text direction to automatic. - + Sets text direction to left-to-right. - + Sets text direction to right-to-left. - + Toggles control character display. - + + ID of "Insert Control Character" submenu. + + Inserts left-to-right mark (LRM) character. - + Inserts right-to-left mark (RLM) character. - + Inserts start of left-to-right embedding (LRE) character. - + Inserts start of right-to-left embedding (RLE) character. - + Inserts start of left-to-right override (LRO) character. - + Inserts start of right-to-left override (RLO) character. - + Inserts pop direction formatting (PDF) character. - + Inserts Arabic letter mark (ALM) character. - + Inserts left-to-right isolate (LRI) character. - + Inserts right-to-left isolate (RLI) character. - + Inserts first strong isolate (FSI) character. - + Inserts pop direction isolate (PDI) character. - + Inserts zero width joiner (ZWJ) character. - + Inserts zero width non-joiner (ZWNJ) character. - + Inserts word joiner (WJ) character. - + Inserts soft hyphen (SHY) character. - + Represents the size of the [enum MenuItems] enum. -- cgit v1.2.3