diff Bar.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 20003239af0b
children fcb5dad031f9
line wrap: on
line diff
--- a/Bar.lua	Tue May 13 16:42:52 2008 +0000
+++ b/Bar.lua	Thu May 22 22:02:08 2008 +0000
@@ -34,6 +34,8 @@
   f:SetWidth(config.width)
   f:SetWidth(config.height)
 
+  ReAction.RegisterCallback(self, "OnConfigModeChanged")
+
   self.frame = f
   self:RefreshLayout()
   self:ApplyAnchor()
@@ -46,14 +48,19 @@
   f:Hide()
   f:SetParent(UIParent)
   f:ClearAllPoints()
+  ReAction.UnregisterAllCallbacks(self)
   self.labelString = nil
   self.controlFrame = nil
   self.frame = nil
   self.config = nil
 end
 
+function Bar:OnConfigModeChanged(event, mode)
+  self:ShowControls(mode)
+end
+
 function Bar:RefreshLayout()
-  ReAction:CallMethodOnAllModules("RefreshBar", self)
+  ReAction:RefreshBar(self)
 end
 
 function Bar:ApplyAnchor()
@@ -186,7 +193,7 @@
     local point, relativeTo, relativePoint, x, y = f:GetPoint(1)
     relativeTo = relativeTo or f:GetParent()
     local anchorTo
-    for name, b in pairs(ReAction.bars) do
+    for name, b in ReAction:IterateBars() do
       if b and b:GetFrame() == relativeTo then
         anchorTo = name
         break
@@ -401,7 +408,7 @@
   local function GetClosestVisibleEdge( f )
     local r, o, e1, e2
     local a = anchorOutside
-    for _, b in pairs(ReAction.bars) do
+    for _, b in ReAction:IterateBars() do
       local d, e, opp = GetClosestFrameEdge(f,b:GetFrame(),a)
       if d and (not r or d < r) then
         r, o, e1, e2 = d, b:GetFrame(), e, opp
@@ -523,10 +530,6 @@
     end
   end
 
-  local function RefreshBarEditor()
-    ReAction:CallModuleMethod("ConfigUI","RefreshBarEditor")
-  end
-
   CreateControls = function(bar)
     local f = bar.frame
 
@@ -584,7 +587,7 @@
       StoreSize(bar)
       ClampToButtons(bar)
       ApplyAnchor(bar)
-      RefreshBarEditor()
+      ReAction:RefreshOptions()
     end
 
     -- edge drag handles
@@ -751,23 +754,23 @@
         end
 
         StoreExtents(bar)
-        RefreshBarEditor()
+        ReAction:RefreshOptions()
         updateDragTooltip()
       end
     )
 
     control:SetScript("OnEnter",
       function()
-        -- add bar type and status information to name
+        -- TODO: add bar type and status information to name
+        --[[
         local name = bar.name
         for _, m in ReAction:IterateModules() do
-          --[[
           local suffix = safecall(m,"GetBarNameModifier",bar)
           if suffix then
             name = ("%s %s"):format(name,suffix)
           end
-          --]]
         end
+        ]]--
 
         updateDragTooltip()
       end
@@ -825,7 +828,7 @@
           type = "execute",
           name = L["Settings..."],
           desc = L["Open the editor for this bar"],
-          func = function() CloseMenu(self.controlFrame); ReAction:CallModuleMethod("ConfigUI","LaunchBarEditor",self) end,
+          func = function() CloseMenu(self.controlFrame); ReAction:ShowEditor(self) end,
           disabled = InCombatLockdown,
           order = 1
         },