Add a "dirty" marker to the editor import dock for unsaved changes

This commit is contained in:
Hugo Locurcio 2021-10-10 01:06:05 +02:00
parent 512211b61c
commit 35d76733b0
No known key found for this signature in database
GPG key ID: 39E8F8BE30B0A49C
2 changed files with 26 additions and 0 deletions

View file

@ -130,6 +130,7 @@ void ImportDock::set_edit_path(const String &p_path) {
_add_keep_import_option(importer_name); _add_keep_import_option(importer_name);
import->set_disabled(false); import->set_disabled(false);
_set_dirty(false);
import_as->set_disabled(false); import_as->set_disabled(false);
preset->set_disabled(false); preset->set_disabled(false);
@ -272,6 +273,7 @@ void ImportDock::set_edit_multiple_paths(const Vector<String> &p_paths) {
params->paths = p_paths; params->paths = p_paths;
import->set_disabled(false); import->set_disabled(false);
_set_dirty(false);
import_as->set_disabled(false); import_as->set_disabled(false);
preset->set_disabled(false); preset->set_disabled(false);
@ -511,6 +513,8 @@ void ImportDock::_reimport() {
EditorFileSystem::get_singleton()->reimport_files(params->paths); EditorFileSystem::get_singleton()->reimport_files(params->paths);
EditorFileSystem::get_singleton()->emit_signal("filesystem_changed"); //it changed, so force emitting the signal EditorFileSystem::get_singleton()->emit_signal("filesystem_changed"); //it changed, so force emitting the signal
_set_dirty(false);
} }
void ImportDock::_notification(int p_what) { void ImportDock::_notification(int p_what) {
@ -526,6 +530,24 @@ void ImportDock::_notification(int p_what) {
} }
} }
void ImportDock::_property_edited(const StringName &p_prop) {
_set_dirty(true);
}
void ImportDock::_set_dirty(bool p_dirty) {
if (p_dirty) {
// Add a dirty marker to notify the user that they should reimport the selected resource to see changes.
import->set_text(TTR("Reimport") + " (*)");
import->add_color_override("font_color", get_color("warning_color", "Editor"));
import->set_tooltip(TTR("You have pending changes that haven't been applied yet. Click Reimport to apply changes made to the import options.\nSelecting another resource in the FileSystem dock without clicking Reimport first will discard changes made in the Import dock."));
} else {
// Remove the dirty marker on the Reimport button.
import->set_text(TTR("Reimport"));
import->add_color_override("font_color", get_color("font_color", "Editor"));
import->set_tooltip("");
}
}
void ImportDock::_property_toggled(const StringName &p_prop, bool p_checked) { void ImportDock::_property_toggled(const StringName &p_prop, bool p_checked) {
if (p_checked) { if (p_checked) {
params->checked.insert(p_prop); params->checked.insert(p_prop);
@ -537,6 +559,7 @@ void ImportDock::_bind_methods() {
ClassDB::bind_method(D_METHOD("_reimport"), &ImportDock::_reimport); ClassDB::bind_method(D_METHOD("_reimport"), &ImportDock::_reimport);
ClassDB::bind_method(D_METHOD("_preset_selected"), &ImportDock::_preset_selected); ClassDB::bind_method(D_METHOD("_preset_selected"), &ImportDock::_preset_selected);
ClassDB::bind_method(D_METHOD("_importer_selected"), &ImportDock::_importer_selected); ClassDB::bind_method(D_METHOD("_importer_selected"), &ImportDock::_importer_selected);
ClassDB::bind_method(D_METHOD("_property_edited"), &ImportDock::_property_edited);
ClassDB::bind_method(D_METHOD("_property_toggled"), &ImportDock::_property_toggled); ClassDB::bind_method(D_METHOD("_property_toggled"), &ImportDock::_property_toggled);
ClassDB::bind_method(D_METHOD("_reimport_and_restart"), &ImportDock::_reimport_and_restart); ClassDB::bind_method(D_METHOD("_reimport_and_restart"), &ImportDock::_reimport_and_restart);
ClassDB::bind_method(D_METHOD("_reimport_attempt"), &ImportDock::_reimport_attempt); ClassDB::bind_method(D_METHOD("_reimport_attempt"), &ImportDock::_reimport_attempt);
@ -570,6 +593,7 @@ ImportDock::ImportDock() {
import_opts = memnew(EditorInspector); import_opts = memnew(EditorInspector);
add_child(import_opts); add_child(import_opts);
import_opts->set_v_size_flags(SIZE_EXPAND_FILL); import_opts->set_v_size_flags(SIZE_EXPAND_FILL);
import_opts->connect("property_edited", this, "_property_edited");
import_opts->connect("property_toggled", this, "_property_toggled"); import_opts->connect("property_toggled", this, "_property_toggled");
hb = memnew(HBoxContainer); hb = memnew(HBoxContainer);

View file

@ -65,7 +65,9 @@ class ImportDock : public VBoxContainer {
void _update_preset_menu(); void _update_preset_menu();
void _add_keep_import_option(const String &p_importer_name); void _add_keep_import_option(const String &p_importer_name);
void _property_edited(const StringName &p_prop);
void _property_toggled(const StringName &p_prop, bool p_checked); void _property_toggled(const StringName &p_prop, bool p_checked);
void _set_dirty(bool p_dirty);
void _reimport_attempt(); void _reimport_attempt();
void _reimport_and_restart(); void _reimport_and_restart();
void _reimport(); void _reimport();