Merge pull request #99147 from KoBeWi/conjure_uid

Create .uid file when creating new Resource
This commit is contained in:
Thaddeus Crews 2024-11-13 08:34:20 -06:00
commit 7cfd762009
No known key found for this signature in database
GPG Key ID: 62181B86FE9E5D84
4 changed files with 21 additions and 0 deletions

View File

@ -1454,6 +1454,16 @@ void EditorNode::save_resource_as(const Ref<Resource> &p_resource, const String
file->popup_file_dialog();
}
void EditorNode::ensure_uid_file(const String &p_new_resource_path) {
if (ResourceLoader::exists(p_new_resource_path) && !ResourceLoader::has_custom_uid_support(p_new_resource_path) && !FileAccess::exists(p_new_resource_path + ".uid")) {
Ref<FileAccess> f = FileAccess::open(p_new_resource_path + ".uid", FileAccess::WRITE);
if (f.is_valid()) {
const ResourceUID::ID id = ResourceUID::get_singleton()->create_id();
f->store_line(ResourceUID::get_singleton()->id_to_text(id));
}
}
}
void EditorNode::_menu_option(int p_option) {
_menu_option_confirm(p_option, false);
}
@ -2173,6 +2183,12 @@ void EditorNode::_dialog_action(String p_file) {
case RESOURCE_SAVE_AS: {
ERR_FAIL_COND(saving_resource.is_null());
save_resource_in_path(saving_resource, p_file);
if (current_menu_option == RESOURCE_SAVE_AS) {
// Create .uid file when making new Resource.
ensure_uid_file(p_file);
}
saving_resource = Ref<Resource>();
ObjectID current_id = editor_history.get_current();
Object *current_obj = current_id.is_valid() ? ObjectDB::get_instance(current_id) : nullptr;

View File

@ -747,6 +747,7 @@ public:
void save_resource_in_path(const Ref<Resource> &p_resource, const String &p_path);
void save_resource(const Ref<Resource> &p_resource);
void save_resource_as(const Ref<Resource> &p_resource, const String &p_at_path = String());
void ensure_uid_file(const String &p_new_resource_path);
void show_about() { _menu_option_confirm(HELP_ABOUT, false); }

View File

@ -359,6 +359,7 @@ void ScriptCreateDialog::_create_new() {
alert->popup_centered();
return;
}
EditorNode::get_singleton()->ensure_uid_file(lpath);
}
emit_signal(SNAME("script_created"), scr);

View File

@ -31,6 +31,7 @@
#include "shader_create_dialog.h"
#include "core/config/project_settings.h"
#include "editor/editor_node.h"
#include "editor/gui/editor_file_dialog.h"
#include "editor/gui/editor_validation_panel.h"
#include "editor/themes/editor_scale.h"
@ -240,6 +241,7 @@ void fog() {
alert->popup_centered();
return;
}
EditorNode::get_singleton()->ensure_uid_file(lpath);
emit_signal(SNAME("shader_include_created"), shader_inc);
} else {
@ -258,6 +260,7 @@ void fog() {
alert->popup_centered();
return;
}
EditorNode::get_singleton()->ensure_uid_file(lpath);
}
emit_signal(SNAME("shader_created"), shader);