diff --git a/doc/classes/EditorSettings.xml b/doc/classes/EditorSettings.xml index 81472c09eea..ac2250ab6d1 100644 --- a/doc/classes/EditorSettings.xml +++ b/doc/classes/EditorSettings.xml @@ -70,6 +70,13 @@ [/codeblocks] + + + + + Checks if any settings with the prefix [code]setting_prefix[/code] exist in the set of changed settings. See also [method get_changed_settings]. + + @@ -77,6 +84,12 @@ Erases the setting whose name is specified by [code]property[/code]. + + + + Gets an array of the settings which have been changed since the last save. Note that internally [code]changed_settings[/code] is cleared after a successful save, so generally the most appropriate place to use this method is when processing [constant NOTIFICATION_EDITOR_SETTINGS_CHANGED] + + @@ -118,6 +131,13 @@ Returns [code]true[/code] if the setting specified by [code]name[/code] exists, [code]false[/code] otherwise. + + + + + Marks the passed editor setting as being changed, see [method get_changed_settings]. Only settings which exist (see [method has_setting]) will be accepted. + + diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 6bd11fcdd66..0135b33bca1 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -63,6 +63,7 @@ bool EditorSettings::_set(const StringName &p_name, const Variant &p_value) { bool changed = _set_only(p_name, p_value); if (changed) { + changed_settings.insert(p_name); emit_signal(SNAME("settings_changed")); } return true; @@ -941,10 +942,34 @@ void EditorSettings::save() { if (err != OK) { ERR_PRINT("Error saving editor settings to " + singleton->config_file_path); } else { + singleton->changed_settings.clear(); print_verbose("EditorSettings: Save OK!"); } } +Array EditorSettings::get_changed_settings() const { + Array arr; + for (const String &setting : changed_settings) { + arr.push_back(setting); + } + + return arr; +} + +bool EditorSettings::check_changed_settings_in_group(const String &p_setting_prefix) const { + for (const String &setting : changed_settings) { + if (setting.begins_with(p_setting_prefix)) { + return true; + } + } + + return false; +} + +void EditorSettings::mark_setting_changed(const String &p_setting) { + changed_settings.insert(p_setting); +} + void EditorSettings::destroy() { if (!singleton.ptr()) { return; @@ -1621,6 +1646,10 @@ void EditorSettings::_bind_methods() { ClassDB::bind_method(D_METHOD("set_builtin_action_override", "name", "actions_list"), &EditorSettings::set_builtin_action_override); + ClassDB::bind_method(D_METHOD("check_changed_settings_in_group", "setting_prefix"), &EditorSettings::check_changed_settings_in_group); + ClassDB::bind_method(D_METHOD("get_changed_settings"), &EditorSettings::get_changed_settings); + ClassDB::bind_method(D_METHOD("mark_setting_changed", "setting"), &EditorSettings::mark_setting_changed); + ADD_SIGNAL(MethodInfo("settings_changed")); BIND_CONSTANT(NOTIFICATION_EDITOR_SETTINGS_CHANGED); diff --git a/editor/editor_settings.h b/editor/editor_settings.h index f0fec3acc76..65723a24f87 100644 --- a/editor/editor_settings.h +++ b/editor/editor_settings.h @@ -77,6 +77,8 @@ private: static Ref singleton; + Set changed_settings; + HashMap hints; HashMap props; int last_order; @@ -140,6 +142,9 @@ public: bool property_can_revert(const String &p_setting); Variant property_get_revert(const String &p_setting); void add_property_hint(const PropertyInfo &p_hint); + Array get_changed_settings() const; + bool check_changed_settings_in_group(const String &p_setting_prefix) const; + void mark_setting_changed(const String &p_setting); void set_resource_clipboard(const Ref &p_resource) { clipboard = p_resource; } Ref get_resource_clipboard() const { return clipboard; }