Browse Source

Create .uid file when creating new Resource

kobewi 10 months ago
parent
commit
28e5b213ae
4 changed files with 21 additions and 0 deletions
  1. 16 0
      editor/editor_node.cpp
  2. 1 0
      editor/editor_node.h
  3. 1 0
      editor/script_create_dialog.cpp
  4. 3 0
      editor/shader_create_dialog.cpp

+ 16 - 0
editor/editor_node.cpp

@@ -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;

+ 1 - 0
editor/editor_node.h

@@ -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); }
 

+ 1 - 0
editor/script_create_dialog.cpp

@@ -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);

+ 3 - 0
editor/shader_create_dialog.cpp

@@ -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);