From 5a1593951bc331583e5867eea0449958509e20b9 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sat, 23 Jan 2016 11:45:36 -0300 Subject: [PATCH] -Added a "modal_close" signal for controls -Used it to keep changes on lineedit when focused out --- scene/gui/control.cpp | 5 +++++ scene/gui/tree.cpp | 16 ++++++++++++++++ scene/gui/tree.h | 1 + 3 files changed, 22 insertions(+) diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 8f6a0b4d536..dce0a4ac0e9 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -509,6 +509,10 @@ void Control::_notification(int p_notification) { update(); } break; + case NOTIFICATION_MODAL_CLOSE: { + + emit_signal("modal_close"); + } break; case NOTIFICATION_VISIBILITY_CHANGED: { if (!is_visible()) { @@ -2246,6 +2250,7 @@ void Control::_bind_methods() { ADD_SIGNAL( MethodInfo("focus_exit") ); ADD_SIGNAL( MethodInfo("size_flags_changed") ); ADD_SIGNAL( MethodInfo("minimum_size_changed") ); + ADD_SIGNAL( MethodInfo("modal_close") ); } diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index e6f09ece94b..e81c08dbeac 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -1721,6 +1721,20 @@ int Tree::propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_ } +void Tree::_text_editor_modal_close() { + + if ( Input::get_singleton()->is_key_pressed(KEY_ESCAPE) || + Input::get_singleton()->is_key_pressed(KEY_ENTER) || + Input::get_singleton()->is_key_pressed(KEY_RETURN) ) { + + return; + } + + + text_editor_enter(text_editor->get_text()); +} + + void Tree::text_editor_enter(String p_text) { @@ -3185,6 +3199,7 @@ void Tree::_bind_methods() { ObjectTypeDB::bind_method(_MD("_input_event"),&Tree::_input_event); ObjectTypeDB::bind_method(_MD("_popup_select"),&Tree::popup_select); ObjectTypeDB::bind_method(_MD("_text_editor_enter"),&Tree::text_editor_enter); + ObjectTypeDB::bind_method(_MD("_text_editor_modal_close"),&Tree::_text_editor_modal_close); ObjectTypeDB::bind_method(_MD("_value_editor_changed"),&Tree::value_editor_changed); ObjectTypeDB::bind_method(_MD("_scroll_moved"),&Tree::_scroll_moved); @@ -3283,6 +3298,7 @@ Tree::Tree() { h_scroll->connect("value_changed", this,"_scroll_moved"); v_scroll->connect("value_changed", this,"_scroll_moved"); text_editor->connect("text_entered", this,"_text_editor_enter"); + text_editor->connect("modal_close", this,"_text_editor_modal_close"); popup_menu->connect("item_pressed", this,"_popup_select"); value_editor->connect("value_changed", this,"_value_editor_changed"); diff --git a/scene/gui/tree.h b/scene/gui/tree.h index 54e6a9c6b9a..e4d349978c9 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -314,6 +314,7 @@ friend class TreeItem; void select_single_item(TreeItem *p_selected,TreeItem *p_current,int p_col,TreeItem *p_prev=NULL,bool *r_in_range=NULL); int propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_doubleclick,TreeItem *p_item,int p_button,const InputModifierState& p_mod); void text_editor_enter(String p_text); + void _text_editor_modal_close(); void value_editor_changed(double p_value); void popup_select(int p_option);