Add option to not expand tree on node select

This commit is contained in:
kobewi 2021-08-09 19:14:06 +02:00
parent 7188cb6012
commit e401cd58f1
5 changed files with 30 additions and 10 deletions

View file

@ -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);

View file

@ -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();

View file

@ -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,

View file

@ -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();

View file

@ -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);