Display time of last save in the unsaved changes confirmation editor dialog

When multitasking, this makes it clearer whether closing a window with unsaved
changes is potentially dangerous or not.
This commit is contained in:
Hugo Locurcio 2023-08-25 01:18:05 +02:00
parent bc88dca176
commit 3ba031602b
No known key found for this signature in database
GPG key ID: 39E8F8BE30B0A49C
2 changed files with 16 additions and 1 deletions

View file

@ -553,6 +553,7 @@ void EditorNode::_notification(int p_what) {
case NOTIFICATION_READY: { case NOTIFICATION_READY: {
{ {
started_timestamp = Time::get_singleton()->get_unix_time_from_system();
_initializing_plugins = true; _initializing_plugins = true;
Vector<String> addons; Vector<String> addons;
if (ProjectSettings::get_singleton()->has_setting("editor_plugins/enabled")) { if (ProjectSettings::get_singleton()->has_setting("editor_plugins/enabled")) {
@ -5517,7 +5518,19 @@ void EditorNode::_scene_tab_closed(int p_tab) {
if (scene_filename.is_empty()) { if (scene_filename.is_empty()) {
unsaved_message = TTR("This scene was never saved."); unsaved_message = TTR("This scene was never saved.");
} else { } else {
unsaved_message = vformat(TTR("Scene \"%s\" has unsaved changes."), scene_filename); // Consider editor startup to be a point of saving, so that when you
// close and reopen the editor, you don't get an excessively long
// "modified X hours ago".
const uint64_t last_modified_seconds = Time::get_singleton()->get_unix_time_from_system() - MAX(started_timestamp, FileAccess::get_modified_time(scene->get_scene_file_path()));
String last_modified_string;
if (last_modified_seconds < 120) {
last_modified_string = vformat(TTRN("%d second ago", "%d seconds ago", last_modified_seconds), last_modified_seconds);
} else if (last_modified_seconds < 7200) {
last_modified_string = vformat(TTRN("%d minute ago", "%d minutes ago", last_modified_seconds / 60), last_modified_seconds / 60);
} else {
last_modified_string = vformat(TTRN("%d hour ago", "%d hours ago", last_modified_seconds / 3600), last_modified_seconds / 3600);
}
unsaved_message = vformat(TTR("Scene \"%s\" has unsaved changes.\nLast saved: %s."), scene_filename, last_modified_string);
} }
} else { } else {
// Check if any plugin has unsaved changes in that scene. // Check if any plugin has unsaved changes in that scene.

View file

@ -355,6 +355,8 @@ private:
Timer *screenshot_timer = nullptr; Timer *screenshot_timer = nullptr;
uint64_t started_timestamp = 0;
PluginConfigDialog *plugin_config_dialog = nullptr; PluginConfigDialog *plugin_config_dialog = nullptr;
RichTextLabel *load_errors = nullptr; RichTextLabel *load_errors = nullptr;