Thanks for a reply! Actually,
ResetDB with
CopyTable makes change permanent.
Unfortunatelly, it looks like I still need to reload UI in order to make GUI active again (clicking checkbox changes it's visuals, and related
ADDON_NAME.db.global setting, but those are not saved on reloading UI).
Lua Code:
ADDON_NAME.db:ResetDB("Default");
ADDON_NAME.db.global = CopyTable(ADDON_NAME.default.global);
ADDON_NAME.libs.ConfigRegistry:NotifyChange("ADDON_NAME");
edit:
ResetProfile makes nothing, even with previously
RegisterDefaults.
edit2:
ResetDB defaults
.db already thanks to second parameter of
New, so no
CopyTable is needed.
Instead, we need to just reinitialize database since it's reset:
Lua Code:
ADDON_NAME.db:ResetDB("Default"); -- reset .db to default settings (passed as second parameter of ADDON_NAME.libs.DB:New)
ADDON_NAME.db = ADDON_NAME.libs.DB:New("ADDON_NAMEDB", ADDON_NAME.default, true); -- reinitialize .db (same as first init above)
ADDON_NAME.libs.ConfigRegistry:NotifyChange("ADDON_NAME"); -- finally, let GUI know to handle changes and work correctly after changing config
Works like a charm.
Final Note: Thanks, Ketho, for pointing out that passing table by reference won't work.
Thanks that, and the linked threads, connected with the "magic" issue, I found out how to handle it.
For futher reference, I am pasting the corrected code:
Lua Code:
-- libs
-- external /libs as ADDON_NAME.libs objects
ADDON_NAME.libs = {};
ADDON_NAME.libs.Config = LibStub("AceConfig-3.0");
ADDON_NAME.libs.ConfigDialog = LibStub("AceConfigDialog-3.0");
ADDON_NAME.libs.ConfigRegistry = LibStub("AceConfigRegistry-3.0");
ADDON_NAME.libs.DB = LibStub("AceDB-3.0");
ADDON_NAME.libs.Timer = LibStub("AceTimer-3.0");
Lua Code:
-- options
-- ADDON_NAME.default.global.MODULE_NAME
-- ADDON_NAME.options.args.MODULE_NAME
ADDON_NAME.default = {global = {}};
ADDON_NAME.options = {
name = "ADDON_FULL_NAME",
type = "group",
args = {},
};
Lua Code:
-- add options
ADDON_NAME.db = ADDON_NAME.libs.DB:New("ADDON_NAMEDB", ADDON_NAME.default, true);
ADDON_NAME.libs.Config:RegisterOptionsTable("ADDON_NAME", ADDON_NAME.options);
ADDON_NAME.frames = {options = ADDON_NAME.libs.ConfigDialog:AddToBlizOptions("ADDON_NAME")};
ADDON_NAME.frames.options.default = function()
ADDON_NAME.db:ResetDB("Default");
ADDON_NAME.db = ADDON_NAME.libs.DB:New("ADDON_NAMEDB", ADDON_NAME.default, true);
ADDON_NAME.libs.ConfigRegistry:NotifyChange("ADDON_NAME");
end;