Skip to content

Commit

Permalink
Automatically expand a resource after creating it in the inspector
Browse files Browse the repository at this point in the history
This reduces the number of mouse clicks needed to set up various nodes,
such as MeshInstance3D and GPUParticles3D.

This is only effective if Open Resources in Current Inspector is enabled
in the editor settings (which is the default).
  • Loading branch information
Calinou committed Nov 26, 2024
1 parent bbc5469 commit faae486
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
7 changes: 5 additions & 2 deletions editor/editor_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2974,7 +2974,7 @@ void EditorPropertyResource::_set_read_only(bool p_read_only) {
resource_picker->set_editable(!p_read_only);
}

void EditorPropertyResource::_resource_selected(const Ref<Resource> &p_resource, bool p_inspect) {
void EditorPropertyResource::_resource_selected(const Ref<Resource> &p_resource, bool p_inspect, bool p_force_open) {
if (p_resource->is_built_in() && !p_resource->get_path().is_empty()) {
String parent = p_resource->get_path().get_slice("::", 0);
List<String> extensions;
Expand All @@ -2992,7 +2992,10 @@ void EditorPropertyResource::_resource_selected(const Ref<Resource> &p_resource,
}

if (!p_inspect && use_sub_inspector) {
bool unfold = !get_edited_object()->editor_is_section_unfolded(get_edited_property());
bool unfold = p_force_open;
if (!unfold) {
unfold = !get_edited_object()->editor_is_section_unfolded(get_edited_property());
}
get_edited_object()->editor_set_section_unfold(get_edited_property(), unfold);
update_property();
} else {
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ class EditorPropertyResource : public EditorProperty {
EditorInspector *sub_inspector = nullptr;
bool opened_editor = false;

void _resource_selected(const Ref<Resource> &p_resource, bool p_inspect);
void _resource_selected(const Ref<Resource> &p_resource, bool p_inspect, bool p_force_open = false);
void _resource_changed(const Ref<Resource> &p_resource);

void _viewport_selected(const NodePath &p_path);
Expand Down
12 changes: 9 additions & 3 deletions editor/editor_resource_picker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void EditorResourcePicker::_resource_selected() {
return;
}

emit_signal(SNAME("resource_selected"), edited_resource, false);
emit_signal(SNAME("resource_selected"), edited_resource, false, false);
}

void EditorResourcePicker::_resource_changed() {
Expand Down Expand Up @@ -353,7 +353,7 @@ void EditorResourcePicker::_edit_menu_cbk(int p_which) {

case OBJ_MENU_INSPECT: {
if (edited_resource.is_valid()) {
emit_signal(SNAME("resource_selected"), edited_resource, true);
emit_signal(SNAME("resource_selected"), edited_resource, true, true);
}
} break;

Expand Down Expand Up @@ -483,6 +483,12 @@ void EditorResourcePicker::_edit_menu_cbk(int p_which) {
Ref<Resource> old_edited_resource = edited_resource;
edited_resource = Ref<Resource>(resp);
_resource_changed();

if (edited_resource.is_valid() && bool(EDITOR_GET("interface/inspector/open_resources_in_current_inspector"))) {
// Expand newly created resources, as the user will most likely want to change at least one property within the resource.
// This is disabled when resources are forcibly opened in a new inspector, as it would be too intrusive.
emit_signal(SNAME("resource_selected"), edited_resource, false, true);
}
} break;
}
}
Expand Down Expand Up @@ -814,7 +820,7 @@ void EditorResourcePicker::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editable"), "set_editable", "is_editable");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "toggle_mode"), "set_toggle_mode", "is_toggle_mode");

ADD_SIGNAL(MethodInfo("resource_selected", PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource"), PropertyInfo(Variant::BOOL, "inspect")));
ADD_SIGNAL(MethodInfo("resource_selected", PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource"), PropertyInfo(Variant::BOOL, "inspect"), PropertyInfo(Variant::BOOL, "force_open")));
ADD_SIGNAL(MethodInfo("resource_changed", PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource")));
}

Expand Down

0 comments on commit faae486

Please sign in to comment.