Fold resources when non-main inspector exits tree

This commit is contained in:
kobewi 2023-02-15 18:03:12 +01:00
parent f2aae8fa5c
commit 7aa3651e2b
3 changed files with 28 additions and 7 deletions

View file

@ -414,6 +414,18 @@ StringName EditorProperty::get_edited_property() const {
return property;
}
EditorInspector *EditorProperty::get_parent_inspector() const {
Node *parent = get_parent();
while (parent) {
EditorInspector *ei = Object::cast_to<EditorInspector>(parent);
if (ei) {
return ei;
}
parent = parent->get_parent();
}
ERR_FAIL_V_MSG(nullptr, "EditorProperty is outside inspector.");
}
void EditorProperty::set_doc_path(const String &p_doc_path) {
doc_path = p_doc_path;
}
@ -2484,6 +2496,10 @@ Button *EditorInspector::create_inspector_action_button(const String &p_text) {
return button;
}
bool EditorInspector::is_main_editor_inspector() const {
return InspectorDock::get_singleton() && InspectorDock::get_inspector_singleton() == this;
}
String EditorInspector::get_selected_path() const {
return property_selected;
}
@ -3286,7 +3302,7 @@ void EditorInspector::update_tree() {
_parse_added_editors(main_vbox, nullptr, ped);
}
if (_is_main_editor_inspector()) {
if (is_main_editor_inspector()) {
// Updating inspector might invalidate some editing owners.
EditorNode::get_singleton()->hide_unused_editors();
}
@ -3316,7 +3332,7 @@ void EditorInspector::_clear(bool p_hide_plugins) {
pending.clear();
restart_request_props.clear();
if (p_hide_plugins && _is_main_editor_inspector()) {
if (p_hide_plugins && is_main_editor_inspector()) {
EditorNode::get_singleton()->hide_unused_editors(this);
}
}
@ -3652,10 +3668,6 @@ void EditorInspector::_edit_set(const String &p_name, const Variant &p_value, bo
}
}
bool EditorInspector::_is_main_editor_inspector() const {
return InspectorDock::get_singleton() && InspectorDock::get_inspector_singleton() == this;
}
void EditorInspector::_property_changed(const String &p_path, const Variant &p_value, const String &p_name, bool p_changing, bool p_update_all) {
// The "changing" variable must be true for properties that trigger events as typing occurs,
// like "text_changed" signal. E.g. text property of Label, Button, RichTextLabel, etc.

View file

@ -38,6 +38,7 @@
class AcceptDialog;
class Button;
class ConfirmationDialog;
class EditorInspector;
class LineEdit;
class OptionButton;
class PanelContainer;
@ -147,6 +148,7 @@ public:
Object *get_edited_object();
StringName get_edited_property() const;
EditorInspector *get_parent_inspector() const;
void set_doc_path(const String &p_doc_path);
@ -498,7 +500,6 @@ class EditorInspector : public ScrollContainer {
bool restrict_to_basic = false;
void _edit_set(const String &p_name, const Variant &p_value, bool p_refresh_all, const String &p_changed_field);
bool _is_main_editor_inspector() const;
void _property_changed(const String &p_path, const Variant &p_value, const String &p_name = "", bool p_changing = false, bool p_update_all = false);
void _multiple_properties_changed(Vector<String> p_paths, Array p_values, bool p_changing = false);
@ -552,6 +553,7 @@ public:
static EditorProperty *instantiate_property_editor(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide = false);
bool is_main_editor_inspector() const;
String get_selected_path() const;
void update_tree();

View file

@ -4141,6 +4141,13 @@ void EditorPropertyResource::_notification(int p_what) {
_update_property_bg();
}
} break;
case NOTIFICATION_EXIT_TREE: {
const EditorInspector *ei = get_parent_inspector();
if (ei && !ei->is_main_editor_inspector()) {
fold_resource();
}
} break;
}
}