comparison modules/Action.lua @ 220:a4e7475633b3

un-namespace action button config
author Flick <flickerstreak@gmail.com>
date Sun, 21 Nov 2010 10:40:54 -0800
parents e63aefb8a555
children c4b134512c50
comparison
equal deleted inserted replaced
219:a5d91d7fd485 220:a4e7475633b3
17 local Handle = { } 17 local Handle = { }
18 local PropHandler = { } 18 local PropHandler = { }
19 19
20 -- Event handlers 20 -- Event handlers
21 function module:OnInitialize() 21 function module:OnInitialize()
22 self.db = ReAction.db:RegisterNamespace( moduleID,
23 {
24 profile = {
25 bars = { },
26 }
27 }
28 )
29 self.handles = setmetatable({ }, weak) 22 self.handles = setmetatable({ }, weak)
30 23
31 ReAction:RegisterBarOptionGenerator(self, "GetBarOptions") 24 ReAction:RegisterBarOptionGenerator(self, "GetBarOptions")
32 25
33 ReAction.RegisterCallback(self, "OnCreateBar") 26 ReAction.RegisterCallback(self, "OnCreateBar")
34 ReAction.RegisterCallback(self, "OnRefreshBar") 27 ReAction.RegisterCallback(self, "OnRefreshBar")
35 ReAction.RegisterCallback(self, "OnDestroyBar") 28 ReAction.RegisterCallback(self, "OnDestroyBar")
36 ReAction.RegisterCallback(self, "OnEraseBar")
37 ReAction.RegisterCallback(self, "OnRenameBar")
38 end 29 end
39 30
40 function module:OnEnable() 31 function module:OnEnable()
41 ReAction:RegisterBarType(Button, true) 32 ReAction:RegisterBarType(Button, true)
42 ReAction:GetModule("State"):RegisterStateProperty("page", nil, PropHandler.GetOptions(), PropHandler) 33 ReAction:GetModule("State"):RegisterStateProperty("page", nil, PropHandler.GetOptions(), PropHandler)
47 ReAction:GetModule("State"):UnregisterStateProperty("page") 38 ReAction:GetModule("State"):UnregisterStateProperty("page")
48 end 39 end
49 40
50 function module:OnCreateBar(event, bar, name) 41 function module:OnCreateBar(event, bar, name)
51 if bar.config.type == moduleID then 42 if bar.config.type == moduleID then
52 local profile = self.db.profile
53 if profile.bars[name] == nil then
54 profile.bars[name] = {
55 buttons = { }
56 }
57 end
58 if self.handles[bar] == nil then 43 if self.handles[bar] == nil then
59 self.handles[bar] = Handle:New(bar, profile.bars[name]) 44 self.handles[bar] = Handle:New(bar)
60 end 45 end
61 end 46 end
62 end 47 end
63 48
64 function module:OnRefreshBar(event, bar, name) 49 function module:OnRefreshBar(event, bar, name)
72 self.handles[bar]:Destroy() 57 self.handles[bar]:Destroy()
73 self.handles[bar] = nil 58 self.handles[bar] = nil
74 end 59 end
75 end 60 end
76 61
77 function module:OnEraseBar(event, bar, name)
78 self.db.profile.bars[name] = nil
79 end
80
81 function module:OnRenameBar(event, bar, oldname, newname)
82 b = self.db.profile.bars
83 b[newname], b[oldname] = b[oldname], nil
84 end
85 62
86 ---- Interface ---- 63 ---- Interface ----
87 function module:GetBarOptions(bar) 64 function module:GetBarOptions(bar)
88 local h = self.handles[bar] 65 local h = self.handles[bar]
89 if h then 66 if h then
226 }, 203 },
227 } 204 }
228 205
229 local meta = { __index = Handle } 206 local meta = { __index = Handle }
230 207
231 function Handle:New( bar, config ) 208 function Handle:New( bar )
209 local config = bar:GetConfig()
232 local self = setmetatable( 210 local self = setmetatable(
233 { 211 {
234 bar = bar, 212 bar = bar,
235 config = config, 213 config = config,
236 btns = { } 214 btns = { }
557 set = "SetProp", 535 set = "SetProp",
558 get = "GetPage", 536 get = "GetPage",
559 }, 537 },
560 } 538 }
561 539
562 local function GetBarConfig(bar)
563 return module.db.profile.bars[bar:GetName()]
564 end
565
566 function PropHandler.GetOptions() 540 function PropHandler.GetOptions()
567 return pageOptions 541 return pageOptions
568 end 542 end
569 543
570 function PropHandler:IsPageDisabled() 544 function PropHandler:IsPageDisabled()
571 local c = GetBarConfig(self.bar) 545 local c = self.bar:GetConfig()
572 local n = c and c.nPages or 1 546 local n = c and c.nPages or 1
573 return not (n > 1) 547 return not (n > 1)
574 end 548 end
575 549
576 function PropHandler:IsPageHidden() 550 function PropHandler:IsPageHidden()
577 return not GetBarConfig(self.bar) 551 return not self.bar:GetConfig()
578 end 552 end
579 553
580 function PropHandler:GetPageValues() 554 function PropHandler:GetPageValues()
581 if not self._pagevalues then 555 if not self._pagevalues then
582 self._pagevalues = { } 556 self._pagevalues = { }
583 end 557 end
584 local c = GetBarConfig(self.bar) 558 local c = self.bar:GetConfig()
585 if c then 559 if c then
586 local n = c.nPages 560 local n = c.nPages
587 -- cache the results 561 -- cache the results
588 if self._npages ~= n then 562 if self._npages ~= n then
589 self._npages = n 563 self._npages = n