Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scene Tree Dock: added ability to deselect items when clicking on empty space #13308

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions editor/scene_tree_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,12 @@ void SceneTreeEditor::_selected_changed() {
blocked--;
}

void SceneTreeEditor::_deselect_items() {

// Clear currently elected items in scene tree dock.
editor_selection->clear();
}

void SceneTreeEditor::_cell_multi_selected(Object *p_object, int p_cell, bool p_selected) {

TreeItem *item = Object::cast_to<TreeItem>(p_object);
Expand Down Expand Up @@ -929,6 +935,7 @@ void SceneTreeEditor::_bind_methods() {
ClassDB::bind_method("_update_tree", &SceneTreeEditor::_update_tree);
ClassDB::bind_method("_node_removed", &SceneTreeEditor::_node_removed);
ClassDB::bind_method("_selected_changed", &SceneTreeEditor::_selected_changed);
ClassDB::bind_method("_deselect_items", &SceneTreeEditor::_deselect_items);
ClassDB::bind_method("_renamed", &SceneTreeEditor::_renamed);
ClassDB::bind_method("_rename_node", &SceneTreeEditor::_rename_node);
ClassDB::bind_method("_test_update_tree", &SceneTreeEditor::_test_update_tree);
Expand Down Expand Up @@ -1005,6 +1012,7 @@ SceneTreeEditor::SceneTreeEditor(bool p_label, bool p_can_rename, bool p_can_ope
tree->connect("item_edited", this, "_renamed", varray(), CONNECT_DEFERRED);
tree->connect("multi_selected", this, "_cell_multi_selected");
tree->connect("button_pressed", this, "_cell_button_pressed");
tree->connect("nothing_selected", this, "_deselect_items");
//tree->connect("item_edited", this,"_renamed",Vector<Variant>(),true);

error = memnew(AcceptDialog);
Expand Down
1 change: 1 addition & 0 deletions editor/scene_tree_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class SceneTreeEditor : public Control {
TreeItem *_find(TreeItem *p_node, const NodePath &p_path);
void _notification(int p_what);
void _selected_changed();
void _deselect_items();
void _rename_node(ObjectID p_node, const String &p_name);

void _cell_collapsed(Object *p_obj);
Expand Down
4 changes: 4 additions & 0 deletions scene/gui/tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1923,6 +1923,9 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
c = c->next;
item_h += child_h;
}

if (!c && !p_mod->get_shift() && !p_mod->get_control() && !p_mod->get_command() && !click_handled && p_button != BUTTON_RIGHT)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this work with BUTTON_MIDDLE?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. I just ignore right mouse button in this case because it has popup menu

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But selection does not work with the MMB, so I don't see why it should with deselection

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, then it will not deselect. So nothing broken after all, right? :)

emit_signal("nothing_selected");
}
}

Expand Down Expand Up @@ -3750,6 +3753,7 @@ void Tree::_bind_methods() {
ADD_SIGNAL(MethodInfo("custom_popup_edited", PropertyInfo(Variant::BOOL, "arrow_clicked")));
ADD_SIGNAL(MethodInfo("item_activated"));
ADD_SIGNAL(MethodInfo("column_title_pressed", PropertyInfo(Variant::INT, "column")));
ADD_SIGNAL(MethodInfo("nothing_selected"));

BIND_ENUM_CONSTANT(SELECT_SINGLE);
BIND_ENUM_CONSTANT(SELECT_ROW);
Expand Down