Zerotorescue@31: local MailOpener = LibStub("AceAddon-3.0"):GetAddon("MailOpener"); Zerotorescue@31: local mod = MailOpener:NewModule("BeanCounterSupport", "AceEvent-3.0", "AceHook-3.0"); Zerotorescue@70: local L = LibStub("AceLocale-3.0"):GetLocale("MailOpener"); Zerotorescue@31: Zerotorescue@68: mod.moduleDescription = L["Prevents mail opening while BeanCounter is still scanning. Does nothing when BeanCounter is disabled."]; Zerotorescue@31: mod.moduleRequired = false; Zerotorescue@31: Zerotorescue@31: local MailAddonName = "BeanCounter"; -- what to fill the global MailAddonBusy with Zerotorescue@31: local refMonitoredFrame; -- reference to the frame we will be monitoring Zerotorescue@31: Zerotorescue@31: function mod:OnInitialize() Zerotorescue@31: if select(6, GetAddOnInfo("BeanCounter")) ~= nil then Zerotorescue@31: -- BeanCounter is DISABLED, so we don't need this module Zerotorescue@31: self:Debug("Disabling"); Zerotorescue@31: self:SetEnabledState(false); Zerotorescue@31: Zerotorescue@31: if self:IsEnabled() then Zerotorescue@31: self:Disable(); Zerotorescue@31: end Zerotorescue@31: end Zerotorescue@31: end Zerotorescue@31: Zerotorescue@31: function mod:OnEnable() Zerotorescue@31: self:Debug("OnEnable"); Zerotorescue@31: Zerotorescue@31: self:RegisterEvent("MAIL_SHOW"); Zerotorescue@31: Zerotorescue@31: -- If we were toggling this module on while the mailbox is opened we must register all events again Zerotorescue@31: if MailFrame:IsVisible() then Zerotorescue@31: self:MAIL_SHOW(); Zerotorescue@31: end Zerotorescue@31: end Zerotorescue@31: Zerotorescue@31: -- Even though Ace can unregister our events it's neater to do it manually too Zerotorescue@31: function mod:OnDisable() Zerotorescue@31: self:Debug("OnDisable"); Zerotorescue@31: Zerotorescue@31: self:UnregisterEvent("MAIL_SHOW"); Zerotorescue@31: end Zerotorescue@31: Zerotorescue@31: function mod:MAIL_SHOW() Zerotorescue@31: self:Debug("MAIL_SHOW"); Zerotorescue@31: Zerotorescue@31: self:RegisterEvent("MAIL_CLOSED"); Zerotorescue@31: Zerotorescue@31: refMonitoredFrame = InboxCloseButton; Zerotorescue@31: Zerotorescue@31: -- Hook the OnHide of refMonitoredFrame indicating BeanCounter has started Zerotorescue@31: self:HookScript(refMonitoredFrame, "OnHide", "BeanCounterActivated"); Zerotorescue@31: end Zerotorescue@31: Zerotorescue@31: function mod:MAIL_CLOSED() Zerotorescue@31: self:Debug("MAIL_CLOSED"); Zerotorescue@31: Zerotorescue@31: self:UnregisterEvent("MAIL_CLOSED"); Zerotorescue@31: Zerotorescue@31: refMonitoredFrame = nil; Zerotorescue@31: Zerotorescue@31: -- We don't need any hooks anymore Zerotorescue@31: self:UnhookAll(); Zerotorescue@31: Zerotorescue@31: -- Make sure we don't get stuck for the entire session (restart every mailbox close) Zerotorescue@31: if MailAddonBusy == MailAddonName then Zerotorescue@31: MailAddonBusy = nil; Zerotorescue@31: end Zerotorescue@31: end Zerotorescue@31: Zerotorescue@31: -- Called when the refMonitoredFrame is hidden Zerotorescue@31: function mod:BeanCounterActivated() Zerotorescue@31: if refMonitoredFrame:GetParent():IsVisible() then Zerotorescue@31: -- Ensure this isn't called when the container is being hidden Zerotorescue@31: Zerotorescue@31: mod:Debug("BeanCounterActivated"); Zerotorescue@31: Zerotorescue@31: -- Unhook the current hook (and reapply it after the OnShow was triggered) Zerotorescue@31: self:Unhook(refMonitoredFrame, "OnHide"); Zerotorescue@31: Zerotorescue@31: -- Hook the OnShow of refMonitoredFrame indicating BeanCounter is finished Zerotorescue@31: self:HookScript(refMonitoredFrame, "OnShow", "BeanCounterDeactivated"); Zerotorescue@31: Zerotorescue@31: MailAddonBusy = MailAddonName; Zerotorescue@31: end Zerotorescue@31: end Zerotorescue@31: Zerotorescue@31: -- Called when the refMonitoredFrame is shown Zerotorescue@31: function mod:BeanCounterDeactivated() Zerotorescue@31: if refMonitoredFrame:GetParent():IsVisible() then Zerotorescue@31: -- Ensure this isn't called when the container is being shown Zerotorescue@31: Zerotorescue@31: mod:Debug("BeanCounterDeactivated"); Zerotorescue@31: Zerotorescue@31: -- Unhook the current hook (and reapply it after the OnHide was triggered) Zerotorescue@31: self:Unhook(refMonitoredFrame, "OnShow"); Zerotorescue@31: Zerotorescue@31: -- Hook the OnHide of the refMonitoredFrame again which is trigged when BeanCounter starts Zerotorescue@31: self:HookScript(refMonitoredFrame, "OnHide", "BeanCounterActivated"); Zerotorescue@31: Zerotorescue@31: if MailAddonBusy == MailAddonName then Zerotorescue@31: MailAddonBusy = nil; Zerotorescue@31: end Zerotorescue@31: end Zerotorescue@31: end Zerotorescue@31: Zerotorescue@31: function mod:GetOptionsGroup() Zerotorescue@31: local configGroup = { Zerotorescue@31: order = 0, Zerotorescue@31: type = "modulesSubGroup", Zerotorescue@68: name = L["BeanCounter Support"], Zerotorescue@68: desc = L["Change settings for the BeanCounter Support module."], Zerotorescue@31: args = { Zerotorescue@31: General = { Zerotorescue@31: order = 10, Zerotorescue@31: type = "group", Zerotorescue@31: inline = true, Zerotorescue@68: name = L["General"], Zerotorescue@31: args = { Zerotorescue@31: description = { Zerotorescue@31: order = 10, Zerotorescue@31: type = "description", Zerotorescue@31: name = function() Zerotorescue@68: local descText = L["With this button you can completely toggle this module |cff00ff00on|r or |cffff0000off|r. This setting will be remembered and the module will be automatically toggled |cff00ff00on|r or |cffff0000off|r upon logon as it was last set."] .. "\n\n"; Zerotorescue@31: Zerotorescue@31: -- Behavior info Zerotorescue@68: descText = descText .. L["|cfffed000Please note this module will only be enabled when the addon \"BeanCounter\" is enabled. This module will be disabled when BeanCounter could not be found and enabled when it can unless you manually disabled this module.|r"] .. "\n\n"; Zerotorescue@31: Zerotorescue@31: -- Final warning Zerotorescue@68: descText = descText .. L["|cffff0000You are strongly adviced to leave this module enabled unless you have very good reasons not to.|r"] .. "\n\n"; Zerotorescue@31: Zerotorescue@31: if self:IsEnabled() then Zerotorescue@68: descText = descText .. L["Status: %s"]:format(L["|cff00ff00Enabled|r"]); Zerotorescue@31: else Zerotorescue@68: descText = descText .. L["Status: %s"]:format(L["|cffff0000Disabled|r"]); Zerotorescue@31: end Zerotorescue@31: Zerotorescue@31: return descText; Zerotorescue@31: end, Zerotorescue@31: }, Zerotorescue@31: disable = { Zerotorescue@31: order = 20, Zerotorescue@31: type = "execute", Zerotorescue@31: name = function() Zerotorescue@31: if self:IsEnabled() then Zerotorescue@68: return L["Disable Module"]; Zerotorescue@31: else Zerotorescue@68: return L["Enable Module"]; Zerotorescue@31: end Zerotorescue@31: end, Zerotorescue@68: desc = L["Click here to completely toggle this module on or off."], Zerotorescue@31: width = "double", Zerotorescue@31: func = function() Zerotorescue@31: if self:IsEnabled() then Zerotorescue@31: self:Disable(); Zerotorescue@31: Zerotorescue@31: MailOpener.db.profile.modules[self:GetName()] = false; Zerotorescue@31: else Zerotorescue@31: self:Enable(); Zerotorescue@31: Zerotorescue@31: MailOpener.db.profile.modules[self:GetName()] = nil; Zerotorescue@31: end Zerotorescue@31: end, Zerotorescue@31: confirm = function() Zerotorescue@31: if self:IsEnabled() then Zerotorescue@68: return L["Are you sure you want to disable this module?\n\nIt will only be active when needed and disabling it may cause your BeanCounter data to become incomplete. Leaving it on causes no harm."]; Zerotorescue@31: else Zerotorescue@31: return false; Zerotorescue@31: end Zerotorescue@31: end, Zerotorescue@31: }, Zerotorescue@31: }, Zerotorescue@31: }, Zerotorescue@31: }, Zerotorescue@31: }; Zerotorescue@31: Zerotorescue@31: return configGroup; Zerotorescue@31: end Zerotorescue@31: Zerotorescue@31: function mod:Debug(t) Zerotorescue@31: return MailOpener:Debug("|cff993300BeanCounterSupport|r:" .. t); Zerotorescue@31: end