WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Ace3: Profile reset does not refresh config dialog? (https://www.wowinterface.com/forums/showthread.php?t=57864)

Lybrial 03-06-20 07:00 AM

Ace3: Profile reset does not refresh config dialog?
 
Hey,

I wonder how I can refresh the ace config dialog after I perform a profile reset (using Ace3).

Lua Code:
  1. function MyUI:SetupOptions()
  2.     MyUI.options = {
  3.         type = "group",
  4.         name = "My UI",
  5.         args = {};
  6.     };
  7.     MyUI.options.args.profile = DB_OPTIONS:GetOptionsTable(MyUI.db);
  8.     MyUI.options.args.profile.order = -10;
  9.     MyUI.options.args.profile.args.reset.confirm = true;
  10.  
  11.     CONFIG:RegisterOptionsTable(MyUI.ADDON_NAME, MyUI.options);
  12.     CONFIG:RegisterOptionsTable(MyUI.ADDON_NAME .. "_Profile", MyUI.options.args.profile);
  13.  
  14.     CONFIG_DIALOG:AddToBlizOptions(MyUI.ADDON_NAME, "My UI");
  15.     CONFIG_DIALOG:SetDefaultSize(MyUI.ADDON_NAME, MyUI:DefaultConfigSize());
  16. end

Lua Code:
  1. function MyUI:OnInitialize()
  2.     self.db = DB:New("MyDB", defaults, true);
  3.     self.db.RegisterCallback(self, "OnProfileChanged", "RefreshConfig");
  4.     self.db.RegisterCallback(self, "OnProfileCopied", "RefreshConfig");
  5.     self.db.RegisterCallback(self, "OnProfileReset", "RefreshConfig");
  6. end
  7.  
  8. function MyUI:RefreshConfig()
  9.     -- This calls every sub module to refresh it's state
  10.     self:OnUpdate();
  11. end

When I press the "Reset Profile" button all my settings are getting reset but the ace config dialog which is currently open and where I pressed the reset profile button in is not updating to the new state. I need to reload the UI to get the config dialog to show the new state. But that is not all, the options are also all broken. Those settings which got reset cant get configured by ace config dialog anymore until I reloaded the UI. Nothing happens when I use them without reloading the UI.

I tried using:

Lua Code:
  1. function MyUI:RefreshConfig()
  2.     -- This calls every sub module to refresh it's state
  3.     self:OnUpdate();
  4.  
  5.     CONFIG_REGISTRY:NotifyChange(MyUI.ADDON_NAME);
  6. end

But it has no effect. I would expect that the config dialog refreshes automatically after I reset the profile through ace3 internal functions. Is there any way I can refresh the config dialog without reloading the UI?

Lybrial 03-06-20 08:09 AM

Resetting the profile DOES reset the config dialog. The code above works perfectly.
The error in my case was caused by something different, hidden deep inside the code.

myrroddin 03-06-20 06:54 PM

There is no need to use NotifyChange unless you alter the settings via an external method like a LDB display or minimap button.

Other issues:
  • You don't specify the profile subtable within the defaults table.
  • There is no need to load all the Ace3 modules globally across your addon. AceDB and AceConfig can be local to OnInitialize.
  • Lua does not require ending lines of code with a semicolon. Lua totally ignores ; at the end of a line.

Code:

local MyAddOn = LibStub("AceAddon-3.0"):NewAddon("MyAddOn")

local db

local defaults = {
    profile = {
        cats = true,
    }
}

function MyAddOn:Initialize()
    self.db = LibStub("AceDB-3.0"):New("MyAddOnDB", defaults, true)
    self.db.RegisterCallback(self, "OnProfileChanged", "RefreshConfig")
    self.db.RegisterCallback(self, "OnProfileCopied", "RefreshConfig")
    self.db.RegisterCallback(self, "OnProfileReset", "RefreshConfig")
    db = self.db
end

function MyAddOn:RefreshConfig()
    db = self.db
end



All times are GMT -6. The time now is 03:37 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI