diff modules/ReAction_ConfigUI/ReAction_ConfigUI.lua @ 63:768be7eb22a0

Converted several ReAction APIs to event-driven model instead of 'call-method-on-all-modules' model. Cleaned up a number of other architectural issues.
author Flick <flickerstreak@gmail.com>
date Thu, 22 May 2008 22:02:08 +0000
parents 2ee41dcd673f
children c8c8610fd864
line wrap: on
line diff
--- a/modules/ReAction_ConfigUI/ReAction_ConfigUI.lua	Tue May 13 16:42:52 2008 +0000
+++ b/modules/ReAction_ConfigUI/ReAction_ConfigUI.lua	Thu May 22 22:02:08 2008 +0000
@@ -85,7 +85,7 @@
   self.frame.obj:SetCallback("default", 
     function() 
       ReAction.db:ResetProfile()
-      self:OnOptionsRefreshed()
+      ReAction:RefreshOptions()
     end )
 end
 
@@ -96,7 +96,7 @@
 local function NewEditor()
   -- private variables
   local editorName = "ReAction-Editor"
-  local barOptMap = { }
+  local barOptMap = setmetatable({},{__mode="v"})
   local tmp = { }
   local pointTable = {
     CENTER      = L["Center"], 
@@ -126,7 +126,7 @@
         editor.closePending = false
       end
       if editor.selfClosePending then
-        ed:Hide()
+        editor:Hide()
         AceConfigReg:NotifyChange(configName)
         editor.selfClosePending = false
       end
@@ -193,9 +193,9 @@
           type = {
             type = "select",
             name = L["Button Type"],
-            get  = function() return tmp.barType or ReAction.defaultBarConfigChoice or "" end,
+            get  = function() return tmp.barType or ReAction:GetDefaultBarType() or "" end,
             set  = function(info, val) 
-                     local c = ReAction.defaultBarConfig[val]
+                     local c = ReAction:GetBarTypeConfig(val)
                      tmp.barType = val 
                      tmp.barSize = c.defaultButtonSize or tmp.barSize
                      tmp.barRows = c.defaultBarRows or tmp.barRows
@@ -403,12 +403,10 @@
   end
 
   function editor:RefreshBarTree(bar)
-    local opts = options.args[barOptMap[bar:GetName()]]
-    opts.plugins = { }
-    for name, module in ReAction:IterateModules() do
-      if module.GetBarOptions then
-        opts.plugins[module:GetName()] = { [module:GetName()] = module:GetBarOptions(bar) }
-      end
+    local key = barOptMap[bar:GetName()]
+    if key and options.args[key] then
+      options.args[key].plugins = ReAction:GenerateBarOptionsTable(bar)
+      AceConfigReg:NotifyChange(editorName)
     end
   end
 
@@ -416,6 +414,14 @@
     self:CreateBarTree(bar)
   end
 
+  function editor:OnDestroyBar(evt, bar, name)
+    local key = barOptMap[name]
+    if key then
+      options.args[key] = nil
+    end
+    self:Refresh()
+  end
+
   function editor:OnEraseBar(evt, name)
     local key = barOptMap[name]
     barOptMap[name] = nil
@@ -434,29 +440,37 @@
     end
   end
   
+  function editor:OnBarOptionGeneratorRegistered(evt)
+    for name in pairs(barOptMap) do
+      local bar = ReAction:GetBar(name)
+      if bar then
+        self:RefreshBarTree(bar)
+      end
+    end
+  end
+
   local _scratch = { }
   function editor:GetBarTypes()
     for k,v in pairs(_scratch) do
       _scratch[k] = nil
     end
-    for k in pairs(ReAction.defaultBarConfig) do
-      _scratch[k] = k
-    end
-    return _scratch
+    return ReAction:GetBarTypeOptions(_scratch)
   end
 
   function editor:CreateBar()
     if tmp.barName and tmp.barName ~= "" then
-      ReAction:CreateBar(tmp.barName, tmp.barType or ReAction.defaultBarConfigChoice, tmp.barRows, tmp.barCols, tmp.barSize, tmp.barSpacing)
+      ReAction:CreateBar(tmp.barName, tmp.barType or ReAction:GetDefaultBarType(), tmp.barRows, tmp.barCols, tmp.barSize, tmp.barSpacing)
       tmp.barName = nil
     end
   end
 
   ReAction.RegisterCallback(editor,"OnCreateBar")
+  ReAction.RegisterCallback(editor,"OnDestroyBar")
   ReAction.RegisterCallback(editor,"OnEraseBar")
   ReAction.RegisterCallback(editor,"OnRenameBar")
+  ReAction.RegisterCallback(editor,"OnBarOptionGeneratorRegistered")
 
-  for name, bar in pairs(ReAction.bars) do
+  for name, bar in ReAction:IterateBars() do
     editor:CreateBarTree(bar)
   end
 
@@ -471,6 +485,7 @@
     if not self.editor then
       self.editor = NewEditor()
     end
+    -- TODO: figure out how to open to a particular bar: currently AceConfigDialogue doesn't support this
     self.editor:Open()
     ReAction:SetConfigMode(true)
   end