Merge pull request #12789 from ianb96/context_menu_fix

Context menu disable
This commit is contained in:
Poommetee Ketson 2017-11-11 16:58:39 +07:00 committed by GitHub
commit 35e7f99299
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 63 additions and 1 deletions

View file

@ -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">

View file

@ -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">

View file

@ -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);

View file

@ -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();

View file

@ -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");

View file

@ -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();