Merge pull request #108551 from KoBeWi/paste_as_unique_norecursive

Improve Paste as Unique option
This commit is contained in:
Thaddeus Crews 2025-09-23 14:51:47 -05:00
commit b1b9a42517
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC

View file

@ -49,6 +49,17 @@
#include "scene/resources/gradient_texture.h"
#include "scene/resources/image_texture.h"
static bool _has_sub_resources(const Ref<Resource> &p_res) {
List<PropertyInfo> property_list;
p_res->get_property_list(&property_list);
for (const PropertyInfo &p : property_list) {
if (p.type == Variant::OBJECT && p.hint == PROPERTY_HINT_RESOURCE_TYPE && !(p.usage & PROPERTY_USAGE_NEVER_DUPLICATE) && p_res->get(p.name).get_validated_object()) {
return true;
}
}
return false;
}
void EditorResourcePicker::_update_resource() {
String resource_path;
if (edited_resource.is_valid() && edited_resource->get_path().is_resource_file()) {
@ -237,17 +248,7 @@ void EditorResourcePicker::_update_menu_items() {
}
edit_menu->add_icon_item(get_editor_theme_icon(SNAME("Duplicate")), TTR("Make Unique"), OBJ_MENU_MAKE_UNIQUE);
// Check whether the resource has subresources.
List<PropertyInfo> property_list;
edited_resource->get_property_list(&property_list);
bool has_subresources = false;
for (PropertyInfo &p : property_list) {
if ((p.type == Variant::OBJECT) && (p.hint == PROPERTY_HINT_RESOURCE_TYPE) && (p.name != "script") && ((Object *)edited_resource->get(p.name) != nullptr)) {
has_subresources = true;
break;
}
}
if (has_subresources) {
if (_has_sub_resources(edited_resource)) {
edit_menu->add_icon_item(get_editor_theme_icon(SNAME("Duplicate")), TTR("Make Unique (Recursive)"), OBJ_MENU_MAKE_UNIQUE_RECURSIVE);
}
@ -464,9 +465,13 @@ void EditorResourcePicker::_edit_menu_cbk(int p_which) {
case OBJ_MENU_PASTE_AS_UNIQUE: {
edited_resource = EditorSettings::get_singleton()->get_resource_clipboard();
// Use the recursive version when using Paste as Unique.
// This will show up a dialog to select which resources to make unique.
_edit_menu_cbk(OBJ_MENU_MAKE_UNIQUE_RECURSIVE);
if (_has_sub_resources(edited_resource)) {
// Use the recursive version when the Resource has sub-resources.
// This will show up a dialog to select which resources to make unique.
_edit_menu_cbk(OBJ_MENU_MAKE_UNIQUE_RECURSIVE);
} else {
_edit_menu_cbk(OBJ_MENU_MAKE_UNIQUE);
}
} break;
case OBJ_MENU_SHOW_IN_FILE_SYSTEM: {