# HG changeset patch # User Flick # Date 1174425620 0 # Node ID 2da5089ab7fff3f95e64587547c6f94027f8544e # Parent 27aeec452e7fc44f26a099c34b4b317ed4dfc20a diff -r 27aeec452e7f -r 2da5089ab7ff classes/ReBinder.lua --- a/classes/ReBinder.lua Tue Mar 20 21:20:05 2007 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,136 +0,0 @@ --- ReBinder.lua --- - -ReBinder = { } - --- initial values -ReBinder.active = false - -ReBinder.targets = { } - -function ReBinder:AddKeybindTarget( t ) - if t then - self.targets[t] = CreateFrame("Button", nil, t, "ReBinderClickBindingTemplate") - self.targets[t].keybindTarget = t:GetName() - end -end - -function ReBinder:RemoveKeybindTarget( t ) - if t then - self.targets[t] = nil - end -end - -function ReBinder:ShowClickBindingButtons() - for _, clickFrame in pairs(self.targets) do - clickFrame:Show() - end -end - -function ReBinder:HideClickBindingButtons() - for _, clickFrame in pairs(self.targets) do - clickFrame:Hide() - end -end - -function ReBinder:ClearSelectedKey() - self.selectedKey = nil -end - -function ReBinder:ToggleEnabled() - if self:IsEnabled() then - self:Disable() - else - self:Enable() - end -end - -function ReBinder:IsEnabled() - return ReBinderFrame:IsVisible() -end - -function ReBinder:Enable() - ReBinderFrame:Show() -end - -function ReBinder:Disable() - ReBinderFrame:Hide() -end - - -function ReBinder:HandleKeyPressed( key ) - if key == nil or key == "UNKNOWN" or key == "SHIFT" or key == "CTRL" or key == "ALT" then - return - end - if IsShiftKeyDown() then - key = "SHIFT-"..key - end - if IsControlKeyDown() then - key = "CTRL-"..key - end - if IsAltKeyDown() then - key = "ALT-"..key - end - if key == "ESCAPE" or GetBindingAction(key) == "REBINDER_TOGGLEBINDINGMODE" then - ReBinderFrame:Hide() - return nil, nil - end - - self.selectedKey = key - - local keyTxt = GetBindingText(key, "KEY_") - local cmd = GetBindingAction(key) - local cmdTxt - - if cmd then - cmdTxt = GetBindingText(cmd, "BINDING_NAME_") - end - - -- make click-bindings look prettier - local btnName - if cmdTxt then - btnName = string.match(cmdTxt,"CLICK (.+)\:LeftButton") - btnName = btnName or string.match(cmdTxt,"CLICK (.+)\:RightButton") - end - - return keyTxt, btnName or cmdTxt -end - --- TODO: move to override-binding model and store data in profile -function ReBinder:BindSelectedKeyTo( btnName ) - if self.selectedKey and btnName then - self:ClearBinding(btnName) - SetBindingClick(self.selectedKey, btnName, "LeftButton") - SaveBindings(2) -- 2 = character-specific - ReBinderFrame.statusMsg:SetText(GetBindingText(self.selectedKey, "KEY_") .. " is now bound to " .. btnName) - ReBinderFrame.selectedKey:SetText("(none)") - ReBinderFrame.currentAction:SetText("(none)") - self.selectedKey = nil - end -end - - -function ReBinder:ClearBinding( btnName ) - if btnName then - local current = GetBindingKey("CLICK "..btnName..":LeftButton") - if current then - SetBinding(current, nil) - ReBinderFrame.statusMsg:SetText("|cFFFF3333"..btnName .. " is now unbound|r") - end - end -end - - -function ReBinder:UpdateCurrentTarget( btnName ) - local msg = "" - if btnName then - msg = btnName.." is currently " - local current = GetBindingKey("CLICK "..btnName..":LeftButton") - if current then - msg = msg .. "bound to " .. GetBindingText(current, "KEY_") - else - msg = msg .. " not bound" - end - end - ReBinderFrame.statusMsg:SetText(msg) -end diff -r 27aeec452e7f -r 2da5089ab7ff classes/ReBinder.xml --- a/classes/ReBinder.xml Tue Mar 20 21:20:05 2007 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,242 +0,0 @@ - - - - - - - - - - - - - - this.selectedKey = getglobal(this:GetName().."SelectedKeyText") - this.currentAction = getglobal(this:GetName().."CurrentActionText") - this:RegisterForClicks("MiddleButtonUp","Button4Up","Button5Up") - - - local k, a = ReBinder:HandleKeyPressed(arg1) - if k then - this.selectedKey:SetText(k) - this.currentAction:SetText(a or "(none)") - end - - - - - - - this.selectedKey = getglobal(this:GetName().."DialogSelectedKeyText") - this.currentAction = getglobal(this:GetName().."DialogCurrentActionText") - this.statusMsg = getglobal(this:GetName().."DialogStatusMsg") - tinsert(UISpecialFrames,this:GetName()) - this:RegisterForClicks("MiddleButtonUp","Button4Up","Button5Up") - - - this.selectedKey:SetText("(none)") - this.currentAction:SetText("(none)") - this.statusMsg:SetText("") - ReBinder:ShowClickBindingButtons() - - - ReBinder:HideClickBindingButtons() - ReBinder:ClearSelectedKey() - - - local k, a = ReBinder:HandleKeyPressed(arg1) - if k then - this.selectedKey:SetText(k) - this.currentAction:SetText(a or "(none)") - end - - - local k, a = ReBinder:HandleKeyPressed(arg1) - if k then - this.selectedKey:SetText(k) - this.currentAction:SetText(a or "(none)") - end - - - - -