1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-05 12:10:55 +00:00

Optimize unsaved history checking

This commit is contained in:
kobewi
2025-05-13 00:13:12 +02:00
parent 19bb18716e
commit e0e8bd5394
2 changed files with 18 additions and 7 deletions

View File

@@ -354,6 +354,16 @@ void EditorNode::_update_title() {
} }
} }
void EditorNode::_update_unsaved_cache() {
bool is_unsaved = EditorUndoRedoManager::get_singleton()->is_history_unsaved(EditorUndoRedoManager::GLOBAL_HISTORY) ||
EditorUndoRedoManager::get_singleton()->is_history_unsaved(editor_data.get_current_edited_scene_history_id());
if (unsaved_cache != is_unsaved) {
unsaved_cache = is_unsaved;
_update_title();
}
}
void EditorNode::input(const Ref<InputEvent> &p_event) { void EditorNode::input(const Ref<InputEvent> &p_event) {
// EditorNode::get_singleton()->set_process_input is set to true in ProgressDialog // EditorNode::get_singleton()->set_process_input is set to true in ProgressDialog
// only when the progress dialog is visible. // only when the progress dialog is visible.
@@ -692,13 +702,6 @@ void EditorNode::_notification(int p_what) {
} break; } break;
case NOTIFICATION_PROCESS: { case NOTIFICATION_PROCESS: {
bool global_unsaved = EditorUndoRedoManager::get_singleton()->is_history_unsaved(EditorUndoRedoManager::GLOBAL_HISTORY);
bool scene_or_global_unsaved = global_unsaved || EditorUndoRedoManager::get_singleton()->is_history_unsaved(editor_data.get_current_edited_scene_history_id());
if (unsaved_cache != scene_or_global_unsaved) {
unsaved_cache = scene_or_global_unsaved;
_update_title();
}
if (editor_data.is_scene_changed(-1)) { if (editor_data.is_scene_changed(-1)) {
scene_tabs->update_scene_tabs(); scene_tabs->update_scene_tabs();
} }
@@ -1975,6 +1978,7 @@ int EditorNode::_save_external_resources(bool p_also_save_external_data) {
} }
EditorUndoRedoManager::get_singleton()->set_history_as_saved(EditorUndoRedoManager::GLOBAL_HISTORY); EditorUndoRedoManager::get_singleton()->set_history_as_saved(EditorUndoRedoManager::GLOBAL_HISTORY);
_update_unsaved_cache();
return saved; return saved;
} }
@@ -2094,6 +2098,7 @@ void EditorNode::_save_scene(String p_file, int idx) {
} }
scene->propagate_notification(NOTIFICATION_EDITOR_POST_SAVE); scene->propagate_notification(NOTIFICATION_EDITOR_POST_SAVE);
_update_unsaved_cache();
} }
void EditorNode::save_all_scenes() { void EditorNode::save_all_scenes() {
@@ -3066,6 +3071,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
} }
} }
} }
_update_unsaved_cache();
} break; } break;
case SCENE_REDO: { case SCENE_REDO: {
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
@@ -3092,6 +3098,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
} }
} }
} }
_update_unsaved_cache();
} break; } break;
case SCENE_RELOAD_SAVED_SCENE: { case SCENE_RELOAD_SAVED_SCENE: {
@@ -4117,6 +4124,7 @@ void EditorNode::_set_current_scene_nocheck(int p_idx) {
} }
_update_undo_redo_allowed(); _update_undo_redo_allowed();
_update_unsaved_cache();
} }
void EditorNode::setup_color_picker(ColorPicker *p_picker) { void EditorNode::setup_color_picker(ColorPicker *p_picker) {
@@ -7280,7 +7288,9 @@ EditorNode::EditorNode() {
add_child(epnp); add_child(epnp);
EditorUndoRedoManager::get_singleton()->connect("version_changed", callable_mp(this, &EditorNode::_update_undo_redo_allowed)); EditorUndoRedoManager::get_singleton()->connect("version_changed", callable_mp(this, &EditorNode::_update_undo_redo_allowed));
EditorUndoRedoManager::get_singleton()->connect("version_changed", callable_mp(this, &EditorNode::_update_unsaved_cache));
EditorUndoRedoManager::get_singleton()->connect("history_changed", callable_mp(this, &EditorNode::_update_undo_redo_allowed)); EditorUndoRedoManager::get_singleton()->connect("history_changed", callable_mp(this, &EditorNode::_update_undo_redo_allowed));
EditorUndoRedoManager::get_singleton()->connect("history_changed", callable_mp(this, &EditorNode::_update_unsaved_cache));
ProjectSettings::get_singleton()->connect("settings_changed", callable_mp(this, &EditorNode::_update_from_settings)); ProjectSettings::get_singleton()->connect("settings_changed", callable_mp(this, &EditorNode::_update_from_settings));
GDExtensionManager::get_singleton()->connect("extensions_reloaded", callable_mp(this, &EditorNode::_gdextensions_reloaded)); GDExtensionManager::get_singleton()->connect("extensions_reloaded", callable_mp(this, &EditorNode::_gdextensions_reloaded));

View File

@@ -566,6 +566,7 @@ private:
void _save_editor_states(const String &p_file, int p_idx = -1); void _save_editor_states(const String &p_file, int p_idx = -1);
void _load_editor_plugin_states_from_config(const Ref<ConfigFile> &p_config_file); void _load_editor_plugin_states_from_config(const Ref<ConfigFile> &p_config_file);
void _update_title(); void _update_title();
void _update_unsaved_cache();
void _version_control_menu_option(int p_idx); void _version_control_menu_option(int p_idx);
void _close_messages(); void _close_messages();
void _show_messages(); void _show_messages();