diff options
-rw-r--r-- | doc/classes/LineEdit.xml | 19 | ||||
-rw-r--r-- | doc/classes/TextEdit.xml | 19 | ||||
-rw-r--r-- | scene/gui/line_edit.cpp | 14 | ||||
-rw-r--r-- | scene/gui/line_edit.h | 3 | ||||
-rw-r--r-- | scene/gui/text_edit.cpp | 7 | ||||
-rw-r--r-- | scene/gui/text_edit.h | 2 |
6 files changed, 63 insertions, 1 deletions
diff --git a/doc/classes/LineEdit.xml b/doc/classes/LineEdit.xml index 850f724714..bf81d90efe 100644 --- a/doc/classes/LineEdit.xml +++ b/doc/classes/LineEdit.xml @@ -114,6 +114,13 @@ Return the text in the [code]LineEdit[/code]. </description> </method> + <method name="is_context_menu_enabled" qualifiers="const"> + <return type="bool"> + </return> + <description> + Returns true if the context menu is enabled. + </description> + </method> <method name="is_editable" qualifiers="const"> <return type="bool"> </return> @@ -170,6 +177,15 @@ Set text alignment of the [code]LineEdit[/code]. </description> </method> + <method name="set_context_menu_enabled"> + <return type="void"> + </return> + <argument index="0" name="enabled" type="bool"> + </argument> + <description> + Set the status of the context menu. When enabled, the context menu will appear when the [code]LineEdit[/code] is right clicked. + </description> + </method> <method name="set_cursor_position"> <return type="void"> </return> @@ -276,6 +292,9 @@ <member name="text" type="String" setter="set_text" getter="get_text"> String value of the [LineEdit]. </member> + <member name="context_menu_enabled" type="bool" setter="set_context_menu_enabled" getter="is_context_menu_enabled"> + If [code]true[/code] the context menu will appear when right clicked. + </member> </members> <signals> <signal name="text_changed"> diff --git a/doc/classes/TextEdit.xml b/doc/classes/TextEdit.xml index 43e5158515..e7f94b5826 100644 --- a/doc/classes/TextEdit.xml +++ b/doc/classes/TextEdit.xml @@ -239,6 +239,14 @@ Returns true if highlight all occurrences is enabled. </description> </method> + </method> + <method name="is_context_menu_enabled" qualifiers="const"> + <return type="bool"> + </return> + <description> + Returns true if the context menu is enabled. + </description> + </method> <method name="is_highlight_current_line_enabled" qualifiers="const"> <return type="bool"> </return> @@ -337,6 +345,15 @@ Select all the text. </description> </method> + <method name="set_context_menu_enabled"> + <return type="void"> + </return> + <argument index="0" name="enabled" type="bool"> + </argument> + <description> + Set the status of the context menu. When enabled, the context menu will appear when the [code]TextEdit[/code] is right clicked. + </description> + </method> <method name="set_highlight_all_occurrences"> <return type="void"> </return> @@ -455,6 +472,8 @@ </member> <member name="show_line_numbers" type="bool" setter="set_show_line_numbers" getter="is_show_line_numbers_enabled"> </member> + <member name="context_menu_enabled" type="bool" setter="set_context_menu_enabled" getter="is_context_menu_enabled"> + </member> <member name="smooth_scrolling" type="bool" setter="set_smooth_scroll_enable" getter="is_smooth_scroll_enabled"> </member> <member name="syntax_highlighting" type="bool" setter="set_syntax_coloring" getter="is_syntax_coloring_enabled"> diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 40e2dba6c2..5d3e5ec0e8 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -48,7 +48,7 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) { if (b.is_valid()) { - if (b->is_pressed() && b->get_button_index() == BUTTON_RIGHT) { + if (b->is_pressed() && b->get_button_index() == BUTTON_RIGHT && context_menu_enabled) { menu->set_position(get_global_transform().xform(get_local_mouse_position())); menu->set_size(Vector2(1, 1)); menu->popup(); @@ -1286,6 +1286,14 @@ void LineEdit::menu_option(int p_option) { } } +void LineEdit::set_context_menu_enabled(bool p_enable) { + context_menu_enabled = p_enable; +} + +bool LineEdit::is_context_menu_enabled() { + return context_menu_enabled; +} + PopupMenu *LineEdit::get_menu() const { return menu; } @@ -1395,6 +1403,8 @@ void LineEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("select", "from", "to"), &LineEdit::select, DEFVAL(0), DEFVAL(-1)); ClassDB::bind_method(D_METHOD("menu_option", "option"), &LineEdit::menu_option); ClassDB::bind_method(D_METHOD("get_menu"), &LineEdit::get_menu); + ClassDB::bind_method(D_METHOD("set_context_menu_enabled", "enable"), &LineEdit::set_context_menu_enabled); + ClassDB::bind_method(D_METHOD("is_context_menu_enabled"), &LineEdit::is_context_menu_enabled); ADD_SIGNAL(MethodInfo("text_changed", PropertyInfo(Variant::STRING, "text"))); ADD_SIGNAL(MethodInfo("text_entered", PropertyInfo(Variant::STRING, "text"))); @@ -1426,6 +1436,7 @@ void LineEdit::_bind_methods() { ADD_GROUP("Caret", "caret_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_blink"), "cursor_set_blink_enabled", "cursor_get_blink_enabled"); ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "caret_blink_speed", PROPERTY_HINT_RANGE, "0.1,10,0.1"), "cursor_set_blink_speed", "cursor_get_blink_speed"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "context_menu_enabled"), "set_context_menu_enabled", "is_context_menu_enabled"); } LineEdit::LineEdit() { @@ -1455,6 +1466,7 @@ LineEdit::LineEdit() { caret_blink_timer->connect("timeout", this, "_toggle_draw_caret"); cursor_set_blink_enabled(false); + context_menu_enabled = true; menu = memnew(PopupMenu); add_child(menu); menu->add_item(TTR("Cut"), MENU_CUT, KEY_MASK_CMD | KEY_X); diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h index bece29a37d..c3a299c2f5 100644 --- a/scene/gui/line_edit.h +++ b/scene/gui/line_edit.h @@ -74,6 +74,7 @@ private: String ime_text; Point2 ime_selection; + bool context_menu_enabled; PopupMenu *menu; int cursor_pos; @@ -150,6 +151,8 @@ public: virtual void drop_data(const Point2 &p_point, const Variant &p_data); void menu_option(int p_option); + void set_context_menu_enabled(bool p_enable); + bool is_context_menu_enabled(); PopupMenu *get_menu() const; void select_all(); diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 7d200a799b..f4876668f6 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -4866,6 +4866,10 @@ void TextEdit::set_context_menu_enabled(bool p_enable) { context_menu_enabled = p_enable; } +bool TextEdit::is_context_menu_enabled() { + return context_menu_enabled; +} + PopupMenu *TextEdit::get_menu() const { return menu; } @@ -4912,6 +4916,8 @@ void TextEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("set_readonly", "enable"), &TextEdit::set_readonly); ClassDB::bind_method(D_METHOD("set_wrap", "enable"), &TextEdit::set_wrap); ClassDB::bind_method(D_METHOD("set_max_chars", "amount"), &TextEdit::set_max_chars); + ClassDB::bind_method(D_METHOD("set_context_menu_enabled", "enable"), &TextEdit::set_context_menu_enabled); + ClassDB::bind_method(D_METHOD("is_context_menu_enabled"), &TextEdit::is_context_menu_enabled); ClassDB::bind_method(D_METHOD("cut"), &TextEdit::cut); ClassDB::bind_method(D_METHOD("copy"), &TextEdit::copy); @@ -4963,6 +4969,7 @@ void TextEdit::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_line_numbers"), "set_show_line_numbers", "is_show_line_numbers_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "highlight_all_occurrences"), "set_highlight_all_occurrences", "is_highlight_all_occurrences_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "override_selected_font_color"), "set_override_selected_font_color", "is_overriding_selected_font_color"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "context_menu_enabled"), "set_context_menu_enabled", "is_context_menu_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "smooth_scrolling"), "set_smooth_scroll_enable", "is_smooth_scroll_enabled"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "v_scroll_speed"), "set_v_scroll_speed", "get_v_scroll_speed"); diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index 81310b7c10..094474b264 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -547,6 +547,8 @@ public: bool is_selecting_identifiers_on_hover_enabled() const; void set_context_menu_enabled(bool p_enable); + bool is_context_menu_enabled(); + PopupMenu *get_menu() const; String get_text_for_completion(); |