From 19b998396c5caefe3beda9cb81337c5c7159519c Mon Sep 17 00:00:00 2001 From: kobewi Date: Sun, 9 Apr 2023 20:43:55 +0200 Subject: Close built-in shaders when closing scene (cherry picked from commit aaf02ec04a8ef053a359bc2f4cc3f1747448a4a3) --- editor/editor_data.cpp | 2 +- editor/editor_node.cpp | 1 + editor/plugins/script_editor_plugin.cpp | 7 +++++-- editor/plugins/script_editor_plugin.h | 3 +-- editor/plugins/shader_editor_plugin.cpp | 28 ++++++++++++++++++++++++++++ editor/plugins/shader_editor_plugin.h | 4 ++++ 6 files changed, 40 insertions(+), 5 deletions(-) (limited to 'editor') diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp index 9bdd39f684..7eb539333b 100644 --- a/editor/editor_data.cpp +++ b/editor/editor_data.cpp @@ -595,7 +595,7 @@ void EditorData::remove_scene(int p_idx) { } if (!edited_scene[p_idx].path.is_empty()) { - ScriptEditor::get_singleton()->close_builtin_scripts_from_scene(edited_scene[p_idx].path); + EditorNode::get_singleton()->emit_signal("scene_closed", edited_scene[p_idx].path); } undo_redo_manager->discard_history(edited_scene[p_idx].history_id); diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 87ca642be5..54494b63df 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -6617,6 +6617,7 @@ void EditorNode::_bind_methods() { ADD_SIGNAL(MethodInfo("scene_saved", PropertyInfo(Variant::STRING, "path"))); ADD_SIGNAL(MethodInfo("project_settings_changed")); ADD_SIGNAL(MethodInfo("scene_changed")); + ADD_SIGNAL(MethodInfo("scene_closed", PropertyInfo(Variant::STRING, "path"))); } static Node *_resource_get_edited_scene() { diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 46218869b3..ef86fd2a4c 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -1643,6 +1643,7 @@ void ScriptEditor::_notification(int p_what) { get_tree()->connect("tree_changed", callable_mp(this, &ScriptEditor::_tree_changed)); InspectorDock::get_singleton()->connect("request_help", callable_mp(this, &ScriptEditor::_help_class_open)); EditorNode::get_singleton()->connect("request_help_search", callable_mp(this, &ScriptEditor::_help_search)); + EditorNode::get_singleton()->connect("scene_closed", callable_mp(this, &ScriptEditor::_close_builtin_scripts_from_scene)); } break; case NOTIFICATION_EXIT_TREE: { @@ -1677,7 +1678,7 @@ bool ScriptEditor::can_take_away_focus() const { } } -void ScriptEditor::close_builtin_scripts_from_scene(const String &p_scene) { +void ScriptEditor::_close_builtin_scripts_from_scene(const String &p_scene) { for (int i = 0; i < tab_container->get_tab_count(); i++) { ScriptEditorBase *se = Object::cast_to(tab_container->get_tab_control(i)); @@ -1687,7 +1688,7 @@ void ScriptEditor::close_builtin_scripts_from_scene(const String &p_scene) { continue; } - if (scr->is_built_in() && scr->get_path().begins_with(p_scene)) { //is an internal script and belongs to scene being closed + if (scr->is_built_in() && scr->get_path().begins_with(p_scene)) { // Is an internal script and belongs to scene being closed. _close_tab(i, false); i--; } @@ -4089,6 +4090,8 @@ ScriptEditor::ScriptEditor() { Ref json_syntax_highlighter; json_syntax_highlighter.instantiate(); register_syntax_highlighter(json_syntax_highlighter); + + EditorNode::get_singleton()->connect("scene_closed", callable_mp(this, &ScriptEditor::_close_builtin_scripts_from_scene)); } ScriptEditor::~ScriptEditor() { diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h index 7d2f5ad22a..10dfe0f199 100644 --- a/editor/plugins/script_editor_plugin.h +++ b/editor/plugins/script_editor_plugin.h @@ -482,6 +482,7 @@ class ScriptEditor : public PanelContainer { void _on_find_in_files_modified_files(PackedStringArray paths); static void _open_script_request(const String &p_path); + void _close_builtin_scripts_from_scene(const String &p_scene); static ScriptEditor *script_editor; @@ -523,8 +524,6 @@ public: void notify_script_close(const Ref