mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
Merge pull request #108551 from KoBeWi/paste_as_unique_norecursive
Improve Paste as Unique option
This commit is contained in:
commit
b1b9a42517
1 changed files with 19 additions and 14 deletions
|
@ -49,6 +49,17 @@
|
||||||
#include "scene/resources/gradient_texture.h"
|
#include "scene/resources/gradient_texture.h"
|
||||||
#include "scene/resources/image_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() {
|
void EditorResourcePicker::_update_resource() {
|
||||||
String resource_path;
|
String resource_path;
|
||||||
if (edited_resource.is_valid() && edited_resource->get_path().is_resource_file()) {
|
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);
|
edit_menu->add_icon_item(get_editor_theme_icon(SNAME("Duplicate")), TTR("Make Unique"), OBJ_MENU_MAKE_UNIQUE);
|
||||||
|
|
||||||
// Check whether the resource has subresources.
|
if (_has_sub_resources(edited_resource)) {
|
||||||
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) {
|
|
||||||
edit_menu->add_icon_item(get_editor_theme_icon(SNAME("Duplicate")), TTR("Make Unique (Recursive)"), OBJ_MENU_MAKE_UNIQUE_RECURSIVE);
|
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: {
|
case OBJ_MENU_PASTE_AS_UNIQUE: {
|
||||||
edited_resource = EditorSettings::get_singleton()->get_resource_clipboard();
|
edited_resource = EditorSettings::get_singleton()->get_resource_clipboard();
|
||||||
// Use the recursive version when using Paste as Unique.
|
if (_has_sub_resources(edited_resource)) {
|
||||||
// This will show up a dialog to select which resources to make unique.
|
// Use the recursive version when the Resource has sub-resources.
|
||||||
_edit_menu_cbk(OBJ_MENU_MAKE_UNIQUE_RECURSIVE);
|
// 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;
|
} break;
|
||||||
|
|
||||||
case OBJ_MENU_SHOW_IN_FILE_SYSTEM: {
|
case OBJ_MENU_SHOW_IN_FILE_SYSTEM: {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue