|
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@31
|
48 -- Hook the OnHide of refMonitoredFrame indicating BeanCounter has started
|
|
Zerotorescue@31
|
49 self:HookScript(refMonitoredFrame, "OnHide", "BeanCounterActivated");
|
|
Zerotorescue@31
|
50 end
|
|
Zerotorescue@31
|
51
|
|
Zerotorescue@31
|
52 function mod:MAIL_CLOSED()
|
|
Zerotorescue@31
|
53 self:Debug("MAIL_CLOSED");
|
|
Zerotorescue@31
|
54
|
|
Zerotorescue@31
|
55 self:UnregisterEvent("MAIL_CLOSED");
|
|
Zerotorescue@31
|
56
|
|
Zerotorescue@31
|
57 refMonitoredFrame = nil;
|
|
Zerotorescue@31
|
58
|
|
Zerotorescue@31
|
59 -- We don't need any hooks anymore
|
|
Zerotorescue@31
|
60 self:UnhookAll();
|
|
Zerotorescue@31
|
61
|
|
Zerotorescue@31
|
62 -- Make sure we don't get stuck for the entire session (restart every mailbox close)
|
|
Zerotorescue@31
|
63 if MailAddonBusy == MailAddonName then
|
|
Zerotorescue@31
|
64 MailAddonBusy = nil;
|
|
Zerotorescue@31
|
65 end
|
|
Zerotorescue@31
|
66 end
|
|
Zerotorescue@31
|
67
|
|
Zerotorescue@31
|
68 -- Called when the refMonitoredFrame is hidden
|
|
Zerotorescue@31
|
69 function mod:BeanCounterActivated()
|
|
Zerotorescue@31
|
70 if refMonitoredFrame:GetParent():IsVisible() then
|
|
Zerotorescue@31
|
71 -- Ensure this isn't called when the container is being hidden
|
|
Zerotorescue@31
|
72
|
|
Zerotorescue@31
|
73 mod:Debug("BeanCounterActivated");
|
|
Zerotorescue@31
|
74
|
|
Zerotorescue@31
|
75 -- Unhook the current hook (and reapply it after the OnShow was triggered)
|
|
Zerotorescue@31
|
76 self:Unhook(refMonitoredFrame, "OnHide");
|
|
Zerotorescue@31
|
77
|
|
Zerotorescue@31
|
78 -- Hook the OnShow of refMonitoredFrame indicating BeanCounter is finished
|
|
Zerotorescue@31
|
79 self:HookScript(refMonitoredFrame, "OnShow", "BeanCounterDeactivated");
|
|
Zerotorescue@31
|
80
|
|
Zerotorescue@31
|
81 MailAddonBusy = MailAddonName;
|
|
Zerotorescue@31
|
82 end
|
|
Zerotorescue@31
|
83 end
|
|
Zerotorescue@31
|
84
|
|
Zerotorescue@31
|
85 -- Called when the refMonitoredFrame is shown
|
|
Zerotorescue@31
|
86 function mod:BeanCounterDeactivated()
|
|
Zerotorescue@31
|
87 if refMonitoredFrame:GetParent():IsVisible() then
|
|
Zerotorescue@31
|
88 -- Ensure this isn't called when the container is being shown
|
|
Zerotorescue@31
|
89
|
|
Zerotorescue@31
|
90 mod:Debug("BeanCounterDeactivated");
|
|
Zerotorescue@31
|
91
|
|
Zerotorescue@31
|
92 -- Unhook the current hook (and reapply it after the OnHide was triggered)
|
|
Zerotorescue@31
|
93 self:Unhook(refMonitoredFrame, "OnShow");
|
|
Zerotorescue@31
|
94
|
|
Zerotorescue@31
|
95 -- Hook the OnHide of the refMonitoredFrame again which is trigged when BeanCounter starts
|
|
Zerotorescue@31
|
96 self:HookScript(refMonitoredFrame, "OnHide", "BeanCounterActivated");
|
|
Zerotorescue@31
|
97
|
|
Zerotorescue@31
|
98 if MailAddonBusy == MailAddonName then
|
|
Zerotorescue@31
|
99 MailAddonBusy = nil;
|
|
Zerotorescue@31
|
100 end
|
|
Zerotorescue@31
|
101 end
|
|
Zerotorescue@31
|
102 end
|
|
Zerotorescue@31
|
103
|
|
Zerotorescue@31
|
104 function mod:GetOptionsGroup()
|
|
Zerotorescue@31
|
105 local configGroup = {
|
|
Zerotorescue@31
|
106 order = 0,
|
|
Zerotorescue@31
|
107 type = "modulesSubGroup",
|
|
Zerotorescue@68
|
108 name = L["BeanCounter Support"],
|
|
Zerotorescue@68
|
109 desc = L["Change settings for the BeanCounter Support module."],
|
|
Zerotorescue@31
|
110 args = {
|
|
Zerotorescue@31
|
111 General = {
|
|
Zerotorescue@31
|
112 order = 10,
|
|
Zerotorescue@31
|
113 type = "group",
|
|
Zerotorescue@31
|
114 inline = true,
|
|
Zerotorescue@68
|
115 name = L["General"],
|
|
Zerotorescue@31
|
116 args = {
|
|
Zerotorescue@31
|
117 description = {
|
|
Zerotorescue@31
|
118 order = 10,
|
|
Zerotorescue@31
|
119 type = "description",
|
|
Zerotorescue@31
|
120 name = function()
|
|
Zerotorescue@68
|
121 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
|
122
|
|
Zerotorescue@31
|
123 -- Behavior info
|
|
Zerotorescue@68
|
124 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
|
125
|
|
Zerotorescue@31
|
126 -- Final warning
|
|
Zerotorescue@68
|
127 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
|
128
|
|
Zerotorescue@31
|
129 if self:IsEnabled() then
|
|
Zerotorescue@68
|
130 descText = descText .. L["Status: %s"]:format(L["|cff00ff00Enabled|r"]);
|
|
Zerotorescue@31
|
131 else
|
|
Zerotorescue@68
|
132 descText = descText .. L["Status: %s"]:format(L["|cffff0000Disabled|r"]);
|
|
Zerotorescue@31
|
133 end
|
|
Zerotorescue@31
|
134
|
|
Zerotorescue@31
|
135 return descText;
|
|
Zerotorescue@31
|
136 end,
|
|
Zerotorescue@31
|
137 },
|
|
Zerotorescue@31
|
138 disable = {
|
|
Zerotorescue@31
|
139 order = 20,
|
|
Zerotorescue@31
|
140 type = "execute",
|
|
Zerotorescue@31
|
141 name = function()
|
|
Zerotorescue@31
|
142 if self:IsEnabled() then
|
|
Zerotorescue@68
|
143 return L["Disable Module"];
|
|
Zerotorescue@31
|
144 else
|
|
Zerotorescue@68
|
145 return L["Enable Module"];
|
|
Zerotorescue@31
|
146 end
|
|
Zerotorescue@31
|
147 end,
|
|
Zerotorescue@68
|
148 desc = L["Click here to completely toggle this module on or off."],
|
|
Zerotorescue@31
|
149 width = "double",
|
|
Zerotorescue@31
|
150 func = function()
|
|
Zerotorescue@31
|
151 if self:IsEnabled() then
|
|
Zerotorescue@31
|
152 self:Disable();
|
|
Zerotorescue@31
|
153
|
|
Zerotorescue@31
|
154 MailOpener.db.profile.modules[self:GetName()] = false;
|
|
Zerotorescue@31
|
155 else
|
|
Zerotorescue@31
|
156 self:Enable();
|
|
Zerotorescue@31
|
157
|
|
Zerotorescue@31
|
158 MailOpener.db.profile.modules[self:GetName()] = nil;
|
|
Zerotorescue@31
|
159 end
|
|
Zerotorescue@31
|
160 end,
|
|
Zerotorescue@31
|
161 confirm = function()
|
|
Zerotorescue@31
|
162 if self:IsEnabled() then
|
|
Zerotorescue@68
|
163 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
|
164 else
|
|
Zerotorescue@31
|
165 return false;
|
|
Zerotorescue@31
|
166 end
|
|
Zerotorescue@31
|
167 end,
|
|
Zerotorescue@31
|
168 },
|
|
Zerotorescue@31
|
169 },
|
|
Zerotorescue@31
|
170 },
|
|
Zerotorescue@31
|
171 },
|
|
Zerotorescue@31
|
172 };
|
|
Zerotorescue@31
|
173
|
|
Zerotorescue@31
|
174 return configGroup;
|
|
Zerotorescue@31
|
175 end
|
|
Zerotorescue@31
|
176
|
|
Zerotorescue@31
|
177 function mod:Debug(t)
|
|
Zerotorescue@31
|
178 return MailOpener:Debug("|cff993300BeanCounterSupport|r:" .. t);
|
|
Zerotorescue@31
|
179 end |