Skip to content

Commit

Permalink
Create .uid file when creating new Resource
Browse files Browse the repository at this point in the history
  • Loading branch information
KoBeWi committed Nov 12, 2024
1 parent cb411fa commit 28e5b21
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
16 changes: 16 additions & 0 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions editor/editor_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,7 @@ class EditorNode : public Node {
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); }

Expand Down
1 change: 1 addition & 0 deletions editor/script_create_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions editor/shader_create_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -258,6 +260,7 @@ void fog() {
alert->popup_centered();
return;
}
EditorNode::get_singleton()->ensure_uid_file(lpath);
}

emit_signal(SNAME("shader_created"), shader);
Expand Down

0 comments on commit 28e5b21

Please sign in to comment.