summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/gui/line_edit.cpp14
-rw-r--r--scene/gui/line_edit.h3
-rw-r--r--scene/gui/text_edit.cpp7
-rw-r--r--scene/gui/text_edit.h2
4 files changed, 25 insertions, 1 deletions
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();