Skip to content

Commit

Permalink
Merge pull request #52984 from pycbouh/disable-freaky-subinspectors-3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga authored Sep 24, 2021
2 parents 792f95a + d3d7c29 commit 94f658a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
35 changes: 16 additions & 19 deletions editor/editor_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2237,7 +2237,7 @@ EditorPropertyRID::EditorPropertyRID() {
////////////// RESOURCE //////////////////////

void EditorPropertyResource::_resource_selected(const RES &p_resource) {
if (use_sub_inspector) {
if (_can_use_sub_inspector(p_resource)) {
bool unfold = !get_edited_object()->editor_is_section_unfolded(get_edited_property());
get_edited_object()->editor_set_section_unfold(get_edited_property(), unfold);
update_property();
Expand Down Expand Up @@ -2399,6 +2399,20 @@ void EditorPropertyResource::_viewport_selected(const NodePath &p_path) {
update_property();
}

bool EditorPropertyResource::_can_use_sub_inspector(const RES &p_resource) {
bool use_editor = false;
if (p_resource.is_valid()) {
for (int i = 0; i < EditorNode::get_editor_data().get_editor_plugin_count(); i++) {
EditorPlugin *ep = EditorNode::get_editor_data().get_editor_plugin(i);
if (ep->handles((Resource *)p_resource.ptr())) {
use_editor = true;
}
}
}

return !use_editor && use_sub_inspector;
}

void EditorPropertyResource::setup(Object *p_object, const String &p_path, const String &p_base_type) {
if (resource_picker) {
resource_picker->disconnect("resource_selected", this, "_resource_selected");
Expand Down Expand Up @@ -2433,7 +2447,7 @@ void EditorPropertyResource::setup(Object *p_object, const String &p_path, const
void EditorPropertyResource::update_property() {
RES res = get_edited_object()->get(get_edited_property());

if (use_sub_inspector) {
if (_can_use_sub_inspector(res)) {
if (res.is_valid() != resource_picker->is_toggle_mode()) {
resource_picker->set_toggle_mode(res.is_valid());
}
Expand Down Expand Up @@ -2462,23 +2476,6 @@ void EditorPropertyResource::update_property() {
sub_inspector_vbox->add_child(sub_inspector);
resource_picker->set_toggle_pressed(true);

bool use_editor = false;
for (int i = 0; i < EditorNode::get_editor_data().get_editor_plugin_count(); i++) {
EditorPlugin *ep = EditorNode::get_editor_data().get_editor_plugin(i);
if (ep->handles(res.ptr())) {
use_editor = true;
}
}

if (use_editor) {
// Open editor directly and hide other such editors which are currently open.
_open_editor_pressed();
if (is_inside_tree()) {
get_tree()->call_deferred("call_group", "_editor_resource_properties", "_fold_other_editors", this);
}
opened_editor = true;
}

_update_property_bg();
}

Expand Down
1 change: 1 addition & 0 deletions editor/editor_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ class EditorPropertyResource : public EditorProperty {
void _sub_inspector_resource_selected(const RES &p_resource, const String &p_property);
void _sub_inspector_object_id_selected(int p_id);

bool _can_use_sub_inspector(const RES &p_resource);
void _open_editor_pressed();
void _fold_other_editors(Object *p_self);
void _update_property_bg();
Expand Down

0 comments on commit 94f658a

Please sign in to comment.