Fix doubleclick on tree item, restore input focus on previous windows.

Closes #37335
This commit is contained in:
Juan Linietsky 2020-07-01 10:59:42 -03:00
parent 8a484756de
commit 058166fb6c
7 changed files with 31 additions and 17 deletions

View file

@ -1786,7 +1786,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
case TreeItem::CELL_MODE_STRING: {
//nothing in particular
if (select_mode == SELECT_MULTI && (get_tree()->get_event_count() == focus_in_id || !already_cursor)) {
if (select_mode == SELECT_MULTI && (get_viewport()->get_processed_events_count() == focus_in_id || !already_cursor)) {
bring_up_editor = false;
}
@ -1861,7 +1861,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
} else {
editor_text = String::num(p_item->cells[col].val, Math::range_step_decimals(p_item->cells[col].step));
if (select_mode == SELECT_MULTI && get_tree()->get_event_count() == focus_in_id) {
if (select_mode == SELECT_MULTI && get_viewport()->get_processed_events_count() == focus_in_id) {
bring_up_editor = false;
}
}
@ -2787,7 +2787,7 @@ int Tree::_get_title_button_height() const {
void Tree::_notification(int p_what) {
if (p_what == NOTIFICATION_FOCUS_ENTER) {
focus_in_id = get_tree()->get_event_count();
focus_in_id = get_viewport()->get_processed_events_count();
}
if (p_what == NOTIFICATION_MOUSE_EXIT) {
if (cache.hover_type != Cache::CLICK_NONE) {
@ -3839,7 +3839,7 @@ Tree::Tree() {
add_child(popup_menu);
// popup_menu->set_as_toplevel(true);
popup_editor = memnew(PopupPanel);
popup_editor = memnew(Popup);
popup_editor->set_wrap_controls(true);
add_child(popup_editor);
popup_editor_vb = memnew(VBoxContainer);

View file

@ -359,11 +359,11 @@ private:
VBoxContainer *popup_editor_vb;
PopupPanel *popup_editor;
Popup *popup_editor;
LineEdit *text_editor;
HSlider *value_editor;
bool updating_value_editor;
int64_t focus_in_id;
uint64_t focus_in_id;
PopupMenu *popup_menu;
Vector<ColumnInfo> columns;

View file

@ -939,10 +939,6 @@ int64_t SceneTree::get_frame() const {
return current_frame;
}
int64_t SceneTree::get_event_count() const {
return current_event;
}
Array SceneTree::_get_nodes_in_group(const StringName &p_group) {
Array ret;
Map<StringName, Group>::Element *E = group_map.find(p_group);
@ -1362,7 +1358,6 @@ SceneTree::SceneTree() {
root = nullptr;
pause = false;
current_frame = 0;
current_event = 0;
tree_changed_name = "tree_changed";
node_added_name = "node_added";
node_removed_name = "node_removed";

View file

@ -110,7 +110,6 @@ private:
StringName node_renamed_name;
int64_t current_frame;
int64_t current_event;
int node_count;
#ifdef TOOLS_ENABLED
@ -300,7 +299,6 @@ public:
int get_collision_debug_contact_count() { return collision_debug_contacts; }
int64_t get_frame() const;
int64_t get_event_count() const;
int get_node_count() const;

View file

@ -2450,6 +2450,22 @@ void Viewport::_gui_remove_control(Control *p_control) {
}
}
Window *Viewport::get_base_window() const {
Viewport *v = const_cast<Viewport *>(this);
Window *w = Object::cast_to<Window>(v);
while (!w) {
v = v->get_parent_viewport();
w = Object::cast_to<Window>(v);
}
return w;
}
void Viewport::_gui_remove_focus_for_window(Node *p_window) {
if (get_base_window() == p_window) {
_gui_remove_focus();
}
}
void Viewport::_gui_remove_focus() {
if (gui.key_focus) {
Node *f = gui.key_focus;
@ -2467,7 +2483,7 @@ void Viewport::_gui_control_grab_focus(Control *p_control) {
if (gui.key_focus && gui.key_focus == p_control) {
return;
}
get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, "_viewports", "_gui_remove_focus");
get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, "_viewports", "_gui_remove_focus_for_window", (Node *)get_base_window());
gui.key_focus = p_control;
emit_signal("gui_focus_changed", p_control);
p_control->notification(Control::NOTIFICATION_FOCUS_ENTER);
@ -2924,6 +2940,8 @@ void Viewport::input(const Ref<InputEvent> &p_event, bool p_local_coords) {
if (!is_input_handled()) {
_gui_input_event(ev);
}
event_count++;
//get_tree()->call_group(SceneTree::GROUP_CALL_REVERSE|SceneTree::GROUP_CALL_REALTIME|SceneTree::GROUP_CALL_MULIILEVEL,gui_input_group,"_gui_input",ev); //special one for GUI, as controls use their own process check
}
@ -3305,8 +3323,7 @@ void Viewport::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_disable_input", "disable"), &Viewport::set_disable_input);
ClassDB::bind_method(D_METHOD("is_input_disabled"), &Viewport::is_input_disabled);
ClassDB::bind_method(D_METHOD("_gui_show_tooltip"), &Viewport::_gui_show_tooltip);
ClassDB::bind_method(D_METHOD("_gui_remove_focus"), &Viewport::_gui_remove_focus);
ClassDB::bind_method(D_METHOD("_gui_remove_focus_for_window"), &Viewport::_gui_remove_focus_for_window);
ClassDB::bind_method(D_METHOD("_post_gui_grab_click_focus"), &Viewport::_post_gui_grab_click_focus);
ClassDB::bind_method(D_METHOD("set_shadow_atlas_size", "size"), &Viewport::set_shadow_atlas_size);

View file

@ -392,6 +392,7 @@ private:
void _gui_force_drag(Control *p_base, const Variant &p_data, Control *p_control);
void _gui_set_drag_preview(Control *p_base, Control *p_control);
void _gui_remove_focus_for_window(Node *p_window);
void _gui_remove_focus();
void _gui_unfocus_control(Control *p_control);
bool _gui_control_has_focus(const Control *p_control);
@ -442,6 +443,7 @@ private:
SubWindowResize _sub_window_get_resize_margin(Window *p_subwindow, const Point2 &p_point);
virtual bool _can_consume_input_events() const { return true; }
uint64_t event_count = 0;
protected:
void _set_size(const Size2i &p_size, const Size2i &p_size_2d_override, const Rect2i &p_to_screen_rect, const Transform2D &p_stretch_transform, bool p_allocated);
@ -455,6 +457,8 @@ protected:
virtual void _validate_property(PropertyInfo &property) const;
public:
uint64_t get_processed_events_count() const { return event_count; }
Listener3D *get_listener() const;
Camera3D *get_camera() const;
@ -572,6 +576,7 @@ public:
bool is_embedding_subwindows() const;
Viewport *get_parent_viewport() const;
Window *get_base_window() const;
void pass_mouse_focus_to(Viewport *p_viewport, Control *p_control);

View file

@ -134,7 +134,6 @@ private:
protected:
Viewport *_get_embedder() const;
virtual Rect2i _popup_adjust_rect() const { return Rect2i(); }
virtual void _post_popup() {}