annotate Modules/BeanCounterSupport.lua @ 36:a918ec27126f

Tagging as v1.1.0
author Zerotorescue
date Sat, 11 Sep 2010 00:17:31 +0200
parents 90d58723ac0a
children eadff31e61e8
rev   line source
Zerotorescue@31 1 local MailOpener = LibStub("AceAddon-3.0"):GetAddon("MailOpener");
Zerotorescue@31 2 local mod = MailOpener:NewModule("BeanCounterSupport", "AceEvent-3.0", "AceHook-3.0");
Zerotorescue@31 3
Zerotorescue@31 4 mod.moduleDescription = "Prevents mail opening while BeanCounter is still scanning. Does nothing when BeanCounter is disabled.";
Zerotorescue@31 5 mod.moduleRequired = false;
Zerotorescue@31 6
Zerotorescue@31 7 local MailAddonName = "BeanCounter"; -- what to fill the global MailAddonBusy with
Zerotorescue@31 8 local refMonitoredFrame; -- reference to the frame we will be monitoring
Zerotorescue@31 9
Zerotorescue@31 10 function mod:OnInitialize()
Zerotorescue@31 11 if select(6, GetAddOnInfo("BeanCounter")) ~= nil then
Zerotorescue@31 12 -- BeanCounter is DISABLED, so we don't need this module
Zerotorescue@31 13 self:Debug("Disabling");
Zerotorescue@31 14 self:SetEnabledState(false);
Zerotorescue@31 15
Zerotorescue@31 16 if self:IsEnabled() then
Zerotorescue@31 17 self:Disable();
Zerotorescue@31 18 end
Zerotorescue@31 19 end
Zerotorescue@31 20 end
Zerotorescue@31 21
Zerotorescue@31 22 function mod:OnEnable()
Zerotorescue@31 23 self:Debug("OnEnable");
Zerotorescue@31 24
Zerotorescue@31 25 self:RegisterEvent("MAIL_SHOW");
Zerotorescue@31 26
Zerotorescue@31 27 -- If we were toggling this module on while the mailbox is opened we must register all events again
Zerotorescue@31 28 if MailFrame:IsVisible() then
Zerotorescue@31 29 self:MAIL_SHOW();
Zerotorescue@31 30 end
Zerotorescue@31 31 end
Zerotorescue@31 32
Zerotorescue@31 33 -- Even though Ace can unregister our events it's neater to do it manually too
Zerotorescue@31 34 function mod:OnDisable()
Zerotorescue@31 35 self:Debug("OnDisable");
Zerotorescue@31 36
Zerotorescue@31 37 self:UnregisterEvent("MAIL_SHOW");
Zerotorescue@31 38 end
Zerotorescue@31 39
Zerotorescue@31 40 function mod:MAIL_SHOW()
Zerotorescue@31 41 self:Debug("MAIL_SHOW");
Zerotorescue@31 42
Zerotorescue@31 43 self:RegisterEvent("MAIL_CLOSED");
Zerotorescue@31 44
Zerotorescue@31 45 refMonitoredFrame = InboxCloseButton;
Zerotorescue@31 46
Zerotorescue@31 47 -- Hook the OnHide of refMonitoredFrame indicating BeanCounter has started
Zerotorescue@31 48 self:HookScript(refMonitoredFrame, "OnHide", "BeanCounterActivated");
Zerotorescue@31 49 end
Zerotorescue@31 50
Zerotorescue@31 51 function mod:MAIL_CLOSED()
Zerotorescue@31 52 self:Debug("MAIL_CLOSED");
Zerotorescue@31 53
Zerotorescue@31 54 self:UnregisterEvent("MAIL_CLOSED");
Zerotorescue@31 55
Zerotorescue@31 56 refMonitoredFrame = nil;
Zerotorescue@31 57
Zerotorescue@31 58 -- We don't need any hooks anymore
Zerotorescue@31 59 self:UnhookAll();
Zerotorescue@31 60
Zerotorescue@31 61 -- Make sure we don't get stuck for the entire session (restart every mailbox close)
Zerotorescue@31 62 if MailAddonBusy == MailAddonName then
Zerotorescue@31 63 MailAddonBusy = nil;
Zerotorescue@31 64 end
Zerotorescue@31 65 end
Zerotorescue@31 66
Zerotorescue@31 67 -- Called when the refMonitoredFrame is hidden
Zerotorescue@31 68 function mod:BeanCounterActivated()
Zerotorescue@31 69 if refMonitoredFrame:GetParent():IsVisible() then
Zerotorescue@31 70 -- Ensure this isn't called when the container is being hidden
Zerotorescue@31 71
Zerotorescue@31 72 mod:Debug("BeanCounterActivated");
Zerotorescue@31 73
Zerotorescue@31 74 -- Unhook the current hook (and reapply it after the OnShow was triggered)
Zerotorescue@31 75 self:Unhook(refMonitoredFrame, "OnHide");
Zerotorescue@31 76
Zerotorescue@31 77 -- Hook the OnShow of refMonitoredFrame indicating BeanCounter is finished
Zerotorescue@31 78 self:HookScript(refMonitoredFrame, "OnShow", "BeanCounterDeactivated");
Zerotorescue@31 79
Zerotorescue@31 80 MailAddonBusy = MailAddonName;
Zerotorescue@31 81 end
Zerotorescue@31 82 end
Zerotorescue@31 83
Zerotorescue@31 84 -- Called when the refMonitoredFrame is shown
Zerotorescue@31 85 function mod:BeanCounterDeactivated()
Zerotorescue@31 86 if refMonitoredFrame:GetParent():IsVisible() then
Zerotorescue@31 87 -- Ensure this isn't called when the container is being shown
Zerotorescue@31 88
Zerotorescue@31 89 mod:Debug("BeanCounterDeactivated");
Zerotorescue@31 90
Zerotorescue@31 91 -- Unhook the current hook (and reapply it after the OnHide was triggered)
Zerotorescue@31 92 self:Unhook(refMonitoredFrame, "OnShow");
Zerotorescue@31 93
Zerotorescue@31 94 -- Hook the OnHide of the refMonitoredFrame again which is trigged when BeanCounter starts
Zerotorescue@31 95 self:HookScript(refMonitoredFrame, "OnHide", "BeanCounterActivated");
Zerotorescue@31 96
Zerotorescue@31 97 if MailAddonBusy == MailAddonName then
Zerotorescue@31 98 MailAddonBusy = nil;
Zerotorescue@31 99 end
Zerotorescue@31 100 end
Zerotorescue@31 101 end
Zerotorescue@31 102
Zerotorescue@31 103 function mod:GetOptionsGroup()
Zerotorescue@31 104 local configGroup = {
Zerotorescue@31 105 order = 0,
Zerotorescue@31 106 type = "modulesSubGroup",
Zerotorescue@31 107 name = "BeanCounter Support",
Zerotorescue@31 108 desc = "Change settings for the BeanCounter Support module.",
Zerotorescue@31 109 args = {
Zerotorescue@31 110 General = {
Zerotorescue@31 111 order = 10,
Zerotorescue@31 112 type = "group",
Zerotorescue@31 113 inline = true,
Zerotorescue@31 114 name = "General",
Zerotorescue@31 115 args = {
Zerotorescue@31 116 description = {
Zerotorescue@31 117 order = 10,
Zerotorescue@31 118 type = "description",
Zerotorescue@31 119 name = function()
Zerotorescue@31 120 local descText = "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 121
Zerotorescue@31 122 -- Behavior info
Zerotorescue@31 123 descText = descText .. "|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 124
Zerotorescue@31 125 -- Final warning
Zerotorescue@31 126 descText = descText .. "|cffff0000You are strongly adviced to leave this module enabled unless you have very good reasons not to.|r\n\n";
Zerotorescue@31 127
Zerotorescue@31 128 if self:IsEnabled() then
Zerotorescue@31 129 descText = descText .. "Status: |cff00ff00Enabled|r";
Zerotorescue@31 130 else
Zerotorescue@31 131 descText = descText .. "Status: |cffff0000Disabled|r";
Zerotorescue@31 132 end
Zerotorescue@31 133
Zerotorescue@31 134 return descText;
Zerotorescue@31 135 end,
Zerotorescue@31 136 },
Zerotorescue@31 137 disable = {
Zerotorescue@31 138 order = 20,
Zerotorescue@31 139 type = "execute",
Zerotorescue@31 140 name = function()
Zerotorescue@31 141 if self:IsEnabled() then
Zerotorescue@31 142 return "Disable Module";
Zerotorescue@31 143 else
Zerotorescue@31 144 return "Enable Module";
Zerotorescue@31 145 end
Zerotorescue@31 146 end,
Zerotorescue@31 147 desc = "Click here to completely toggle this module on or off.",
Zerotorescue@31 148 width = "double",
Zerotorescue@31 149 func = function()
Zerotorescue@31 150 if self:IsEnabled() then
Zerotorescue@31 151 self:Disable();
Zerotorescue@31 152
Zerotorescue@31 153 MailOpener.db.profile.modules[self:GetName()] = false;
Zerotorescue@31 154 else
Zerotorescue@31 155 self:Enable();
Zerotorescue@31 156
Zerotorescue@31 157 MailOpener.db.profile.modules[self:GetName()] = nil;
Zerotorescue@31 158 end
Zerotorescue@31 159 end,
Zerotorescue@31 160 confirm = function()
Zerotorescue@31 161 if self:IsEnabled() then
Zerotorescue@31 162 return "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 163 else
Zerotorescue@31 164 return false;
Zerotorescue@31 165 end
Zerotorescue@31 166 end,
Zerotorescue@31 167 },
Zerotorescue@31 168 },
Zerotorescue@31 169 },
Zerotorescue@31 170 },
Zerotorescue@31 171 };
Zerotorescue@31 172
Zerotorescue@31 173 return configGroup;
Zerotorescue@31 174 end
Zerotorescue@31 175
Zerotorescue@31 176 function mod:Debug(t)
Zerotorescue@31 177 return MailOpener:Debug("|cff993300BeanCounterSupport|r:" .. t);
Zerotorescue@31 178 end