diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-04-30 10:15:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-30 10:15:47 +0200 |
commit | ea30bcdfef5c869f5b37a1d9af8b7ea32ba25cb4 (patch) | |
tree | 08ce8f85f3a171aeaeb501b6074af9411d75e852 /scene/gui/line_edit.cpp | |
parent | e98ccaefe8bfe636cb7fc43667a41e7fce69ec45 (diff) | |
parent | f7a45eb0de38efa533bb2f83a6684e1e41bb2ef5 (diff) |
Merge pull request #28287 from YeldhamDev/text_editable_contextmenu
Make 'Line/TextEdit's context menus hide their editing options when in readonly mode
Diffstat (limited to 'scene/gui/line_edit.cpp')
-rw-r--r-- | scene/gui/line_edit.cpp | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 4536cfe17c..d889c8d8b8 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -1328,7 +1328,27 @@ void LineEdit::select_all() { void LineEdit::set_editable(bool p_editable) { + if (editable == p_editable) + return; + editable = p_editable; + + // Reorganize context menu. + menu->clear(); + if (editable) + menu->add_item(RTR("Cut"), MENU_CUT, KEY_MASK_CMD | KEY_X); + menu->add_item(RTR("Copy"), MENU_COPY, KEY_MASK_CMD | KEY_C); + if (editable) + menu->add_item(RTR("Paste"), MENU_PASTE, KEY_MASK_CMD | KEY_V); + menu->add_separator(); + menu->add_item(RTR("Select All"), MENU_SELECT_ALL, KEY_MASK_CMD | KEY_A); + if (editable) { + menu->add_item(RTR("Clear"), MENU_CLEAR); + menu->add_separator(); + menu->add_item(RTR("Undo"), MENU_UNDO, KEY_MASK_CMD | KEY_Z); + menu->add_item(RTR("Redo"), MENU_REDO, KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_Z); + } + update(); } @@ -1624,7 +1644,6 @@ LineEdit::LineEdit() { deselect(); set_focus_mode(FOCUS_ALL); - editable = true; set_default_cursor_shape(CURSOR_IBEAM); set_mouse_filter(MOUSE_FILTER_STOP); @@ -1639,15 +1658,7 @@ LineEdit::LineEdit() { context_menu_enabled = true; menu = memnew(PopupMenu); add_child(menu); - menu->add_item(RTR("Cut"), MENU_CUT, KEY_MASK_CMD | KEY_X); - menu->add_item(RTR("Copy"), MENU_COPY, KEY_MASK_CMD | KEY_C); - menu->add_item(RTR("Paste"), MENU_PASTE, KEY_MASK_CMD | KEY_V); - menu->add_separator(); - menu->add_item(RTR("Select All"), MENU_SELECT_ALL, KEY_MASK_CMD | KEY_A); - menu->add_item(RTR("Clear"), MENU_CLEAR); - menu->add_separator(); - menu->add_item(RTR("Undo"), MENU_UNDO, KEY_MASK_CMD | KEY_Z); - menu->add_item(RTR("Redo"), MENU_REDO, KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_Z); + set_editable(true); menu->connect("id_pressed", this, "menu_option"); expand_to_text_length = false; } |