View Single Post
12-28-14, 09:37 AM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Oh, I misunderstood what you wanted to do... I thought you actually wanted to open the tradeskill window for a specific profession. For what you're trying to do, I couldn't find a good way to toggle the spellbook from insecure code in ~10 minutes of testing, so you're probably going to have to do one of those out-of-combat workarounds:

Code:
local clicker
local function HideClicker()
          if not clicker then return end
          clicker:ClearAllPoints()
          clicker:Hide()
end

dataobj.OnEnter = function(self)
     if InCombatLockdown() then return end

     if not clicker then
          clicker = CreateFrame("Button", nil, UIParent, "SecureActionButtonTemplate")
          clicker:RegisterForClicks("AnyUp")
          clicker:SetAttribute("type", "macro")
          clicker:SetAttribute("macrotext", "/click [btn:3] SpellbookMicroButton")
          clicker:RegisterEvent("PLAYER_REGEN_DISABLED")
          clicker:SetScript("OnEvent", HideClicker)
          clicker:SetScript("OnLeave", HideClicker)
          self:HookScript("OnHide", HideClicker)
     end

     clicker:ClearAllPoints()
     clicker:SetAllPoints(self)
     clicker:SetFrameStrata("DIALOG")
     clicker:Show()
end

dataobj.OnLeave = HideClicker
Note that this will also hijack your tooltip, so if you need a tooltip, you'll have to set OnEnter/OnLeave scripts on the clicker to show/hide a tooltip. If you want to do other things on left/right click, you'll have to modify the clicker's macrotext attribute.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote