view OOCDo.lua @ 7:e41de98f6b33

.MacroText: explicitly set button type, as newer commands could change it to something else; luadoc.
author rowaasr13
date Tue, 10 Jan 2017 19:39:55 +0300
parents 0a7fd4d73d30
children 3b9bc71a1dd6
line wrap: on
line source
-- [AUTOLOCAL START]
local CreateFrame = CreateFrame
local InCombatLockdown = InCombatLockdown
local SecureHandlerWrapScript = SecureHandlerWrapScript
local print = print
local type = type
-- [AUTOLOCAL END]

local frame_name = "OOCDo"
local button = CreateFrame("Button", frame_name, nil, "SecureActionButtonTemplate,SecureHandlerMouseUpDownTemplate")
button:SetAttribute("type", "macro")
button:SetAttribute("macrotext", "")
SecureHandlerWrapScript(
   button,     -- frame
   "OnClick",  -- script
   button,     -- header
   'return nil, "reset"', -- pre
   'self:SetAttribute("type", "macro") self:SetAttribute("macrotext", "")' -- post
)

--- Sets button to perform given macro text as-is.
-- Sets button's .type to "macro" and .macrotext to given string verbatim
-- @param command macro text to perform
-- @param command2 same as command, if first argument is "taken" because of : call.
function button.MacroText(command, command2)
   if command == button then command = command2 end
   if InCombatLockdown() then return end
   button:SetAttribute("type", "macro")
   button:SetAttribute("macrotext", command)
end

button.Macro = button.MacroText
button.T = button.MacroText
button.M = button.MacroText