diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2023-08-31 08:54:05 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-08-31 08:54:05 +0200 |
commit | 59de8f913d16f8655abc9428ea9f98a3aed40904 (patch) | |
tree | 0646e387e6fcf245f78ac8b8346cf1da9d828c14 | |
parent | aa9f3583e83338a7fa8f2c092cbb65996186c805 (diff) | |
parent | 3ba031602b8be8e93b5e77aa6645d071791748a6 (diff) | |
download | redot-engine-59de8f913d16f8655abc9428ea9f98a3aed40904.tar.gz |
Merge pull request #80976 from Calinou/editor-unsaved-changes-display-last-save-time
Display time of last save in the unsaved changes confirmation editor dialog
-rw-r--r-- | editor/editor_node.cpp | 15 | ||||
-rw-r--r-- | editor/editor_node.h | 2 |
2 files changed, 16 insertions, 1 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 645d6dd0f9..f5e13ac294 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -553,6 +553,7 @@ void EditorNode::_notification(int p_what) { case NOTIFICATION_READY: { { + started_timestamp = Time::get_singleton()->get_unix_time_from_system(); _initializing_plugins = true; Vector<String> addons; 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()) { unsaved_message = TTR("This scene was never saved."); } 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 { // Check if any plugin has unsaved changes in that scene. diff --git a/editor/editor_node.h b/editor/editor_node.h index d39e848de8..cac36f8bc2 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -355,6 +355,8 @@ private: Timer *screenshot_timer = nullptr; + uint64_t started_timestamp = 0; + PluginConfigDialog *plugin_config_dialog = nullptr; RichTextLabel *load_errors = nullptr; |