summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkobewi <kobewi4e@gmail.com>2021-08-09 19:14:06 +0200
committerkobewi <kobewi4e@gmail.com>2021-08-12 00:36:56 +0200
commite401cd58f1e2fa296bf2920c2af7562fb344011c (patch)
tree2364b46f4fe7493ecbeb527a177c3a6f6bf8eb78
parent7188cb60127c1f4e900f080adbc47a55645f1645 (diff)
Add option to not expand tree on node select
-rw-r--r--editor/editor_settings.cpp1
-rw-r--r--editor/scene_tree_dock.cpp7
-rw-r--r--editor/scene_tree_dock.h1
-rw-r--r--editor/scene_tree_editor.cpp29
-rw-r--r--editor/scene_tree_editor.h2
5 files changed, 30 insertions, 10 deletions
diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp
index 16c2a0f028..b0ae541f8b 100644
--- a/editor/editor_settings.cpp
+++ b/editor/editor_settings.cpp
@@ -476,6 +476,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
// SceneTree
_initial_set("docks/scene_tree/start_create_dialog_fully_expanded", false);
+ _initial_set("docks/scene_tree/auto_expand_to_selected", true);
// FileSystem
_initial_set("docks/filesystem/thumbnail_size", 64);
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp
index 8994adf112..c9dbb9382a 100644
--- a/editor/scene_tree_dock.cpp
+++ b/editor/scene_tree_dock.cpp
@@ -975,6 +975,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
}
EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT);
} break;
+ case TOOL_AUTO_EXPAND: {
+ scene_tree->set_auto_expand_selected(!EditorSettings::get_singleton()->get("docks/scene_tree/auto_expand_to_selected"), true);
+ } break;
case TOOL_SCENE_EDITABLE_CHILDREN: {
if (!profile_allow_editing) {
break;
@@ -1286,12 +1289,14 @@ void SceneTreeDock::_notification(int p_what) {
case NOTIFICATION_ENTER_TREE: {
clear_inherit_confirm->connect("confirmed", callable_mp(this, &SceneTreeDock::_tool_selected), make_binds(TOOL_SCENE_CLEAR_INHERITANCE_CONFIRM, false));
+ scene_tree->set_auto_expand_selected(EditorSettings::get_singleton()->get("docks/scene_tree/auto_expand_to_selected"), false);
} break;
case NOTIFICATION_EXIT_TREE: {
clear_inherit_confirm->disconnect("confirmed", callable_mp(this, &SceneTreeDock::_tool_selected));
} break;
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
+ scene_tree->set_auto_expand_selected(EditorSettings::get_singleton()->get("docks/scene_tree/auto_expand_to_selected"), false);
button_add->set_icon(get_theme_icon(SNAME("Add"), SNAME("EditorIcons")));
button_instance->set_icon(get_theme_icon(SNAME("Instance"), SNAME("EditorIcons")));
button_create_script->set_icon(get_theme_icon(SNAME("ScriptCreate"), SNAME("EditorIcons")));
@@ -2813,6 +2818,8 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
}
menu->add_separator();
menu->add_icon_item(get_theme_icon(SNAME("Help"), SNAME("EditorIcons")), TTR("Open Documentation"), TOOL_OPEN_DOCUMENTATION);
+ menu->add_check_item(TTR("Auto Expand to Selected"), TOOL_AUTO_EXPAND);
+ menu->set_item_checked(menu->get_item_idx_from_text(TTR("Auto Expand to Selected")), EditorSettings::get_singleton()->get("docks/scene_tree/auto_expand_to_selected"));
if (profile_allow_editing) {
menu->add_separator();
diff --git a/editor/scene_tree_dock.h b/editor/scene_tree_dock.h
index ccdc0a3786..bd1ac2ff90 100644
--- a/editor/scene_tree_dock.h
+++ b/editor/scene_tree_dock.h
@@ -79,6 +79,7 @@ class SceneTreeDock : public VBoxContainer {
TOOL_COPY_NODE_PATH,
TOOL_BUTTON_MAX,
TOOL_OPEN_DOCUMENTATION,
+ TOOL_AUTO_EXPAND,
TOOL_SCENE_EDITABLE_CHILDREN,
TOOL_SCENE_USE_PLACEHOLDER,
TOOL_SCENE_MAKE_LOCAL,
diff --git a/editor/scene_tree_editor.cpp b/editor/scene_tree_editor.cpp
index 83b0203f32..1d6009b45a 100644
--- a/editor/scene_tree_editor.cpp
+++ b/editor/scene_tree_editor.cpp
@@ -735,17 +735,18 @@ void SceneTreeEditor::set_selected(Node *p_node, bool p_emit_selected) {
TreeItem *item = p_node ? _find(tree->get_root(), p_node->get_path()) : nullptr;
if (item) {
- // make visible when it's collapsed
- TreeItem *node = item->get_parent();
- while (node && node != tree->get_root()) {
- node->set_collapsed(false);
- node = node->get_parent();
+ if (auto_expand_selected) {
+ // Make visible when it's collapsed.
+ TreeItem *node = item->get_parent();
+ while (node && node != tree->get_root()) {
+ node->set_collapsed(false);
+ node = node->get_parent();
+ }
+ item->select(0);
+ item->set_as_cursor(0);
+ selected = p_node;
+ tree->ensure_cursor_is_visible();
}
- item->select(0);
- item->set_as_cursor(0);
- selected = p_node;
- tree->ensure_cursor_is_visible();
-
} else {
if (!p_node) {
selected = nullptr;
@@ -1125,11 +1126,19 @@ void SceneTreeEditor::_rmb_select(const Vector2 &p_pos) {
void SceneTreeEditor::update_warning() {
_warning_changed(nullptr);
}
+
void SceneTreeEditor::_warning_changed(Node *p_for_node) {
//should use a timer
update_timer->start();
}
+void SceneTreeEditor::set_auto_expand_selected(bool p_auto, bool p_update_settings) {
+ if (p_update_settings) {
+ EditorSettings::get_singleton()->set("docks/scene_tree/auto_expand_to_selected", p_auto);
+ }
+ auto_expand_selected = p_auto;
+}
+
void SceneTreeEditor::set_connect_to_script_mode(bool p_enable) {
connect_to_script_mode = p_enable;
update_tree();
diff --git a/editor/scene_tree_editor.h b/editor/scene_tree_editor.h
index acd49e8d92..4acd5d8486 100644
--- a/editor/scene_tree_editor.h
+++ b/editor/scene_tree_editor.h
@@ -64,6 +64,7 @@ class SceneTreeEditor : public Control {
AcceptDialog *error;
AcceptDialog *warning;
+ bool auto_expand_selected = true;
bool connect_to_script_mode;
bool connecting_signal;
@@ -152,6 +153,7 @@ public:
void update_tree() { _update_tree(); }
+ void set_auto_expand_selected(bool p_auto, bool p_update_settings);
void set_connect_to_script_mode(bool p_enable);
void set_connecting_signal(bool p_enable);