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