Remove settings properly (#7676)
authorSmallJoker <SmallJoker@users.noreply.github.com>
Sun, 30 Sep 2018 17:57:31 +0000 (19:57 +0200)
committerGitHub <noreply@github.com>
Sun, 30 Sep 2018 17:57:31 +0000 (19:57 +0200)
builtin/mainmenu/dlg_settings_advanced.lua
src/settings.cpp

index 2e6617aa728f34c02f29b384f085ea2bd5350e05..cc8a6d5d036c070c486b9e3e1896ed57c3c810d9 100644 (file)
@@ -977,12 +977,7 @@ local function handle_settings_buttons(this, fields, tabname, tabdata)
        if fields["btn_restore"] then
                local setting = settings[selected_setting]
                if setting and setting.type ~= "category" then
-                       if setting.type == "noise_params_2d"
-                                       or setting.type == "noise_params_3d" then
-                               core.settings:set_np_group(setting.name, setting.default_table)
-                       else
-                               core.settings:set(setting.name, setting.default)
-                       end
+                       core.settings:remove(setting.name)
                        core.settings:write()
                        core.update_formspec(this:get_formspec())
                end
index 0c34eb10c921b7236db6423204ec7a5fd3d4a1b0..4dd72a4f4737777f1c03b1455e56c637466a5cb0 100644 (file)
@@ -225,9 +225,13 @@ bool Settings::updateConfigObject(std::istream &is, std::ostream &os,
                case SPE_KVPAIR:
                        it = m_settings.find(name);
                        if (it != m_settings.end() &&
-                               (it->second.is_group || it->second.value != value)) {
+                                       (it->second.is_group || it->second.value != value)) {
                                printEntry(os, name, it->second, tab_depth);
                                was_modified = true;
+                       } else if (it == m_settings.end()) {
+                               // Remove by skipping
+                               was_modified = true;
+                               break;
                        } else {
                                os << line << "\n";
                                if (event == SPE_MULTILINE)
@@ -242,6 +246,10 @@ bool Settings::updateConfigObject(std::istream &is, std::ostream &os,
                                sanity_check(it->second.group != NULL);
                                was_modified |= it->second.group->updateConfigObject(is, os,
                                        "}", tab_depth + 1);
+                       } else if (it == m_settings.end()) {
+                               // Remove by skipping
+                               was_modified = true;
+                               break;
                        } else {
                                printEntry(os, name, it->second, tab_depth);
                                was_modified = true;
@@ -901,6 +909,8 @@ bool Settings::remove(const std::string &name)
        if (it != m_settings.end()) {
                delete it->second.group;
                m_settings.erase(it);
+
+               doCallbacks(name);
                return true;
        }