flickerstreak@175: local addonName, addonTable = ... flickerstreak@175: local ReAction = addonTable.ReAction flickerstreak@24: local L = ReAction.L flickerstreak@24: local _G = _G flickerstreak@88: local format = string.format flickerstreak@92: local wipe = wipe flickerstreak@24: flickerstreak@116: local weak = { __mode="k" } flickerstreak@116: flickerstreak@24: -- module declaration flickerstreak@24: local moduleID = "Action" flickerstreak@28: local module = ReAction:NewModule( moduleID ) flickerstreak@24: flickerstreak@90: -- Class declarations flickerstreak@90: local PropHandler = { } flickerstreak@87: flickerstreak@77: -- Event handlers flickerstreak@24: function module:OnInitialize() flickerstreak@90: self.handles = setmetatable({ }, weak) flickerstreak@24: end flickerstreak@24: flickerstreak@24: function module:OnEnable() flickerstreak@90: ReAction:GetModule("State"):RegisterStateProperty("page", nil, PropHandler.GetOptions(), PropHandler) flickerstreak@24: end flickerstreak@24: flickerstreak@24: function module:OnDisable() flickerstreak@90: ReAction:GetModule("State"):UnregisterStateProperty("page") flickerstreak@90: end flickerstreak@90: flickerstreak@87: ------ State property options ------ flickerstreak@87: do flickerstreak@87: local pageOptions = { flickerstreak@87: page = { flickerstreak@92: name = L["Show Page #"], flickerstreak@92: order = 11, flickerstreak@92: type = "select", flickerstreak@92: width = "half", flickerstreak@87: disabled = "IsPageDisabled", flickerstreak@87: hidden = "IsPageHidden", flickerstreak@87: values = "GetPageValues", flickerstreak@87: set = "SetProp", flickerstreak@87: get = "GetPage", flickerstreak@87: }, flickerstreak@87: } flickerstreak@50: flickerstreak@90: function PropHandler.GetOptions() flickerstreak@90: return pageOptions flickerstreak@87: end flickerstreak@87: flickerstreak@90: function PropHandler:IsPageDisabled() flickerstreak@220: local c = self.bar:GetConfig() flickerstreak@90: local n = c and c.nPages or 1 flickerstreak@90: return not (n > 1) flickerstreak@87: end flickerstreak@87: flickerstreak@90: function PropHandler:IsPageHidden() flickerstreak@220: return not self.bar:GetConfig() flickerstreak@87: end flickerstreak@87: flickerstreak@90: function PropHandler:GetPageValues() flickerstreak@92: if not self._pagevalues then flickerstreak@92: self._pagevalues = { } flickerstreak@92: end flickerstreak@220: local c = self.bar:GetConfig() flickerstreak@87: if c then flickerstreak@87: local n = c.nPages flickerstreak@92: -- cache the results flickerstreak@87: if self._npages ~= n then flickerstreak@87: self._npages = n flickerstreak@92: wipe(self._pagevalues) flickerstreak@87: for i = 1, n do flickerstreak@90: self._pagevalues["page"..i] = i flickerstreak@87: end flickerstreak@87: end flickerstreak@87: end flickerstreak@92: return self._pagevalues flickerstreak@87: end flickerstreak@87: flickerstreak@90: function PropHandler:GetPage(info) flickerstreak@87: return self:GetProp(info) or 1 flickerstreak@87: end flickerstreak@90: flickerstreak@87: end flickerstreak@87: