diff ReAction.lua @ 88:fc83b3f5b322

Added keybindings using LibKeyBound-1.0, with modifications for Override bindings instead of standard bindings.
author Flick <flickerstreak@gmail.com>
date Sun, 31 Aug 2008 06:02:18 +0000
parents 57f8151ea0f0
children 7cabc8ac6c16
line wrap: on
line diff
--- a/ReAction.lua	Sat Jun 28 00:54:21 2008 +0000
+++ b/ReAction.lua	Sun Aug 31 06:02:18 2008 +0000
@@ -51,11 +51,16 @@
 
 ------ LIBRARIES ------
 local callbacks = LibStub("CallbackHandler-1.0"):New(ReAction)
+local KB = LibStub("LibKeyBound-1.0")
 local L = LibStub("AceLocale-3.0"):GetLocale("ReAction")
 ReAction.L = L
 
 ------ PRIVATE ------
-local private = { }
+local weak = {__mode="k"}
+local private = {
+  allKB = setmetatable({}, weak),
+  kbHooked = setmetatable({}, weak),
+}
 local bars = {}
 local defaultBarConfig = {}
 local barOptionGenerators = { }
@@ -198,12 +203,15 @@
       self:SetConfigMode(true)
     elseif option == "lock" then
       self:SetConfigMode(false)
+    elseif option == "kb" then
+      self:SetKeybindMode(true)
     else
       self:Print(("%3.1f.%d"):format(version,self.revision))
       self:Print("/rxn config")
       self:Print("/rxn edit")
       self:Print("/rxn lock")
       self:Print("/rxn unlock")
+      self:Print("/rxn kb")
     end
   end
 end
@@ -223,6 +231,9 @@
   self.db.RegisterCallback(self,"OnProfileChanged")
   self.db.RegisterCallback(self,"OnProfileReset","OnProfileChanged")
 
+  KB.RegisterCallback(self,"LIBKEYBOUND_ENABLED")
+  KB.RegisterCallback(self,"LIBKEYBOUND_DISABLED")
+
   options.args.profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
 
   self:RegisterChatCommand("reaction", SlashHandler)
@@ -247,9 +258,18 @@
   if private.configMode == true then
     self:UserError(L["ReAction config mode disabled during combat."])
     self:SetConfigMode(false)
+    self:SetKeybindMode(false)
   end
 end
 
+function ReAction:LIBKEYBOUND_ENABLED( evt )
+  self:SetKeybindMode(true)
+end
+
+function ReAction:LIBKEYBOUND_DISABLED( evt )
+  return self:SetKeybindMode(false)
+end
+
 
 
 ------ API ------
@@ -465,3 +485,58 @@
 function ReAction:ShowEditor(bar, ...)
   CallModuleMethod("ConfigUI","LaunchBarEditor",bar, ...)
 end
+
+
+local kb_onEnter
+do
+  function kb_onEnter( self )
+    if ReAction:GetKeybindMode() then
+      KB:Set(self)
+    end
+  end
+end
+
+function ReAction:SetKeybindMode( mode )
+  if mode ~= private.kbMode then
+    if mode then
+      for f in pairs(private.allKB) do
+        if not private.kbHooked[f] then
+          -- avoid taint, particularly with SecureAnchorEnterTemplate
+          -- don't hook scripts multiple times, there isn't any unhook!
+          f:HookScript("OnEnter",kb_onEnter)
+          private.kbHooked[f] = true
+        end
+      end
+      KB:Activate()
+    else
+      KB:Deactivate()
+    end
+    private.kbMode = KB:IsShown() or false
+  end
+end
+
+function ReAction:GetKeybindMode( mode )
+  return private.kbMode
+end
+
+function ReAction:RegisterKeybindFrame( f )
+  private.allKB[f] = true
+end
+
+function ReAction:FreeOverrideHotkey( key )
+  for f in pairs(private.allKB) do
+    if f.GetBindings then
+      for i = 1, select('#', f:GetBindings()) do
+        if select(i, f:GetBindings()) == key then
+          if f.FreeKey then
+            return f:FreeKey(key)
+          else
+            local action = f.GetActionName and f:GetActionName() or f:GetName()
+            SetOverrideBinding(f, false, key, nil)
+            return action
+          end
+        end
+      end
+    end
+  end
+end