annotate Libs/AceEvent-3.0/AceEvent-3.0.lua @ 8:1b2d819b4fa8

Now using the global MailAddonBusy to indicate MailOpener is busy, read comments in Core.lua for more info. Default status is now ?enabled without automatic mail opening? to let first time users look around before MailOpener messes up their heads. A StaticPopupDialog will be added later to ask if they want to auto-enable. When ?enabled without automatic mail opening? is on and you toggle the mail opening checkbox on, mail opening will automatically start.
author Zerotorescue
date Thu, 09 Sep 2010 10:53:19 +0200
parents 823e33465b6e
children
rev   line source
Zerotorescue@0 1 --- AceEvent-3.0 provides event registration and secure dispatching.
Zerotorescue@0 2 -- All dispatching is done using **CallbackHandler-1.0**. AceEvent is a simple wrapper around
Zerotorescue@0 3 -- CallbackHandler, and dispatches all game events or addon message to the registrees.
Zerotorescue@0 4 --
Zerotorescue@0 5 -- **AceEvent-3.0** can be embeded into your addon, either explicitly by calling AceEvent:Embed(MyAddon) or by
Zerotorescue@0 6 -- specifying it as an embeded library in your AceAddon. All functions will be available on your addon object
Zerotorescue@0 7 -- and can be accessed directly, without having to explicitly call AceEvent itself.\\
Zerotorescue@0 8 -- It is recommended to embed AceEvent, otherwise you'll have to specify a custom `self` on all calls you
Zerotorescue@0 9 -- make into AceEvent.
Zerotorescue@0 10 -- @class file
Zerotorescue@0 11 -- @name AceEvent-3.0
Zerotorescue@0 12 -- @release $Id: AceEvent-3.0.lua 877 2009-11-02 15:56:50Z nevcairiel $
Zerotorescue@0 13 local MAJOR, MINOR = "AceEvent-3.0", 3
Zerotorescue@0 14 local AceEvent = LibStub:NewLibrary(MAJOR, MINOR)
Zerotorescue@0 15
Zerotorescue@0 16 if not AceEvent then return end
Zerotorescue@0 17
Zerotorescue@0 18 -- Lua APIs
Zerotorescue@0 19 local pairs = pairs
Zerotorescue@0 20
Zerotorescue@0 21 local CallbackHandler = LibStub:GetLibrary("CallbackHandler-1.0")
Zerotorescue@0 22
Zerotorescue@0 23 AceEvent.frame = AceEvent.frame or CreateFrame("Frame", "AceEvent30Frame") -- our event frame
Zerotorescue@0 24 AceEvent.embeds = AceEvent.embeds or {} -- what objects embed this lib
Zerotorescue@0 25
Zerotorescue@0 26 -- APIs and registry for blizzard events, using CallbackHandler lib
Zerotorescue@0 27 if not AceEvent.events then
Zerotorescue@0 28 AceEvent.events = CallbackHandler:New(AceEvent,
Zerotorescue@0 29 "RegisterEvent", "UnregisterEvent", "UnregisterAllEvents")
Zerotorescue@0 30 end
Zerotorescue@0 31
Zerotorescue@0 32 function AceEvent.events:OnUsed(target, eventname)
Zerotorescue@0 33 AceEvent.frame:RegisterEvent(eventname)
Zerotorescue@0 34 end
Zerotorescue@0 35
Zerotorescue@0 36 function AceEvent.events:OnUnused(target, eventname)
Zerotorescue@0 37 AceEvent.frame:UnregisterEvent(eventname)
Zerotorescue@0 38 end
Zerotorescue@0 39
Zerotorescue@0 40
Zerotorescue@0 41 -- APIs and registry for IPC messages, using CallbackHandler lib
Zerotorescue@0 42 if not AceEvent.messages then
Zerotorescue@0 43 AceEvent.messages = CallbackHandler:New(AceEvent,
Zerotorescue@0 44 "RegisterMessage", "UnregisterMessage", "UnregisterAllMessages"
Zerotorescue@0 45 )
Zerotorescue@0 46 AceEvent.SendMessage = AceEvent.messages.Fire
Zerotorescue@0 47 end
Zerotorescue@0 48
Zerotorescue@0 49 --- embedding and embed handling
Zerotorescue@0 50 local mixins = {
Zerotorescue@0 51 "RegisterEvent", "UnregisterEvent",
Zerotorescue@0 52 "RegisterMessage", "UnregisterMessage",
Zerotorescue@0 53 "SendMessage",
Zerotorescue@0 54 "UnregisterAllEvents", "UnregisterAllMessages",
Zerotorescue@0 55 }
Zerotorescue@0 56
Zerotorescue@0 57 --- Register for a Blizzard Event.
Zerotorescue@0 58 -- The callback will always be called with the event as the first argument, and if supplied, the `arg` as second argument.
Zerotorescue@0 59 -- Any arguments to the event will be passed on after that.
Zerotorescue@0 60 -- @name AceEvent:RegisterEvent
Zerotorescue@0 61 -- @class function
Zerotorescue@0 62 -- @paramsig event[, callback [, arg]]
Zerotorescue@0 63 -- @param event The event to register for
Zerotorescue@0 64 -- @param callback The callback function to call when the event is triggered (funcref or method, defaults to a method with the event name)
Zerotorescue@0 65 -- @param arg An optional argument to pass to the callback function
Zerotorescue@0 66
Zerotorescue@0 67 --- Unregister an event.
Zerotorescue@0 68 -- @name AceEvent:UnregisterEvent
Zerotorescue@0 69 -- @class function
Zerotorescue@0 70 -- @paramsig event
Zerotorescue@0 71 -- @param event The event to unregister
Zerotorescue@0 72
Zerotorescue@0 73 --- Register for a custom AceEvent-internal message.
Zerotorescue@0 74 -- The callback will always be called with the event as the first argument, and if supplied, the `arg` as second argument.
Zerotorescue@0 75 -- Any arguments to the event will be passed on after that.
Zerotorescue@0 76 -- @name AceEvent:RegisterMessage
Zerotorescue@0 77 -- @class function
Zerotorescue@0 78 -- @paramsig message[, callback [, arg]]
Zerotorescue@0 79 -- @param message The message to register for
Zerotorescue@0 80 -- @param callback The callback function to call when the message is triggered (funcref or method, defaults to a method with the event name)
Zerotorescue@0 81 -- @param arg An optional argument to pass to the callback function
Zerotorescue@0 82
Zerotorescue@0 83 --- Unregister a message
Zerotorescue@0 84 -- @name AceEvent:UnregisterMessage
Zerotorescue@0 85 -- @class function
Zerotorescue@0 86 -- @paramsig message
Zerotorescue@0 87 -- @param message The message to unregister
Zerotorescue@0 88
Zerotorescue@0 89 --- Send a message over the AceEvent-3.0 internal message system to other addons registered for this message.
Zerotorescue@0 90 -- @name AceEvent:SendMessage
Zerotorescue@0 91 -- @class function
Zerotorescue@0 92 -- @paramsig message, ...
Zerotorescue@0 93 -- @param message The message to send
Zerotorescue@0 94 -- @param ... Any arguments to the message
Zerotorescue@0 95
Zerotorescue@0 96
Zerotorescue@0 97 -- Embeds AceEvent into the target object making the functions from the mixins list available on target:..
Zerotorescue@0 98 -- @param target target object to embed AceEvent in
Zerotorescue@0 99 function AceEvent:Embed(target)
Zerotorescue@0 100 for k, v in pairs(mixins) do
Zerotorescue@0 101 target[v] = self[v]
Zerotorescue@0 102 end
Zerotorescue@0 103 self.embeds[target] = true
Zerotorescue@0 104 return target
Zerotorescue@0 105 end
Zerotorescue@0 106
Zerotorescue@0 107 -- AceEvent:OnEmbedDisable( target )
Zerotorescue@0 108 -- target (object) - target object that is being disabled
Zerotorescue@0 109 --
Zerotorescue@0 110 -- Unregister all events messages etc when the target disables.
Zerotorescue@0 111 -- this method should be called by the target manually or by an addon framework
Zerotorescue@0 112 function AceEvent:OnEmbedDisable(target)
Zerotorescue@0 113 target:UnregisterAllEvents()
Zerotorescue@0 114 target:UnregisterAllMessages()
Zerotorescue@0 115 end
Zerotorescue@0 116
Zerotorescue@0 117 -- Script to fire blizzard events into the event listeners
Zerotorescue@0 118 local events = AceEvent.events
Zerotorescue@0 119 AceEvent.frame:SetScript("OnEvent", function(this, event, ...)
Zerotorescue@0 120 events:Fire(event, ...)
Zerotorescue@0 121 end)
Zerotorescue@0 122
Zerotorescue@0 123 --- Finally: upgrade our old embeds
Zerotorescue@0 124 for target, v in pairs(AceEvent.embeds) do
Zerotorescue@0 125 AceEvent:Embed(target)
Zerotorescue@0 126 end