summaryrefslogtreecommitdiffstats
path: root/editor/plugins
diff options
context:
space:
mode:
authorkobewi <kobewi4e@gmail.com>2023-04-05 15:45:41 +0200
committerkobewi <kobewi4e@gmail.com>2023-07-18 14:27:56 +0200
commitb883f3218895ba1992601b1721667823a99bca62 (patch)
tree9d87aa9d6789b3f85d60f5495810cf9526ccebbb /editor/plugins
parent000471ee5691fa6f6a212944084d3aa434acc5b8 (diff)
downloadredot-engine-b883f3218895ba1992601b1721667823a99bca62.tar.gz
Check for unsaved changes when closing a scene
Diffstat (limited to 'editor/plugins')
-rw-r--r--editor/plugins/script_editor_plugin.cpp31
-rw-r--r--editor/plugins/script_editor_plugin.h2
-rw-r--r--editor/plugins/shader_editor_plugin.cpp9
-rw-r--r--editor/plugins/shader_editor_plugin.h2
4 files changed, 37 insertions, 7 deletions
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp
index 5a65bc6c04..875ad1b96d 100644
--- a/editor/plugins/script_editor_plugin.cpp
+++ b/editor/plugins/script_editor_plugin.cpp
@@ -2440,7 +2440,7 @@ PackedStringArray ScriptEditor::get_unsaved_scripts() const {
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()) {
+ if (se && se->is_unsaved()) {
unsaved_list.append(se->get_name());
}
}
@@ -4219,15 +4219,40 @@ void ScriptEditorPlugin::selected_notify() {
_focus_another_editor();
}
-String ScriptEditorPlugin::get_unsaved_status() const {
+String ScriptEditorPlugin::get_unsaved_status(const String &p_for_scene) const {
const PackedStringArray unsaved_scripts = script_editor->get_unsaved_scripts();
if (unsaved_scripts.is_empty()) {
return String();
}
PackedStringArray message;
+ if (!p_for_scene.is_empty()) {
+ PackedStringArray unsaved_built_in_scripts;
+
+ const String scene_file = p_for_scene.get_file();
+ for (const String &E : unsaved_scripts) {
+ if (!E.is_resource_file() && E.contains(scene_file)) {
+ unsaved_built_in_scripts.append(E);
+ }
+ }
+
+ if (unsaved_built_in_scripts.is_empty()) {
+ return String();
+ } else {
+ message.resize(unsaved_built_in_scripts.size() + 1);
+ message.write[0] = TTR("There are unsaved changes in the following built-in script(s):");
+
+ int i = 1;
+ for (const String &E : unsaved_built_in_scripts) {
+ message.write[i] = E.trim_suffix("(*)");
+ i++;
+ }
+ return String("\n").join(message);
+ }
+ }
+
message.resize(unsaved_scripts.size() + 1);
- message.write[0] = "Save changes to the following script(s) before quitting?";
+ message.write[0] = TTR("Save changes to the following script(s) before quitting?");
int i = 1;
for (const String &E : unsaved_scripts) {
diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h
index 873d8c2e5b..198aaa6c4e 100644
--- a/editor/plugins/script_editor_plugin.h
+++ b/editor/plugins/script_editor_plugin.h
@@ -573,7 +573,7 @@ public:
virtual void make_visible(bool p_visible) override;
virtual void selected_notify() override;
- virtual String get_unsaved_status() const override;
+ virtual String get_unsaved_status(const String &p_for_scene) 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 89eb6e88a3..247586fbfc 100644
--- a/editor/plugins/shader_editor_plugin.cpp
+++ b/editor/plugins/shader_editor_plugin.cpp
@@ -287,14 +287,19 @@ void ShaderEditorPlugin::get_window_layout(Ref<ConfigFile> p_layout) {
p_layout->set_value("ShaderEditor", "selected_shader", selected_shader);
}
-String ShaderEditorPlugin::get_unsaved_status() const {
+String ShaderEditorPlugin::get_unsaved_status(const String &p_for_scene) const {
+ if (!p_for_scene.is_empty()) {
+ // TODO: handle built-in shaders.
+ return String();
+ }
+
// 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(TTR("Save changes to the following shaders(s) before quitting?"));
}
unsaved_shaders.append(edited_shaders[i].shader_editor->get_name());
}
diff --git a/editor/plugins/shader_editor_plugin.h b/editor/plugins/shader_editor_plugin.h
index 6f206d8504..fb7b283266 100644
--- a/editor/plugins/shader_editor_plugin.h
+++ b/editor/plugins/shader_editor_plugin.h
@@ -115,7 +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 String get_unsaved_status(const String &p_for_scene) const override;
virtual void save_external_data() override;
virtual void apply_changes() override;