diff modules/ReAction_ConfigUI/ReAction_ConfigUI.lua @ 28:21bcaf8215ff

- converted to Ace3 - rearranged file layout - configGUI menus not working right now
author Flick <flickerstreak@gmail.com>
date Mon, 17 Mar 2008 18:24:53 +0000
parents bf997ea151ca
children 0d95ce7a9ec2
line wrap: on
line diff
--- a/modules/ReAction_ConfigUI/ReAction_ConfigUI.lua	Tue Mar 11 21:39:34 2008 +0000
+++ b/modules/ReAction_ConfigUI/ReAction_ConfigUI.lua	Mon Mar 17 18:24:53 2008 +0000
@@ -30,13 +30,11 @@
 local Dewdrop = AceLibrary("Dewdrop-2.0")
 local print = ReAction.print
 local InCombatLockdown = InCombatLockdown
-local BarModule = ReAction:GetModule("Bar")
 
 -- module declaration
 local moduleID = "ConfigUI"
 local module = ReAction:NewModule( moduleID,
-  "AceConsole-2.0",  -- temp
-  "AceEvent-2.0"
+  "AceEvent-3.0"
   -- mixins go here
 )
 
@@ -97,17 +95,11 @@
 
 -- module methods
 function module:OnInitialize()
-  self.db = ReAction:AcquireDBNamespace(moduleID)
-  ReAction:RegisterDefaults(moduleID,"profile", 
+  self.db = ReAction.db:RegisterNamespace( moduleID,
     {
-
+      profile = { }
     }
   )
-
-  -- temp: this will be moved to main ReAction.lua later in a more efficient AceConsole-less implementation
-  -- that can load the ConfigUI module on demand
-  -- NOTE: this inserts an 'about' command that we don't want
-  self:RegisterChatCommand( {L["/reaction"], L["/rxn"]}, self.globalOptions, "REACTION" )
 end
 
 function module:OnEnable()
@@ -136,8 +128,8 @@
 end
 
 function module:SetConfigMode( mode )
-  BarModule:CallMethodOnAllBars("ShowControls",mode)
-  ReAction:CallMethodOnAllModules("ApplyConfigMode",mode,BarModule.bars)
+  ReAction:CallMethodOnAllBars("ShowControls",mode)
+  ReAction:CallMethodOnAllModules("ApplyConfigMode",mode,ReAction.bars)
   self.configMode = mode
 end
 
@@ -161,11 +153,17 @@
   module:RefreshConfig()
 end
 
+local function SafeCall(module, method, ...)
+  if module and type(module[method]) == "function" then
+    return module[method](...)
+  end
+end
+
 function module:RefreshOptions()
   local opts = self.configOptions.args
   
-  for _, m in ReAction:IterateModulesWithMethod("GetGlobalOptions") do
-    local o = m:GetGlobalOptions(self)
+  for _, m in ReAction:IterateModules() do
+    local o = SafeCall(m,"GetGlobalOptions",self)
     if o then
       for k, v in pairs(o) do
         opts.global.args[k] = v
@@ -173,8 +171,8 @@
     end
   end
 
-  for _, m in ReAction:IterateModulesWithMethod("GetGlobalBarOptions") do
-    local o = m:GetGlobalBarOptions(self)
+  for _, m in ReAction:IterateModules() do
+    local o = SafeCall(m,"GetGlobalBarOptions",self)
     if o then
       for k, v in pairs(o) do
         opts.bar.args[k] = v
@@ -182,8 +180,8 @@
     end
   end
 
-  for _, m in ReAction:IterateModulesWithMethod("GetModuleOptions") do
-    local o = m:GetModuleOptions(self)
+  for _, m in ReAction:IterateModules() do
+    local o = SafeCall(m,"GetModuleOptions",self)
     if o then
       for k, v in pairs(o) do
         opts.module.args[k] = v
@@ -192,7 +190,7 @@
   end
 
   local barOpts = opts.bar.args
-  for name, bar in pairs(BarModule.bars) do
+  for name, bar in pairs(ReAction.bars) do
     if bar then
       if barOpts[name] == nil then
         barOpts[name] = {
@@ -200,14 +198,28 @@
           name = name,
           desc = name,
           handler = bar,
-          args = { }
+          args = { 
+            delete = {
+              type = "execute",
+              name = L["Delete Bar"],
+              desc = L["Remove the bar from the current profile"],
+              func = function() ReAction:EraseBar(bar); self:RefreshConfig() end
+            },
+            rename = {
+              type = "text",
+              name = L["Rename Bar"],
+              desc = L["Set a name for the bar"],
+              get  = "GetName",
+              set  = function(name) ReAction:RenameBar(bar,name); self:RefreshConfig() end
+            }
+          }
         }
       end
       if bar.modConfigOpts == nil then 
         bar.modConfigOpts = { }
       end
-      for _, m in ReAction:IterateModulesWithMethod("GetBarConfigOptions") do
-        local o = m:GetBarConfigOptions(bar,self)
+      for _, m in ReAction:IterateModules() do
+        local o = SafeCall(m,"GetBarConfigOptions",bar,self)
         if o then
           for k, v in pairs(o) do
             barOpts[name].args[k] = v
@@ -218,7 +230,7 @@
   end
   -- remove obsolete bar tables
   for name, opt in pairs(barOpts) do
-    if opt.type == "group" and BarModule.bars[name] == nil then
+    if opt.type == "group" and ReAction.bars[name] == nil then
       barOpts[name] = nil
     end
   end
@@ -262,7 +274,7 @@
 -- Bar config overlay
 --
 -- import some of these for small OnUpdate performance boost
-local Bar           = BarModule.BarClass.prototype
+local Bar           = ReAction.Bar.prototype
 local GetSize       = Bar.GetSize
 local GetButtonSize = Bar.GetButtonSize
 local GetButtonGrid = Bar.GetButtonGrid
@@ -280,7 +292,7 @@
   local point, relativeTo, relativePoint, x, y = f:GetPoint(1)
   relativeTo = relativeTo or f:GetParent()
   local anchorTo
-  for name, b in pairs(BarModule.bars) do
+  for name, b in pairs(ReAction.bars) do
     if b then
       if b:GetFrame() == relativeTo then
         anchorTo = name
@@ -534,8 +546,8 @@
     function()
       -- add bar type and status information to name
       local name = bar.name
-      for _, m in ReAction:IterateModulesWithMethod("GetBarNameModifier") do
-        local suffix = m:GetBarNameModifier(bar)
+      for _, m in ReAction:IterateModules() do
+        local suffix = SafeCall(m,"GetBarNameModifier",bar)
         if suffix then
           name = format("%s %s",name,suffix)
         end
@@ -584,16 +596,26 @@
           func = function() module:OpenConfig(self) end,
           disabled = InCombatLockdown,
           order = 1
-        }
+        },
+        delete = {
+          type = "execute",
+          name = L["Delete Bar"],
+          desc = L["Remove the bar from the current profile"],
+          func = function() ReAction:EraseBar(self) end,
+          order = 2
+        },
       }
     }
   end
   if self.modMenuOpts == nil then
     self.modMenuOpts = { }
   end
-  for _, m in ReAction:IterateModulesWithMethod("GetBarMenuOptions") do
-    for k, v in pairs(m:GetBarMenuOptions(self, module)) do
-      self.menuOpts.args[k] = v
+  for _, m in ReAction:IterateModules() do
+    local opts = SafeCall(m,"GetBarMenuOptions",self,module)
+    if opts then
+      for k, v in pairs(opts) do
+        self.menuOpts.args[k] = v
+      end
     end
   end
   Dewdrop:Open(self.controlFrame, "children", self.menuOpts, "cursorX", true, "cursorY", true)