You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-23 15:16:17 +00:00
Keep selected node visible after filter change
(Implemented both for the local and remote scene tree docks.)
This commit is contained in:
@@ -129,6 +129,8 @@ void EditorDebuggerTree::update_scene_tree(const SceneDebuggerTree *p_tree, int
|
|||||||
updating_scene_tree = true;
|
updating_scene_tree = true;
|
||||||
const String last_path = get_selected_path();
|
const String last_path = get_selected_path();
|
||||||
const String filter = EditorNode::get_singleton()->get_scene_tree_dock()->get_filter();
|
const String filter = EditorNode::get_singleton()->get_scene_tree_dock()->get_filter();
|
||||||
|
bool filter_changed = filter != last_filter;
|
||||||
|
TreeItem *scroll_item = nullptr;
|
||||||
|
|
||||||
// Nodes are in a flatten list, depth first. Use a stack of parents, avoid recursion.
|
// Nodes are in a flatten list, depth first. Use a stack of parents, avoid recursion.
|
||||||
List<Pair<TreeItem *, int>> parents;
|
List<Pair<TreeItem *, int>> parents;
|
||||||
@@ -162,11 +164,17 @@ void EditorDebuggerTree::update_scene_tree(const SceneDebuggerTree *p_tree, int
|
|||||||
if (debugger_id == p_debugger) { // Can use remote id.
|
if (debugger_id == p_debugger) { // Can use remote id.
|
||||||
if (node.id == inspected_object_id) {
|
if (node.id == inspected_object_id) {
|
||||||
item->select(0);
|
item->select(0);
|
||||||
|
if (filter_changed) {
|
||||||
|
scroll_item = item;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else { // Must use path
|
} else { // Must use path
|
||||||
if (last_path == _get_path(item)) {
|
if (last_path == _get_path(item)) {
|
||||||
updating_scene_tree = false; // Force emission of new selection
|
updating_scene_tree = false; // Force emission of new selection
|
||||||
item->select(0);
|
item->select(0);
|
||||||
|
if (filter_changed) {
|
||||||
|
scroll_item = item;
|
||||||
|
}
|
||||||
updating_scene_tree = true;
|
updating_scene_tree = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -183,6 +191,9 @@ void EditorDebuggerTree::update_scene_tree(const SceneDebuggerTree *p_tree, int
|
|||||||
}
|
}
|
||||||
parent->remove_child(item);
|
parent->remove_child(item);
|
||||||
memdelete(item);
|
memdelete(item);
|
||||||
|
if (scroll_item == item) {
|
||||||
|
scroll_item = nullptr;
|
||||||
|
}
|
||||||
if (had_siblings) {
|
if (had_siblings) {
|
||||||
break; // Parent must survive.
|
break; // Parent must survive.
|
||||||
}
|
}
|
||||||
@@ -199,6 +210,10 @@ void EditorDebuggerTree::update_scene_tree(const SceneDebuggerTree *p_tree, int
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
debugger_id = p_debugger; // Needed by hook, could be avoided if every debugger had its own tree
|
debugger_id = p_debugger; // Needed by hook, could be avoided if every debugger had its own tree
|
||||||
|
if (scroll_item) {
|
||||||
|
call_deferred("scroll_to_item", scroll_item);
|
||||||
|
}
|
||||||
|
last_filter = filter;
|
||||||
updating_scene_tree = false;
|
updating_scene_tree = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ private:
|
|||||||
Set<ObjectID> unfold_cache;
|
Set<ObjectID> unfold_cache;
|
||||||
PopupMenu *item_menu = nullptr;
|
PopupMenu *item_menu = nullptr;
|
||||||
EditorFileDialog *file_dialog = nullptr;
|
EditorFileDialog *file_dialog = nullptr;
|
||||||
|
String last_filter;
|
||||||
|
|
||||||
String _get_path(TreeItem *p_item);
|
String _get_path(TreeItem *p_item);
|
||||||
void _scene_tree_folded(Object *p_obj);
|
void _scene_tree_folded(Object *p_obj);
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ void SceneTreeEditor::_toggle_visible(Node *p_node) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) {
|
bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent, bool p_scroll_to_selected) {
|
||||||
if (!p_node) {
|
if (!p_node) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -391,15 +391,19 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool scroll = false;
|
||||||
|
|
||||||
if (editor_selection) {
|
if (editor_selection) {
|
||||||
if (editor_selection->is_selected(p_node)) {
|
if (editor_selection->is_selected(p_node)) {
|
||||||
item->select(0);
|
item->select(0);
|
||||||
|
scroll = p_scroll_to_selected;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selected == p_node) {
|
if (selected == p_node) {
|
||||||
if (!editor_selection) {
|
if (!editor_selection) {
|
||||||
item->select(0);
|
item->select(0);
|
||||||
|
scroll = p_scroll_to_selected;
|
||||||
}
|
}
|
||||||
item->set_as_cursor(0);
|
item->set_as_cursor(0);
|
||||||
}
|
}
|
||||||
@@ -407,7 +411,7 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) {
|
|||||||
bool keep = (filter.is_subsequence_ofi(String(p_node->get_name())));
|
bool keep = (filter.is_subsequence_ofi(String(p_node->get_name())));
|
||||||
|
|
||||||
for (int i = 0; i < p_node->get_child_count(); i++) {
|
for (int i = 0; i < p_node->get_child_count(); i++) {
|
||||||
bool child_keep = _add_nodes(p_node->get_child(i), item);
|
bool child_keep = _add_nodes(p_node->get_child(i), item, p_scroll_to_selected);
|
||||||
|
|
||||||
keep = keep || child_keep;
|
keep = keep || child_keep;
|
||||||
}
|
}
|
||||||
@@ -438,6 +442,9 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) {
|
|||||||
memdelete(item);
|
memdelete(item);
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
if (scroll) {
|
||||||
|
tree->scroll_to_item(item);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -525,7 +532,7 @@ void SceneTreeEditor::_node_renamed(Node *p_node) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneTreeEditor::_update_tree() {
|
void SceneTreeEditor::_update_tree(bool p_scroll_to_selected) {
|
||||||
if (!is_inside_tree()) {
|
if (!is_inside_tree()) {
|
||||||
tree_dirty = false;
|
tree_dirty = false;
|
||||||
return;
|
return;
|
||||||
@@ -534,7 +541,7 @@ void SceneTreeEditor::_update_tree() {
|
|||||||
updating_tree = true;
|
updating_tree = true;
|
||||||
tree->clear();
|
tree->clear();
|
||||||
if (get_scene_node()) {
|
if (get_scene_node()) {
|
||||||
_add_nodes(get_scene_node(), nullptr);
|
_add_nodes(get_scene_node(), nullptr, p_scroll_to_selected);
|
||||||
last_hash = hash_djb2_one_64(0);
|
last_hash = hash_djb2_one_64(0);
|
||||||
_compute_hash(get_scene_node(), last_hash);
|
_compute_hash(get_scene_node(), last_hash);
|
||||||
}
|
}
|
||||||
@@ -817,7 +824,7 @@ void SceneTreeEditor::set_marked(Node *p_marked, bool p_selectable, bool p_child
|
|||||||
|
|
||||||
void SceneTreeEditor::set_filter(const String &p_filter) {
|
void SceneTreeEditor::set_filter(const String &p_filter) {
|
||||||
filter = p_filter;
|
filter = p_filter;
|
||||||
_update_tree();
|
_update_tree(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
String SceneTreeEditor::get_filter() const {
|
String SceneTreeEditor::get_filter() const {
|
||||||
|
|||||||
@@ -71,9 +71,9 @@ class SceneTreeEditor : public Control {
|
|||||||
|
|
||||||
void _compute_hash(Node *p_node, uint64_t &hash);
|
void _compute_hash(Node *p_node, uint64_t &hash);
|
||||||
|
|
||||||
bool _add_nodes(Node *p_node, TreeItem *p_parent);
|
bool _add_nodes(Node *p_node, TreeItem *p_parent, bool p_scroll_to_selected = false);
|
||||||
void _test_update_tree();
|
void _test_update_tree();
|
||||||
void _update_tree();
|
void _update_tree(bool p_scroll_to_selected = false);
|
||||||
void _tree_changed();
|
void _tree_changed();
|
||||||
void _node_removed(Node *p_node);
|
void _node_removed(Node *p_node);
|
||||||
void _node_renamed(Node *p_node);
|
void _node_renamed(Node *p_node);
|
||||||
|
|||||||
Reference in New Issue
Block a user