Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't save unnecessarily with save_before_running #90034

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 53 additions & 11 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2073,17 +2073,23 @@ void EditorNode::restart_editor() {
void EditorNode::_save_all_scenes() {
bool all_saved = true;
for (int i = 0; i < editor_data.get_edited_scene_count(); i++) {
Node *scene = editor_data.get_edited_scene_root(i);
if (scene) {
if (!scene->get_scene_file_path().is_empty() && DirAccess::exists(scene->get_scene_file_path().get_base_dir())) {
if (i != editor_data.get_edited_scene()) {
_save_scene(scene->get_scene_file_path(), i);
} else {
_save_scene_with_preview(scene->get_scene_file_path());
}
} else if (!scene->get_scene_file_path().is_empty()) {
all_saved = false;
}
if (!_is_scene_unsaved(i)) {
continue;
}

const Node *scene = editor_data.get_edited_scene_root(i);
ERR_FAIL_NULL(scene);

const String &scene_path = scene->get_scene_file_path();
if (!scene_path.is_empty() && !DirAccess::exists(scene_path.get_base_dir())) {
all_saved = false;
continue;
}

if (i == editor_data.get_edited_scene()) {
_save_scene_with_preview(scene_path);
} else {
_save_scene(scene_path, i);
}
}

Expand Down Expand Up @@ -2111,6 +2117,28 @@ void EditorNode::_mark_unsaved_scenes() {
scene_tabs->update_scene_tabs();
}

bool EditorNode::_is_scene_unsaved(int p_idx) {
const Node *scene = editor_data.get_edited_scene_root(p_idx);
if (!scene) {
return false;
}

if (EditorUndoRedoManager::get_singleton()->is_history_unsaved(editor_data.get_scene_history_id(p_idx))) {
return true;
}

const String &scene_path = scene->get_scene_file_path();
if (!scene_path.is_empty()) {
// Check if scene has unsaved changes in built-in resources.
for (int j = 0; j < editor_data.get_editor_plugin_count(); j++) {
if (!editor_data.get_editor_plugin(j)->get_unsaved_status(scene_path).is_empty()) {
KoBeWi marked this conversation as resolved.
Show resolved Hide resolved
return true;
}
}
}
return false;
}

void EditorNode::_dialog_action(String p_file) {
switch (current_menu_option) {
case FILE_NEW_INHERITED_SCENE: {
Expand Down Expand Up @@ -3493,6 +3521,20 @@ void EditorNode::_discard_changes(const String &p_str) {
}

void EditorNode::_update_file_menu_opened() {
bool has_unsaved = false;
for (int i = 0; i < editor_data.get_edited_scene_count(); i++) {
if (_is_scene_unsaved(i)) {
has_unsaved = true;
break;
}
}
if (has_unsaved) {
file_menu->set_item_disabled(file_menu->get_item_index(FILE_SAVE_ALL_SCENES), false);
file_menu->set_item_tooltip(file_menu->get_item_index(FILE_SAVE_ALL_SCENES), String());
} else {
file_menu->set_item_disabled(file_menu->get_item_index(FILE_SAVE_ALL_SCENES), true);
file_menu->set_item_tooltip(file_menu->get_item_index(FILE_SAVE_ALL_SCENES), TTR("All scenes are already saved."));
}
file_menu->set_item_disabled(file_menu->get_item_index(FILE_OPEN_PREV), previous_scenes.is_empty());
_update_undo_redo_allowed();
}
Expand Down
1 change: 1 addition & 0 deletions editor/editor_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ class EditorNode : public Node {
bool _find_and_save_edited_subresources(Object *obj, HashMap<Ref<Resource>, bool> &processed, int32_t flags);
void _save_edited_subresources(Node *scene, HashMap<Ref<Resource>, bool> &processed, int32_t flags);
void _mark_unsaved_scenes();
bool _is_scene_unsaved(int p_idx);

void _find_node_types(Node *p_node, int &count_2d, int &count_3d);
void _save_scene_with_preview(String p_file, int p_idx = -1);
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/shader_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ String ShaderEditorPlugin::get_unsaved_status(const String &p_for_scene) const {

void ShaderEditorPlugin::save_external_data() {
for (EditedShader &edited_shader : edited_shaders) {
if (edited_shader.shader_editor) {
if (edited_shader.shader_editor && edited_shader.shader_editor->is_unsaved()) {
edited_shader.shader_editor->save_external_data();
}
}
Expand Down
Loading