Skip to content

Commit b39a2e5

Browse files
committed
Fix Ignore External Changes Bug
Fix Issue #106410 : Add a new list `disk_changed_scenes()` and a boolean `disk_changed_project` to keep track of modfied scenes and the project. Save them only if they are in the list or the boolean value is true, when ignoring external changes.
1 parent 4a44078 commit b39a2e5

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

editor/editor_node.cpp

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,21 +1304,28 @@ void EditorNode::_scan_external_changes() {
13041304
disk_changed_list->set_hide_root(true);
13051305
bool need_reload = false;
13061306

1307-
// Check if any edited scene has changed.
1307+
disk_changed_scenes.clear();
1308+
disk_changed_project = false;
13081309

1310+
// Check if any edited scene has changed.
13091311
for (int i = 0; i < editor_data.get_edited_scene_count(); i++) {
13101312
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
1311-
if (editor_data.get_scene_path(i) == "" || !da->file_exists(editor_data.get_scene_path(i))) {
1313+
1314+
String scene_path = editor_data.get_scene_path(i);
1315+
1316+
if (scene_path == "" || !da->file_exists(scene_path)) {
13121317
continue;
13131318
}
13141319

13151320
uint64_t last_date = editor_data.get_scene_modified_time(i);
1316-
uint64_t date = FileAccess::get_modified_time(editor_data.get_scene_path(i));
1321+
uint64_t date = FileAccess::get_modified_time(scene_path);
13171322

13181323
if (date > last_date) {
13191324
TreeItem *ti = disk_changed_list->create_item(r);
1320-
ti->set_text(0, editor_data.get_scene_path(i).get_file());
1325+
ti->set_text(0, scene_path.get_file());
13211326
need_reload = true;
1327+
1328+
disk_changed_scenes.push_back(scene_path);
13221329
}
13231330
}
13241331

@@ -1327,16 +1334,25 @@ void EditorNode::_scan_external_changes() {
13271334
TreeItem *ti = disk_changed_list->create_item(r);
13281335
ti->set_text(0, "project.godot");
13291336
need_reload = true;
1337+
1338+
disk_changed_project = true;
13301339
}
13311340

13321341
if (need_reload) {
13331342
callable_mp((Window *)disk_changed, &Window::popup_centered_ratio).call_deferred(0.3);
13341343
}
13351344
}
13361345

1337-
void EditorNode::_resave_scenes(String p_str) {
1338-
save_all_scenes();
1339-
ProjectSettings::get_singleton()->save();
1346+
void EditorNode::_resave_externally_modified_scenes(String p_str) {
1347+
for (uint32_t i = 0; i < disk_changed_scenes.size(); i++) {
1348+
String scene_path = disk_changed_scenes[i];
1349+
_save_scene(scene_path);
1350+
}
1351+
1352+
if (disk_changed_project) {
1353+
ProjectSettings::get_singleton()->save();
1354+
}
1355+
13401356
disk_changed->hide();
13411357
}
13421358

@@ -8293,7 +8309,7 @@ EditorNode::EditorNode() {
82938309
disk_changed->set_ok_button_text(TTR("Reload from disk"));
82948310

82958311
disk_changed->add_button(TTR("Ignore external changes"), !DisplayServer::get_singleton()->get_swap_cancel_ok(), "resave");
8296-
disk_changed->connect("custom_action", callable_mp(this, &EditorNode::_resave_scenes));
8312+
disk_changed->connect("custom_action", callable_mp(this, &EditorNode::_resave_externally_modified_scenes));
82978313
}
82988314

82998315
gui_base->add_child(disk_changed);

editor/editor_node.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,8 @@ class EditorNode : public Node {
434434
EditorBottomPanel *bottom_panel = nullptr;
435435

436436
Tree *disk_changed_list = nullptr;
437+
LocalVector<String> disk_changed_scenes;
438+
bool disk_changed_project = false;
437439
ConfirmationDialog *disk_changed = nullptr;
438440
ConfirmationDialog *project_data_missing = nullptr;
439441

@@ -674,7 +676,7 @@ class EditorNode : public Node {
674676
void _scan_external_changes();
675677
void _reload_modified_scenes();
676678
void _reload_project_settings();
677-
void _resave_scenes(String p_str);
679+
void _resave_externally_modified_scenes(String p_str);
678680

679681
void _feature_profile_changed();
680682
bool _is_class_editor_disabled_by_feature_profile(const StringName &p_class);

0 commit comments

Comments
 (0)