Merge pull request #86705 from KoBeWi/resourception
Improve saving of built-in resources
This commit is contained in:
commit
16bdd83ea4
5 changed files with 45 additions and 2 deletions
|
@ -1285,7 +1285,14 @@ void EditorNode::save_resource(const Ref<Resource> &p_resource) {
|
||||||
if (p_resource->is_built_in()) {
|
if (p_resource->is_built_in()) {
|
||||||
const String scene_path = p_resource->get_path().get_slice("::", 0);
|
const String scene_path = p_resource->get_path().get_slice("::", 0);
|
||||||
if (!scene_path.is_empty()) {
|
if (!scene_path.is_empty()) {
|
||||||
save_scene_if_open(scene_path);
|
if (ResourceLoader::exists(scene_path) && ResourceLoader::get_resource_type(scene_path) == "PackedScene") {
|
||||||
|
save_scene_if_open(scene_path);
|
||||||
|
} else {
|
||||||
|
// Not a packed scene, so save it as regular resource.
|
||||||
|
Ref<Resource> parent_resource = ResourceCache::get_ref(scene_path);
|
||||||
|
ERR_FAIL_COND_MSG(parent_resource.is_null(), "Parent resource not loaded, can't save.");
|
||||||
|
save_resource(parent_resource);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1001,6 +1001,11 @@ void ScriptEditor::_res_saved_callback(const Ref<Resource> &p_res) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (p_res.is_valid()) {
|
||||||
|
// In case the Resource has built-in scripts.
|
||||||
|
_mark_built_in_scripts_as_saved(p_res->get_path());
|
||||||
|
}
|
||||||
|
|
||||||
_update_script_names();
|
_update_script_names();
|
||||||
Ref<Script> scr = p_res;
|
Ref<Script> scr = p_res;
|
||||||
if (scr.is_valid()) {
|
if (scr.is_valid()) {
|
||||||
|
@ -1010,6 +1015,10 @@ void ScriptEditor::_res_saved_callback(const Ref<Resource> &p_res) {
|
||||||
|
|
||||||
void ScriptEditor::_scene_saved_callback(const String &p_path) {
|
void ScriptEditor::_scene_saved_callback(const String &p_path) {
|
||||||
// If scene was saved, mark all built-in scripts from that scene as saved.
|
// If scene was saved, mark all built-in scripts from that scene as saved.
|
||||||
|
_mark_built_in_scripts_as_saved(p_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptEditor::_mark_built_in_scripts_as_saved(const String &p_parent_path) {
|
||||||
for (int i = 0; i < tab_container->get_tab_count(); i++) {
|
for (int i = 0; i < tab_container->get_tab_count(); i++) {
|
||||||
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_tab_control(i));
|
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_tab_control(i));
|
||||||
if (!se) {
|
if (!se) {
|
||||||
|
@ -1022,7 +1031,7 @@ void ScriptEditor::_scene_saved_callback(const String &p_path) {
|
||||||
continue; // External script, who cares.
|
continue; // External script, who cares.
|
||||||
}
|
}
|
||||||
|
|
||||||
if (edited_res->get_path().get_slice("::", 0) == p_path) {
|
if (edited_res->get_path().get_slice("::", 0) == p_parent_path) {
|
||||||
se->tag_saved_version();
|
se->tag_saved_version();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -401,6 +401,7 @@ class ScriptEditor : public PanelContainer {
|
||||||
void _add_callback(Object *p_obj, const String &p_function, const PackedStringArray &p_args);
|
void _add_callback(Object *p_obj, const String &p_function, const PackedStringArray &p_args);
|
||||||
void _res_saved_callback(const Ref<Resource> &p_res);
|
void _res_saved_callback(const Ref<Resource> &p_res);
|
||||||
void _scene_saved_callback(const String &p_path);
|
void _scene_saved_callback(const String &p_path);
|
||||||
|
void _mark_built_in_scripts_as_saved(const String &p_parent_path);
|
||||||
|
|
||||||
bool open_textfile_after_create = true;
|
bool open_textfile_after_create = true;
|
||||||
bool trim_trailing_whitespace_on_save;
|
bool trim_trailing_whitespace_on_save;
|
||||||
|
|
|
@ -625,12 +625,37 @@ void ShaderEditorPlugin::_file_removed(const String &p_removed_file) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ShaderEditorPlugin::_res_saved_callback(const Ref<Resource> &p_res) {
|
||||||
|
if (p_res.is_null()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const String &path = p_res->get_path();
|
||||||
|
|
||||||
|
for (EditedShader &edited : edited_shaders) {
|
||||||
|
Ref<Resource> shader_res = edited.shader;
|
||||||
|
if (shader_res.is_null()) {
|
||||||
|
shader_res = edited.shader_inc;
|
||||||
|
}
|
||||||
|
ERR_FAIL_COND(shader_res.is_null());
|
||||||
|
|
||||||
|
if (!edited.shader_editor || !shader_res->is_built_in()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shader_res->get_path().get_slice("::", 0) == path) {
|
||||||
|
edited.shader_editor->tag_saved_version();
|
||||||
|
_update_shader_list();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ShaderEditorPlugin::_notification(int p_what) {
|
void ShaderEditorPlugin::_notification(int p_what) {
|
||||||
switch (p_what) {
|
switch (p_what) {
|
||||||
case NOTIFICATION_READY: {
|
case NOTIFICATION_READY: {
|
||||||
EditorNode::get_singleton()->connect("resource_saved", callable_mp(this, &ShaderEditorPlugin::_resource_saved), CONNECT_DEFERRED);
|
EditorNode::get_singleton()->connect("resource_saved", callable_mp(this, &ShaderEditorPlugin::_resource_saved), CONNECT_DEFERRED);
|
||||||
EditorNode::get_singleton()->connect("scene_closed", callable_mp(this, &ShaderEditorPlugin::_close_builtin_shaders_from_scene));
|
EditorNode::get_singleton()->connect("scene_closed", callable_mp(this, &ShaderEditorPlugin::_close_builtin_shaders_from_scene));
|
||||||
FileSystemDock::get_singleton()->connect("file_removed", callable_mp(this, &ShaderEditorPlugin::_file_removed));
|
FileSystemDock::get_singleton()->connect("file_removed", callable_mp(this, &ShaderEditorPlugin::_file_removed));
|
||||||
|
EditorNode::get_singleton()->connect("resource_saved", callable_mp(this, &ShaderEditorPlugin::_res_saved_callback));
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,6 +96,7 @@ class ShaderEditorPlugin : public EditorPlugin {
|
||||||
void _close_shader(int p_index);
|
void _close_shader(int p_index);
|
||||||
void _close_builtin_shaders_from_scene(const String &p_scene);
|
void _close_builtin_shaders_from_scene(const String &p_scene);
|
||||||
void _file_removed(const String &p_removed_file);
|
void _file_removed(const String &p_removed_file);
|
||||||
|
void _res_saved_callback(const Ref<Resource> &p_res);
|
||||||
|
|
||||||
void _shader_created(Ref<Shader> p_shader);
|
void _shader_created(Ref<Shader> p_shader);
|
||||||
void _shader_include_created(Ref<ShaderInclude> p_shader_inc);
|
void _shader_include_created(Ref<ShaderInclude> p_shader_inc);
|
||||||
|
|
Loading…
Reference in a new issue