diff --git a/xanAutoMail.lua b/xanAutoMail.lua
index 7092bd2..d55076a 100644
--- a/xanAutoMail.lua
+++ b/xanAutoMail.lua
@@ -15,97 +15,10 @@ local stopLoop = 10
local loopChk = 0
local skipCount = 0
-local xanAutoMail = CreateFrame("frame","xanAutoMailFrame",UIParent)
-xanAutoMail:SetScript("OnEvent", function(self, event, ...) if self[event] then return self[event](self, event, ...) end end)
-
---[[------------------------
- HOOKING
---------------------------]]
-
local origHook = {}
---create our own hooking function :)
-local function createHook(self, func, method, handler, secure, script)
- if not func then return end
-
- --check if already hooked
- local chkHook = false
- if method and origHook[func] and origHook[func][method] then
- chkHook = true
- elseif not method and origHook[func] then
- chkHook = true
- end
-
- --if we don't have the hook and it's not secure then create it
- if not chkHook and not secure and not script then
-
- --create tmp hook to replace original function
- local tmp = function(...)
- if origHook[func] then
- if handler then
- return handler(self, ...)
- elseif method then
- return self[method](self, ...)
- else
- return self[func](self, ...)
- end
- end
- end
-
- --check to see if were using a method, if we aren't then replace hook
- if not method then
- --store the original hook and then replace it
- origHook[func] = _G[func]
- _G[func] = tmp
- else
- origHook[func] = origHook[func] or {}
- origHook[func][method] = _G[func][method]
- _G[func][method] = tmp
- end
-
- elseif not chkHook and not secure and method and script then
- --NOTE: func cannot be a string
- --store the old script
- origHook[func] = origHook[func] or {}
- origHook[func][method] = func:GetScript(method)
-
- if handler then
- func:SetScript(method, handler)
- else
- func:SetScript(method, self[method])
- --will use a function from the addon as follows
- --self:method(...)
- end
-
- elseif not chkHook and secure then
-
- --it's a secure hook
- if not method then
- --NOTE: func must be a string for this to work properly
- if handler then
- hooksecurefunc(func, handler)
- else
- hooksecurefunc(func, self[func])
- --will use a function from the addon as follows
- --self:func(...)
- end
- origHook[func] = true
- else
- --NOTE: func must be a function/table and cannot be a string, method must be a string
- if handler then
- hooksecurefunc(func, method, handler)
- else
- hooksecurefunc(func, method, self[method])
- --will use a function from the addon as follows
- --self:method(...)
- end
- origHook[func] = origHook[func] or {}
- origHook[func][method] = true
- end
-
- end
-
-end
+local xanAutoMail = CreateFrame("frame","xanAutoMailFrame",UIParent)
+xanAutoMail:SetScript("OnEvent", function(self, event, ...) if self[event] then return self[event](self, event, ...) end end)
--[[------------------------
CORE
@@ -123,11 +36,20 @@ function xanAutoMail:PLAYER_LOGIN()
SendMailNameEditBox:SetHistoryLines(15)
--do the hooks
- createHook(self, "SendMailFrame_Reset")
- createHook(self, "MailFrameTab_OnClick")
- createHook(self, "AutoComplete_Update")
- createHook(self, SendMailNameEditBox, "OnEditFocusGained", nil, nil, true)
- createHook(self, SendMailNameEditBox, "OnChar", nil, nil, true)
+ origHook["SendMailFrame_Reset"] = SendMailFrame_Reset
+ SendMailFrame_Reset = self.SendMailFrame_Reset
+
+ origHook["MailFrameTab_OnClick"] = MailFrameTab_OnClick
+ MailFrameTab_OnClick = self.MailFrameTab_OnClick
+
+ origHook["AutoComplete_Update"] = AutoComplete_Update
+ AutoComplete_Update = self.AutoComplete_Update
+
+ origHook[SendMailNameEditBox] = origHook[SendMailNameEditBox] or {}
+ origHook[SendMailNameEditBox]["OnEditFocusGained"] = SendMailNameEditBox:GetScript("OnEditFocusGained")
+ origHook[SendMailNameEditBox]["OnChar"] = SendMailNameEditBox:GetScript("OnChar")
+ SendMailNameEditBox:SetScript("OnEditFocusGained", self.OnEditFocusGained)
+ SendMailNameEditBox:SetScript("OnChar", self.OnChar)
--make the open all button
inboxAllButton = CreateFrame("Button", "xanAutoMail_OpenAllBTN", InboxFrame, "UIPanelButtonTemplate")
@@ -193,7 +115,7 @@ end
--this is called when one of the mailtabs is clicked
--we have to autofill the name when the tabs are clicked
-function xanAutoMail:MailFrameTab_OnClick(self, tab)
+function xanAutoMail:MailFrameTab_OnClick(tab)
origHook["MailFrameTab_OnClick"](self, tab)
if tab == 2 then
local playerName = DB_RECENT[1]
@@ -206,7 +128,6 @@ end
--this function is called each time a character is pressed in the playername field of the mail window
function xanAutoMail:OnChar(...)
-
if self:GetUTF8CursorPosition() ~= strlenutf8(self:GetText()) then return end
local text = strupper(self:GetText())
local textlen = strlen(text)
@@ -261,9 +182,9 @@ function xanAutoMail:OnEditFocusGained(...)
SendMailNameEditBox:HighlightText()
end
-function xanAutoMail:AutoComplete_Update(editBox, editBoxText, utf8Position, ...)
- if editBox ~= SendMailNameEditBox then
- origHook["AutoComplete_Update"](editBox, editBoxText, utf8Position, ...)
+function xanAutoMail:AutoComplete_Update(editBoxText, utf8Position, ...)
+ if self ~= SendMailNameEditBox then
+ origHook["AutoComplete_Update"](self, editBoxText, utf8Position, ...)
end
end