diff options
Diffstat (limited to 'editor/editor_inspector.cpp')
-rw-r--r-- | editor/editor_inspector.cpp | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 275e47e370..36462f6805 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -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; } @@ -693,7 +705,7 @@ void EditorProperty::gui_input(const Ref<InputEvent> &p_event) { bool is_valid_revert = false; Variant revert_value = EditorPropertyRevert::get_property_revert_value(object, property, &is_valid_revert); ERR_FAIL_COND(!is_valid_revert); - emit_changed(property, revert_value); + emit_changed(_get_revert_property(), revert_value); update_property(); } @@ -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; } @@ -2566,12 +2582,13 @@ bool EditorInspector::_is_property_disabled_by_feature_profile(const StringName } void EditorInspector::update_tree() { - //to update properly if all is refreshed + // Store currently selected and focused elements to restore after the update. + // TODO: Can be useful to store more context for the focusable, such as the caret position in LineEdit. StringName current_selected = property_selected; int current_focusable = -1; if (property_focusable != -1) { - //check focusable is really focusable + // Check that focusable is actually focusable. bool restore_focus = false; Control *focused = get_viewport() ? get_viewport()->gui_get_focus_owner() : nullptr; if (focused) { @@ -2579,8 +2596,8 @@ void EditorInspector::update_tree() { while (parent) { EditorInspector *inspector = Object::cast_to<EditorInspector>(parent); if (inspector) { - restore_focus = inspector == this; //may be owned by another inspector - break; //exit after the first inspector is found, since there may be nested ones + restore_focus = inspector == this; // May be owned by another inspector. + break; // Exit after the first inspector is found, since there may be nested ones. } parent = parent->get_parent(); } @@ -2591,7 +2608,9 @@ void EditorInspector::update_tree() { } } - _clear(); + // Only hide plugins if we are not editing any object. + // This should be handled outside of the update_tree call anyway (see EditorInspector::edit), but might as well keep it safe. + _clear(!object); if (!object) { return; @@ -3283,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(); } @@ -3301,17 +3320,19 @@ void EditorInspector::update_property(const String &p_prop) { } } -void EditorInspector::_clear() { +void EditorInspector::_clear(bool p_hide_plugins) { while (main_vbox->get_child_count()) { memdelete(main_vbox->get_child(0)); } + property_selected = StringName(); property_focusable = -1; editor_property_map.clear(); sections.clear(); pending.clear(); restart_request_props.clear(); - if (_is_main_editor_inspector()) { + + if (p_hide_plugins && is_main_editor_inspector()) { EditorNode::get_singleton()->hide_unused_editors(this); } } @@ -3405,7 +3426,6 @@ void EditorInspector::register_text_enter(Node *p_line_edit) { } void EditorInspector::_filter_changed(const String &p_text) { - _clear(); update_tree(); } @@ -3648,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. |