Create .uid file when creating new Resource

This commit is contained in:
kobewi 2024-11-12 22:17:17 +01:00
parent cb411fa960
commit 28e5b213ae
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(); 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) { void EditorNode::_menu_option(int p_option) {
_menu_option_confirm(p_option, false); _menu_option_confirm(p_option, false);
} }
@ -2173,6 +2183,12 @@ void EditorNode::_dialog_action(String p_file) {
case RESOURCE_SAVE_AS: { case RESOURCE_SAVE_AS: {
ERR_FAIL_COND(saving_resource.is_null()); ERR_FAIL_COND(saving_resource.is_null());
save_resource_in_path(saving_resource, p_file); 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>(); saving_resource = Ref<Resource>();
ObjectID current_id = editor_history.get_current(); ObjectID current_id = editor_history.get_current();
Object *current_obj = current_id.is_valid() ? ObjectDB::get_instance(current_id) : nullptr; 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_in_path(const Ref<Resource> &p_resource, const String &p_path);
void save_resource(const Ref<Resource> &p_resource); void save_resource(const Ref<Resource> &p_resource);
void save_resource_as(const Ref<Resource> &p_resource, const String &p_at_path = String()); 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); } void show_about() { _menu_option_confirm(HELP_ABOUT, false); }

View File

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

View File

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