annotate modules/Action.lua @ 237:704f4a05a1d7

Demodulificate all bar options (except state options)
author Flick
date Thu, 24 Mar 2011 13:11:30 -0700
parents 0e20f65375d5
children
rev   line source
flickerstreak@175 1 local addonName, addonTable = ...
flickerstreak@175 2 local ReAction = addonTable.ReAction
flickerstreak@24 3 local L = ReAction.L
flickerstreak@24 4 local _G = _G
flickerstreak@88 5 local format = string.format
flickerstreak@92 6 local wipe = wipe
flickerstreak@24 7
flickerstreak@116 8 local weak = { __mode="k" }
flickerstreak@116 9
flickerstreak@24 10 -- module declaration
flickerstreak@24 11 local moduleID = "Action"
flickerstreak@28 12 local module = ReAction:NewModule( moduleID )
flickerstreak@24 13
flickerstreak@90 14 -- Class declarations
flickerstreak@90 15 local PropHandler = { }
flickerstreak@87 16
flickerstreak@77 17 -- Event handlers
flickerstreak@24 18 function module:OnInitialize()
flickerstreak@90 19 self.handles = setmetatable({ }, weak)
flickerstreak@24 20 end
flickerstreak@24 21
flickerstreak@24 22 function module:OnEnable()
flickerstreak@90 23 ReAction:GetModule("State"):RegisterStateProperty("page", nil, PropHandler.GetOptions(), PropHandler)
flickerstreak@24 24 end
flickerstreak@24 25
flickerstreak@24 26 function module:OnDisable()
flickerstreak@90 27 ReAction:GetModule("State"):UnregisterStateProperty("page")
flickerstreak@90 28 end
flickerstreak@90 29
flickerstreak@87 30 ------ State property options ------
flickerstreak@87 31 do
flickerstreak@87 32 local pageOptions = {
flickerstreak@87 33 page = {
flickerstreak@92 34 name = L["Show Page #"],
flickerstreak@92 35 order = 11,
flickerstreak@92 36 type = "select",
flickerstreak@92 37 width = "half",
flickerstreak@87 38 disabled = "IsPageDisabled",
flickerstreak@87 39 hidden = "IsPageHidden",
flickerstreak@87 40 values = "GetPageValues",
flickerstreak@87 41 set = "SetProp",
flickerstreak@87 42 get = "GetPage",
flickerstreak@87 43 },
flickerstreak@87 44 }
flickerstreak@50 45
flickerstreak@90 46 function PropHandler.GetOptions()
flickerstreak@90 47 return pageOptions
flickerstreak@87 48 end
flickerstreak@87 49
flickerstreak@90 50 function PropHandler:IsPageDisabled()
flickerstreak@220 51 local c = self.bar:GetConfig()
flickerstreak@90 52 local n = c and c.nPages or 1
flickerstreak@90 53 return not (n > 1)
flickerstreak@87 54 end
flickerstreak@87 55
flickerstreak@90 56 function PropHandler:IsPageHidden()
flickerstreak@220 57 return not self.bar:GetConfig()
flickerstreak@87 58 end
flickerstreak@87 59
flickerstreak@90 60 function PropHandler:GetPageValues()
flickerstreak@92 61 if not self._pagevalues then
flickerstreak@92 62 self._pagevalues = { }
flickerstreak@92 63 end
flickerstreak@220 64 local c = self.bar:GetConfig()
flickerstreak@87 65 if c then
flickerstreak@87 66 local n = c.nPages
flickerstreak@92 67 -- cache the results
flickerstreak@87 68 if self._npages ~= n then
flickerstreak@87 69 self._npages = n
flickerstreak@92 70 wipe(self._pagevalues)
flickerstreak@87 71 for i = 1, n do
flickerstreak@90 72 self._pagevalues["page"..i] = i
flickerstreak@87 73 end
flickerstreak@87 74 end
flickerstreak@87 75 end
flickerstreak@92 76 return self._pagevalues
flickerstreak@87 77 end
flickerstreak@87 78
flickerstreak@90 79 function PropHandler:GetPage(info)
flickerstreak@87 80 return self:GetProp(info) or 1
flickerstreak@87 81 end
flickerstreak@90 82
flickerstreak@87 83 end
flickerstreak@87 84