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

Detect external modification of scenes #31747

Merged
merged 2 commits into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Detect external modification of project.godot
  • Loading branch information
KoBeWi committed Feb 9, 2021
commit c390c82014c23d7396cec731fceb515a354fe752
7 changes: 6 additions & 1 deletion core/config/project_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ Error ProjectSettings::_load_settings_text(const String &p_path) {
// If we're loading a project.godot from source code, we can operate some
// ProjectSettings conversions if need be.
_convert_to_last_version(config_version);
last_save_time = FileAccess::get_modified_time(get_resource_path().plus_file("project.godot"));
return OK;
} else if (err != OK) {
ERR_PRINT("Error parsing " + p_path + " at line " + itos(lines) + ": " + error_text + " File might be corrupted.");
Expand Down Expand Up @@ -676,7 +677,11 @@ void ProjectSettings::clear(const String &p_name) {
}

Error ProjectSettings::save() {
return save_custom(get_resource_path().plus_file("project.godot"));
Error error = save_custom(get_resource_path().plus_file("project.godot"));
if (error == OK) {
last_save_time = FileAccess::get_modified_time(get_resource_path().plus_file("project.godot"));
}
return error;
}

Error ProjectSettings::_save_settings_binary(const String &p_file, const Map<String, List<String>> &props, const CustomMap &p_custom, const String &p_custom_features) {
Expand Down
4 changes: 3 additions & 1 deletion core/config/project_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class ProjectSettings : public Object {

int last_order = NO_BUILTIN_ORDER_BASE;
int last_builtin_order = 0;
uint64_t last_save_time = 0;

Map<StringName, VariantContainer> props;
String resource_path;
Map<StringName, PropertyInfo> custom_prop_info;
Expand Down Expand Up @@ -113,7 +115,6 @@ class ProjectSettings : public Object {

Error _setup(const String &p_path, const String &p_main_pack, bool p_upwards = false);

protected:
static void _bind_methods();

public:
Expand Down Expand Up @@ -150,6 +151,7 @@ class ProjectSettings : public Object {
Error save();
void set_custom_property_info(const String &p_prop, const PropertyInfo &p_info);
const Map<StringName, PropertyInfo> &get_custom_property_info() const;
uint64_t get_last_saved_time() { return last_save_time; }

Vector<String> get_optimizer_presets() const;

Expand Down
2 changes: 1 addition & 1 deletion editor/editor_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class EditorData {
struct EditedScene {
Node *root = nullptr;
String path;
uint64_t file_modified_time;
uint64_t file_modified_time = 0;
Dictionary editor_states;
List<Node *> selection;
Vector<EditorHistory::History> history_stored;
Expand Down
15 changes: 14 additions & 1 deletion editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -904,13 +904,21 @@ void EditorNode::_scan_external_changes() {
}
}

String project_settings_path = ProjectSettings::get_singleton()->get_resource_path().plus_file("project.godot");
if (FileAccess::get_modified_time(project_settings_path) > ProjectSettings::get_singleton()->get_last_saved_time()) {
TreeItem *ti = disk_changed_list->create_item(r);
ti->set_text(0, "project.godot");
need_reload = true;
}

if (need_reload) {
disk_changed->call_deferred("popup_centered_ratio", 0.5);
}
}

void EditorNode::_resave_scenes(String p_str) {
save_all_scenes();
ProjectSettings::get_singleton()->save();
disk_changed->hide();
}

Expand All @@ -932,7 +940,7 @@ void EditorNode::_reload_modified_scenes() {

Error err = load_scene(filename, false, false, true, false, true);
if (err != OK) {
ERR_PRINT("Failed to load scene");
ERR_PRINT(vformat("Failed to load scene: %s", filename));
}
editor_data.move_edited_scene_to_index(i);
}
Expand All @@ -944,6 +952,10 @@ void EditorNode::_reload_modified_scenes() {
disk_changed->hide();
}

void EditorNode::_reload_project_settings() {
ProjectSettings::get_singleton()->setup(ProjectSettings::get_singleton()->get_resource_path(), String(), true);
}

void EditorNode::_vp_resized() {
}

Expand Down Expand Up @@ -6681,6 +6693,7 @@ EditorNode::EditorNode() {
disk_changed_list->set_v_size_flags(Control::SIZE_EXPAND_FILL);

disk_changed->connect("confirmed", callable_mp(this, &EditorNode::_reload_modified_scenes));
disk_changed->connect("confirmed", callable_mp(this, &EditorNode::_reload_project_settings));
disk_changed->get_ok_button()->set_text(TTR("Reload"));

disk_changed->add_button(TTR("Resave"), !DisplayServer::get_singleton()->get_swap_cancel_ok(), "resave");
Expand Down
1 change: 1 addition & 0 deletions editor/editor_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ class EditorNode : public Node {
void _resources_changed(const Vector<String> &p_resources);
void _scan_external_changes();
void _reload_modified_scenes();
void _reload_project_settings();
void _resave_scenes(String p_str);

void _feature_profile_changed();
Expand Down