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