# HG changeset patch # User Flick # Date 1241740500 0 # Node ID 901c91dc1bf25666ac905495c100bbf12087572f # Parent 86564b5cbbffb80aef6a649a9a1d9d891d949caa Some refactoring of configmode/keybind handlers diff -r 86564b5cbbff -r 901c91dc1bf2 classes/Bar.lua --- a/classes/Bar.lua Thu Apr 30 16:51:43 2009 +0000 +++ b/classes/Bar.lua Thu May 07 23:55:00 2009 +0000 @@ -8,9 +8,12 @@ ReAction:UpdateRevision("$Revision$") +local KB = LibStub("LibKeyBound-1.0") + +---- Bar class ---- local Bar = { } -local proto = { __index = Bar } local weak = { __mode = "k" } +local frameList = { } ReAction.Bar = Bar -- export to ReAction @@ -26,15 +29,21 @@ name = name, buttons = setmetatable( { }, weak ), width = config.width or 480, - height = config.height or 40 + height = config.height or 40, }, - proto ) + {__index = self} ) -- The frame type is 'Button' in order to have an OnClick handler. However, the frame itself is -- not mouse-clickable by the user. local parent = config.parent and (ReAction:GetBar(config.parent) or _G[config.parent]) or UIParent - local f = CreateFrame("Button", name and format("ReAction-%s",name), parent, - "SecureHandlerStateTemplate, SecureHandlerClickTemplate") + name = name and "ReAction-"..name + local f = name and frameList[name] + if not f then + f = CreateFrame("Button", name, parent, "SecureHandlerStateTemplate, SecureHandlerClickTemplate") + if name then + frameList[name] = f + end + end f:SetFrameStrata("MEDIUM") f:SetWidth(self.width) f:SetHeight(self.height) @@ -62,7 +71,13 @@ end self:ApplyAnchor() + self:SetConfigMode(ReAction:GetConfigMode()) + self:SetKeybindMode(ReAction:GetKeybindMode()) + ReAction.RegisterCallback(self, "OnConfigModeChanged") + KB.RegisterCallback(self, "LIBKEYBOUND_ENABLED") + KB.RegisterCallback(self, "LIBKEYBOUND_DISABLED") + KB.RegisterCallback(self, "LIBKEYBOUND_MODE_COLOR_CHANGED","LIBKEYBOUND_ENABLED") return self end @@ -72,21 +87,27 @@ f:UnregisterAllEvents() self:ShowControls(false) ReAction.UnregisterAllCallbacks(self) + KB.UnregisterAllCallbacks(self) ReAction.gridProxy:RemoveFrame(f) - f:Hide() f:SetParent(UIParent) f:ClearAllPoints() + f:Hide() end -function Bar:GetConfig() - return self.config +-- +-- Events +-- + +function Bar:OnConfigModeChanged(event, mode) + self:SetConfigMode(mode) end -function Bar:OnConfigModeChanged(event, mode) - self:ShowControls(mode) -- Bar:ShowControls() defined in Overlay.lua - for b in pairs(self.buttons) do - b:ShowGridTemp(mode) - end +function Bar:LIBKEYBOUND_ENABLED(evt) + self:SetKeybindMode(true) +end + +function Bar:LIBKEYBOUND_DISABLED(evt) + self:SetKeybindMode(false) end function Bar:ApplyAnchor() @@ -246,6 +267,20 @@ return pairs(self.buttons) end +function Bar:SetConfigMode(mode) + self:ShowControls(mode) + for b in self:IterateButtons() do + b:ShowGridTemp(mode) + b:UpdateActionIDLabel(mode) + end +end + +function Bar:SetKeybindMode(mode) + for b in self:IterateButtons() do + b:SetKeybindMode(mode) + end +end + function Bar:PlaceButton(button, baseW, baseH) local idx = self.buttons[button] if idx then @@ -264,4 +299,4 @@ function Bar:SkinButton() -- does nothing by default -end \ No newline at end of file +end diff -r 86564b5cbbff -r 901c91dc1bf2 locale/enUS.lua --- a/locale/enUS.lua Thu Apr 30 16:51:43 2009 +0000 +++ b/locale/enUS.lua Thu May 07 23:55:00 2009 +0000 @@ -146,7 +146,7 @@ "Action Bars", "Hide Empty Buttons", "Lock Buttons", -"Prevents picking up/dragging actions.|nNOTE: This setting is overridden by the global setting in Blizzard's Action Buttons tab", +"Prevents picking up/dragging actions (use SHIFT to override this behavior)", "Only in Combat", "Only lock the buttons when in combat", "# Pages", diff -r 86564b5cbbff -r 901c91dc1bf2 modules/Action.lua --- a/modules/Action.lua Thu Apr 30 16:51:43 2009 +0000 +++ b/modules/Action.lua Thu May 07 23:55:00 2009 +0000 @@ -9,9 +9,6 @@ local weak = { __mode="k" } --- libraries -local KB = LibStub("LibKeyBound-1.0") - -- module declaration local moduleID = "Action" local module = ReAction:NewModule( moduleID ) @@ -39,11 +36,6 @@ ReAction.RegisterCallback(self, "OnDestroyBar") ReAction.RegisterCallback(self, "OnEraseBar") ReAction.RegisterCallback(self, "OnRenameBar") - ReAction.RegisterCallback(self, "OnConfigModeChanged") - - KB.RegisterCallback(self, "LIBKEYBOUND_ENABLED") - KB.RegisterCallback(self, "LIBKEYBOUND_DISABLED") - KB.RegisterCallback(self, "LIBKEYBOUND_MODE_COLOR_CHANGED","LIBKEYBOUND_ENABLED") end function module:OnEnable() @@ -99,25 +91,6 @@ b[newname], b[oldname] = b[oldname], nil end -function module:OnConfigModeChanged(event, mode) - for _, h in pairs(self.handles) do - h:SetConfigMode(mode) - end -end - -function module:LIBKEYBOUND_ENABLED(evt) - for _, h in pairs(self.handles) do - h:SetKeybindMode(true) - end -end - -function module:LIBKEYBOUND_DISABLED(evt) - for _, h in pairs(self.handles) do - h:SetKeybindMode(false) - end -end - - ---- Interface ---- function module:GetBarOptions(bar) local h = self.handles[bar] @@ -141,7 +114,7 @@ }, lockButtons = { name = L["Lock Buttons"], - desc = L["Prevents picking up/dragging actions.|nNOTE: This setting is overridden by the global setting in Blizzard's Action Buttons tab"], + desc = L["Prevents picking up/dragging actions (use SHIFT to override this behavior)"], order = 2, type = "toggle", get = "GetLockButtons", @@ -276,7 +249,6 @@ self.config.buttons = { } end self:Refresh() - self:SetKeybindMode(ReAction:GetKeybindMode()) return self end @@ -321,22 +293,10 @@ end end - function Handle:SetConfigMode(mode) - for _, b in pairs(self.btns) do - b:UpdateActionIDLabel(mode) - end - end - function Handle:UpdateButtonLock() Button.SetButtonLock(self.bar, self.config.lockButtons, self.config.lockButtonsCombat) end - function Handle:SetKeybindMode(mode) - for _, b in pairs(self.btns) do - b:SetKeybindMode(mode) - end - end - function Handle:GetLastButton() return self.btns[#self.btns] end diff -r 86564b5cbbff -r 901c91dc1bf2 modules/Bag.lua --- a/modules/Bag.lua Thu Apr 30 16:51:43 2009 +0000 +++ b/modules/Bag.lua Thu May 07 23:55:00 2009 +0000 @@ -17,9 +17,6 @@ -- mixins go here ) --- libraries -local KB = LibStub("LibKeyBound-1.0") - -- handlers function module:OnInitialize() self.db = ReAction.db:RegisterNamespace( moduleID, @@ -37,11 +34,6 @@ ReAction.RegisterCallback(self, "OnRefreshBar") ReAction.RegisterCallback(self, "OnEraseBar") ReAction.RegisterCallback(self, "OnRenameBar") - ReAction.RegisterCallback(self, "OnConfigModeChanged") - - KB.RegisterCallback(self, "LIBKEYBOUND_ENABLED") - KB.RegisterCallback(self, "LIBKEYBOUND_DISABLED") - KB.RegisterCallback(self, "LIBKEYBOUND_MODE_COLOR_CHANGED","LIBKEYBOUND_ENABLED") end function module:OnEnable() @@ -125,36 +117,6 @@ b[newname], b[oldname] = b[oldname], nil end -function module:OnConfigModeChanged(event, mode) - for bar in pairs(self.buttons) do - for b in bar:IterateButtons() do - b:UpdateActionIDLabel(mode) - end - end -end - -function module:LIBKEYBOUND_ENABLED(evt) - for _, buttons in pairs(self.buttons) do - for _, b in pairs(buttons) do - b:SetKeybindMode(true) - end - end -end - -function module:LIBKEYBOUND_DISABLED(evt) - for _, buttons in pairs(self.buttons) do - for _, b in pairs(buttons) do - b:SetKeybindMode(false) - end - end -end - -function module:RefreshAll() - for bar in pairs(self.buttons) do - self:OnRefreshBar(nil,bar,bar:GetName()) - end -end - -- hook some functions to propagate to our bag buttons hooksecurefunc("Disable_BagButtons", diff -r 86564b5cbbff -r 901c91dc1bf2 modules/ModuleTemplate.lua --- a/modules/ModuleTemplate.lua Thu Apr 30 16:51:43 2009 +0000 +++ b/modules/ModuleTemplate.lua Thu May 07 23:55:00 2009 +0000 @@ -30,7 +30,6 @@ ReAction.RegisterCallback(self, "OnRefreshBar") ReAction.RegisterCallback(self, "OnEraseBar") ReAction.RegisterCallback(self, "OnRenameBar") - ReAction.RegisterCallback(self, "OnConfigModeChanged") end function module:OnEnable() @@ -66,8 +65,4 @@ end --- update any local display/options based on config mode (true/false) -function module:OnConfigModeChanged(event, mode) -end - diff -r 86564b5cbbff -r 901c91dc1bf2 modules/PetAction.lua --- a/modules/PetAction.lua Thu Apr 30 16:51:43 2009 +0000 +++ b/modules/PetAction.lua Thu May 07 23:55:00 2009 +0000 @@ -15,9 +15,6 @@ ReAction:UpdateRevision("$Revision$") --- libraries -local KB = LibStub("LibKeyBound-1.0") - -- module declaration local moduleID = "PetAction" local module = ReAction:NewModule( moduleID ) @@ -56,10 +53,6 @@ ReAction.RegisterCallback(self, "OnEraseBar") ReAction.RegisterCallback(self, "OnRenameBar") ReAction.RegisterCallback(self, "OnConfigModeChanged") - - KB.RegisterCallback(self, "LIBKEYBOUND_ENABLED") - KB.RegisterCallback(self, "LIBKEYBOUND_DISABLED") - KB.RegisterCallback(self, "LIBKEYBOUND_MODE_COLOR_CHANGED","LIBKEYBOUND_ENABLED") end function module:OnEnable() @@ -171,23 +164,6 @@ end end -function module:LIBKEYBOUND_ENABLED(evt) - for _, buttons in pairs(self.buttons) do - for _, b in pairs(buttons) do - b:SetKeybindMode(true) - end - end -end - -function module:LIBKEYBOUND_DISABLED(evt) - for _, buttons in pairs(self.buttons) do - for _, b in pairs(buttons) do - b:SetKeybindMode(false) - end - end -end - - ---- Options ---- local Handler = { } local meta = { __index = Handler } @@ -232,7 +208,7 @@ args = { lockButtons = { name = L["Lock Buttons"], - desc = L["Prevents picking up/dragging actions.|nNOTE: This setting is overridden by the global setting in Blizzard's Action Buttons tab"], + desc = L["Prevents picking up/dragging actions (use SHIFT to override this behavior)"], order = 2, type = "toggle", get = "GetLockButtons", diff -r 86564b5cbbff -r 901c91dc1bf2 modules/Stance.lua --- a/modules/Stance.lua Thu Apr 30 16:51:43 2009 +0000 +++ b/modules/Stance.lua Thu May 07 23:55:00 2009 +0000 @@ -17,9 +17,6 @@ -- mixins go here ) --- libraries -local KB = LibStub("LibKeyBound-1.0") - -- handlers function module:OnInitialize() self.db = ReAction.db:RegisterNamespace( moduleID, @@ -39,11 +36,6 @@ ReAction.RegisterCallback(self, "OnRefreshBar") ReAction.RegisterCallback(self, "OnEraseBar") ReAction.RegisterCallback(self, "OnRenameBar") - ReAction.RegisterCallback(self, "OnConfigModeChanged") - - KB.RegisterCallback(self, "LIBKEYBOUND_ENABLED") - KB.RegisterCallback(self, "LIBKEYBOUND_DISABLED") - KB.RegisterCallback(self, "LIBKEYBOUND_MODE_COLOR_CHANGED","LIBKEYBOUND_ENABLED") end function module:OnEnable() @@ -128,30 +120,6 @@ b[newname], b[oldname] = b[oldname], nil end -function module:OnConfigModeChanged(event, mode) - for bar in pairs(self.buttons) do - for b in bar:IterateButtons() do - b:UpdateActionIDLabel(mode) - end - end -end - -function module:LIBKEYBOUND_ENABLED(evt) - for _, buttons in pairs(self.buttons) do - for _, b in pairs(buttons) do - b:SetKeybindMode(true) - end - end -end - -function module:LIBKEYBOUND_DISABLED(evt) - for _, buttons in pairs(self.buttons) do - for _, b in pairs(buttons) do - b:SetKeybindMode(false) - end - end -end - function module:RefreshAll() for bar in pairs(self.buttons) do self:OnRefreshBar(nil,bar,bar:GetName())