diff options
-rw-r--r-- | editor/plugins/script_editor_plugin.cpp | 30 | ||||
-rw-r--r-- | editor/plugins/script_editor_plugin.h | 2 | ||||
-rw-r--r-- | editor/plugins/shader_editor_plugin.cpp | 16 | ||||
-rw-r--r-- | editor/plugins/shader_editor_plugin.h | 1 |
4 files changed, 49 insertions, 0 deletions
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 791937dbf6..5a65bc6c04 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -2435,6 +2435,18 @@ bool ScriptEditor::edit(const Ref<Resource> &p_resource, int p_line, int p_col, return true; } +PackedStringArray ScriptEditor::get_unsaved_scripts() const { + PackedStringArray unsaved_list; + + for (int i = 0; i < tab_container->get_tab_count(); i++) { + ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_tab_control(i)); + if (se->is_unsaved()) { + unsaved_list.append(se->get_name()); + } + } + return unsaved_list; +} + void ScriptEditor::save_current_script() { ScriptEditorBase *current = _get_current_editor(); if (!current || _test_script_times_on_disk()) { @@ -4207,6 +4219,24 @@ void ScriptEditorPlugin::selected_notify() { _focus_another_editor(); } +String ScriptEditorPlugin::get_unsaved_status() const { + const PackedStringArray unsaved_scripts = script_editor->get_unsaved_scripts(); + if (unsaved_scripts.is_empty()) { + return String(); + } + + PackedStringArray message; + message.resize(unsaved_scripts.size() + 1); + message.write[0] = "Save changes to the following script(s) before quitting?"; + + int i = 1; + for (const String &E : unsaved_scripts) { + message.write[i] = E.trim_suffix("(*)"); + i++; + } + return String("\n").join(message); +} + void ScriptEditorPlugin::save_external_data() { script_editor->save_all_scripts(); } diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h index e879920e41..873d8c2e5b 100644 --- a/editor/plugins/script_editor_plugin.h +++ b/editor/plugins/script_editor_plugin.h @@ -512,6 +512,7 @@ public: void get_breakpoints(List<String> *p_breakpoints); + PackedStringArray get_unsaved_scripts() const; void save_current_script(); void save_all_scripts(); @@ -572,6 +573,7 @@ public: virtual void make_visible(bool p_visible) override; virtual void selected_notify() override; + virtual String get_unsaved_status() const override; virtual void save_external_data() override; virtual void apply_changes() override; diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp index 268828e8f5..89eb6e88a3 100644 --- a/editor/plugins/shader_editor_plugin.cpp +++ b/editor/plugins/shader_editor_plugin.cpp @@ -287,6 +287,22 @@ void ShaderEditorPlugin::get_window_layout(Ref<ConfigFile> p_layout) { p_layout->set_value("ShaderEditor", "selected_shader", selected_shader); } +String ShaderEditorPlugin::get_unsaved_status() const { + // TODO: This should also include visual shaders and shader includes, but save_external_data() doesn't seem to save them... + PackedStringArray unsaved_shaders; + for (uint32_t i = 0; i < edited_shaders.size(); i++) { + if (edited_shaders[i].shader_editor) { + if (edited_shaders[i].shader_editor->is_unsaved()) { + if (unsaved_shaders.is_empty()) { + unsaved_shaders.append("Save changes to the following shaders(s) before quitting?"); + } + unsaved_shaders.append(edited_shaders[i].shader_editor->get_name()); + } + } + } + return String("\n").join(unsaved_shaders); +} + void ShaderEditorPlugin::save_external_data() { for (EditedShader &edited_shader : edited_shaders) { if (edited_shader.shader_editor) { diff --git a/editor/plugins/shader_editor_plugin.h b/editor/plugins/shader_editor_plugin.h index 45b48a2f91..6f206d8504 100644 --- a/editor/plugins/shader_editor_plugin.h +++ b/editor/plugins/shader_editor_plugin.h @@ -115,6 +115,7 @@ public: virtual void set_window_layout(Ref<ConfigFile> p_layout) override; virtual void get_window_layout(Ref<ConfigFile> p_layout) override; + virtual String get_unsaved_status() const override; virtual void save_external_data() override; virtual void apply_changes() override; |