diff --git a/!Compatibility/api/wowAPI.lua b/!Compatibility/api/wowAPI.lua index 6d4e4a6..fa6a2bf 100644 --- a/!Compatibility/api/wowAPI.lua +++ b/!Compatibility/api/wowAPI.lua @@ -7,7 +7,7 @@ local select = select local tonumber = tonumber local type = type local unpack = unpack -local find, format, gmatch, gsub, lower, match, upper = string.find, string.format, string.gmatch, string.gsub, string.lower, string.match, string.upper +local find, format, gmatch, gsub, len, lower, match, upper, sub = string.find, string.format, string.gmatch, string.gsub, string.len, string.lower, string.match, string.upper, string.sub local getn = table.getn --WoW API local debugstack = debugstack @@ -412,6 +412,80 @@ function CreateStatusBarTexturePointer(statusbar) return f end +local function removeScript(self, script) + local func = self:GetScript(script) + + if func then + self:SetScript(script, nil) + end + + return func +end + +local nbsp = string.char(255) +function EditBoxGetCursorPosition(self) + if self == WowLuaFrameEditBox or self == WowLuaFrameCommandEditBox then return 0 end + + if self:GetText() == "" then return 0 end + + local occ = removeScript(self, "OnCursorChanged") + local otc = removeScript(self, "OnTextChanged") + local ots = removeScript(self, "OnTextSet") + + self:Insert(nbsp) + + local pos = find(self:GetText(), nbsp) + if not pos then + pos = len(self:GetText()) + print(format("CursorPosition position for `%s` not found!", self.GetName and self:GetName() or tostring(self))) + else + self:HighlightText(pos - 1, pos) + self:Insert("") + end + + if occ then self:SetScript("OnCursorChanged", occ) end + if otc then self:SetScript("OnTextChanged", otc) end + if ots then self:SetScript("OnTextSet", ots) end + + return pos - 1 +end + +function EditBoxSetCursorPosition(self, pos) + if self == WowLuaFrameEditBox or self == WowLuaFrameCommandEditBox then return end + + if self:GetText() == "" then return end + + local occ = removeScript(self, "OnCursorChanged") + local otc = removeScript(self, "OnTextChanged") + local ots = removeScript(self, "OnTextSet") + + local text = self:GetText() + local size = len(text) + + if pos < 0 then + pos = 0 + elseif pos > size then + pos = size + end + + if pos == 0 then + text = sub(text, 0, 1) + self:HighlightText(0, 1) + self:Insert(nbsp) + self:Insert(text) + self:HighlightText(0, 1) + self:Insert("") + else + text = sub(text, pos, pos) + self:HighlightText(pos - 1, pos) + self:Insert(text) + end + + if occ then self:SetScript("OnCursorChanged", occ) end + if otc then self:SetScript("OnTextChanged", otc) end + if ots then self:SetScript("OnTextSet", ots) end +end + local threatColors = { [0] = {0.69, 0.69, 0.69}, [1] = {1, 1, 0.47}, diff --git a/!DebugTools/Blizzard_DebugTools.lua b/!DebugTools/Blizzard_DebugTools.lua index 3b0c15d..80bb25a 100644 --- a/!DebugTools/Blizzard_DebugTools.lua +++ b/!DebugTools/Blizzard_DebugTools.lua @@ -590,8 +590,8 @@ function ScriptErrorsFrame_Update () editBox.text = text; if (prevText ~= text) then editBox:SetText(text); + EditBoxSetCursorPosition(editBox, 0); editBox:HighlightText(0); --- editBox:SetCursorPosition(0); else ScriptErrorsFrameScrollFrame:UpdateScrollChildRect(); end diff --git a/ElvUI/Core/Commands.lua b/ElvUI/Core/Commands.lua index bbff357..9f1e435 100644 --- a/ElvUI/Core/Commands.lua +++ b/ElvUI/Core/Commands.lua @@ -114,7 +114,7 @@ function E:DelayScriptCall(msg) self:Print("usage: /in ") self:Print("example: /in 1.5 /say hi") else - E:ScheduleTimer(OnCallback, secs, 1, command) + E:ScheduleTimer(OnCallback, secs, command) end end diff --git a/ElvUI/Libraries/AceAddon-3.0/AceAddon-3.0.lua b/ElvUI/Libraries/AceAddon-3.0/AceAddon-3.0.lua index cc99899..3d85c6f 100644 --- a/ElvUI/Libraries/AceAddon-3.0/AceAddon-3.0.lua +++ b/ElvUI/Libraries/AceAddon-3.0/AceAddon-3.0.lua @@ -35,10 +35,6 @@ local AceAddon, oldminor = LibStub:NewLibrary(MAJOR, MINOR) if not AceAddon then return end -- No Upgrade needed. -local AceCore = LibStub("AceCore-3.0") -local new, del = AceCore.new, AceCore.del -local wipe, truncate = AceCore.wipe, AceCore.truncate - AceAddon.frame = AceAddon.frame or CreateFrame("Frame", "AceAddon30Frame") -- Our very own frame AceAddon.addons = AceAddon.addons or {} -- addons in general AceAddon.statuses = AceAddon.statuses or {} -- statuses of addon. @@ -47,8 +43,8 @@ AceAddon.enablequeue = AceAddon.enablequeue or {} -- addons that are initialized AceAddon.embeds = AceAddon.embeds or setmetatable({}, {__index = function(tbl, key) tbl[key] = {} return tbl[key] end }) -- contains a list of libraries embedded in an addon -- Lua APIs -local tinsert, tconcat, tremove, tgetn = table.insert, table.concat, table.remove, table.getn -local strfmt, tostring = string.format, tostring +local tinsert, tconcat, tremove, getn = table.insert, table.concat, table.remove, table.getn +local fmt, gsub, tostring = string.format, string.gsub, tostring local pairs, next, type, unpack = pairs, next, type, unpack local loadstring, assert, error = loadstring, assert, error local setmetatable, getmetatable, rawset, rawget = setmetatable, getmetatable, rawset, rawget @@ -60,7 +56,51 @@ local setmetatable, getmetatable, rawset, rawget = setmetatable, getmetatable, r --[[ xpcall safecall implementation ]] -local safecall = AceCore.safecall +local xpcall = xpcall + +local function errorhandler(err) + return geterrorhandler()(err) +end + +local function CreateDispatcher(argCount) + local code = [[ + local xpcall, eh = xpcall, function(err) return geterrorhandler()(err) end + local method, ARGS + local function call() return method(ARGS) end + + local function dispatch(func, ...) + method = func + if not method then return end + ARGS = unpack(arg) + return xpcall(call, eh) + end + + return dispatch + ]] + + local ARGS = {} + for i = 1, argCount do ARGS[i] = "arg"..i end + code = gsub(code,"ARGS", tconcat(ARGS, ", ")) + return assert(loadstring(code, "safecall Dispatcher["..argCount.."]"))(xpcall, errorhandler) +end + +local Dispatchers = setmetatable({}, {__index=function(self, argCount) + local dispatcher = CreateDispatcher(argCount) + rawset(self, argCount, dispatcher) + return dispatcher +end}) +Dispatchers[0] = function(func) + return xpcall(func, errorhandler) +end + +local function safecall(func, ...) + -- we check to see if the func is passed is actually a function here and don't error when it isn't + -- this safecall is used for optional functions like OnInitialize OnEnable etc. When they are not + -- present execution should continue without hinderance + if type(func) == "function" then + return Dispatchers[arg.n](func, unpack(arg)) + end +end -- local functions that will be implemented further down local Enable, Disable, EnableModule, DisableModule, Embed, NewModule, GetModule, GetName, SetDefaultModuleState, SetDefaultModuleLibraries, SetEnabledState, SetDefaultModulePrototype @@ -70,7 +110,7 @@ local function addontostring( self ) return self.name end -- Check if the addon is queued for initialization local function queuedForInitialization(addon) - for i = 1, tgetn(AceAddon.initializequeue) do + for i = 1, getn(AceAddon.initializequeue) do if AceAddon.initializequeue[i] == addon then return true end @@ -93,34 +133,23 @@ end -- -- Create a Addon object based on the table of a frame -- local MyFrame = CreateFrame("Frame") -- MyAddon = LibStub("AceAddon-3.0"):NewAddon(MyFrame, "MyAddon", "AceEvent-3.0") -function AceAddon:NewAddon(objectorname,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) - +function AceAddon:NewAddon(objectorname, ...) local object,name + local i=1 if type(objectorname)=="table" then object=objectorname - name=a0 + name=arg[1] + i=2 else name=objectorname end if type(name)~="string" then - error(strfmt("Usage: NewAddon([object,] name, [lib, lib, lib, ...]): 'name' - string expected got '%s'.", type(name)), 2) + error(fmt("Usage: NewAddon([object,] name, [lib, lib, lib, ...]): 'name' - string expected got '%s'.", type(name)), 2) end if self.addons[name] then - error(strfmt("Usage: NewAddon([object,] name, [lib, lib, lib, ...]): 'name' - Addon '%s' already exists.", name), 2) + error(fmt("Usage: NewAddon([object,] name, [lib, lib, lib, ...]): 'name' - Addon '%s' already exists.", name), 2) end - local args = new() - args[1] = a1 - args[2] = a2 - args[3] = a3 - args[4] = a4 - args[5] = a5 - args[6] = a6 - args[7] = a7 - args[8] = a8 - args[9] = a9 - args[10] = a10 - object = object or {} object.name = name @@ -137,18 +166,20 @@ function AceAddon:NewAddon(objectorname,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) object.orderedModules = {} object.defaultModuleLibraries = {} Embed( object ) -- embed NewModule, GetModule methods - if type(objectorname)=="table" then - self:EmbedLibraries(object,nil,args) - elseif a0 then - self:EmbedLibraries(object,a0,args) + + if i == 1 then + self:EmbedLibraries(object, unpack(arg)) + else + table.remove(arg, 1) + self:EmbedLibraries(object, unpack(arg)) end - del(args) -- add to queue of addons to be initialized upon ADDON_LOADED tinsert(self.initializequeue, object) return object end + --- Get the addon object by its name from the internal AceAddon registry. -- Throws an error if the addon object cannot be found (except if silent is set). -- @param name unique name of the addon object @@ -158,7 +189,7 @@ end -- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") function AceAddon:GetAddon(name, silent) if not silent and not self.addons[name] then - error(strfmt("Usage: GetAddon(name): 'name' - Cannot find an AceAddon '%s'.", tostring(name)), 2) + error(fmt("Usage: GetAddon(name): 'name' - Cannot find an AceAddon '%s'.", tostring(name)), 2) end return self.addons[name] end @@ -171,12 +202,10 @@ end -- @paramsig addon, [lib, ...] -- @param addon addon object to embed the libs in -- @param lib List of libraries to embed into the addon -function AceAddon:EmbedLibraries(addon,a1,arg) - if a1 then self:EmbedLibrary(addon, a1, false, 4) end - -- 10 is the max number of variable arguments in the function NewAddon and NewModule - for i=1,10 do - if not arg[i] then return end - self:EmbedLibrary(addon, arg[i], false, 4) +function AceAddon:EmbedLibraries(addon, ...) + for i=1,arg.n do + local libname = arg[i] + self:EmbedLibrary(addon, libname, false, 4) end end @@ -194,13 +223,13 @@ end function AceAddon:EmbedLibrary(addon, libname, silent, offset) local lib = LibStub:GetLibrary(libname, true) if not lib and not silent then - error(strfmt("Usage: EmbedLibrary(addon, libname, silent, offset): 'libname' - Cannot find a library instance of %q.", tostring(libname)), offset or 2) + error(fmt("Usage: EmbedLibrary(addon, libname, silent, offset): 'libname' - Cannot find a library instance of %q.", tostring(libname)), offset or 2) elseif lib and type(lib.Embed) == "function" then lib:Embed(addon) tinsert(self.embeds[addon], libname) return true elseif lib then - error(strfmt("Usage: EmbedLibrary(addon, libname, silent, offset): 'libname' - Library '%s' is not Embed capable", libname), offset or 2) + error(fmt("Usage: EmbedLibrary(addon, libname, silent, offset): 'libname' - Library '%s' is not Embed capable", libname), offset or 2) end end @@ -217,7 +246,7 @@ end -- MyModule = MyAddon:GetModule("MyModule") function GetModule(self, name, silent) if not self.modules[name] and not silent then - error(strfmt("Usage: GetModule(name, silent): 'name' - Cannot find module '%s'.", tostring(name)), 2) + error(fmt("Usage: GetModule(name, silent): 'name' - Cannot find module '%s'.", tostring(name)), 2) end return self.modules[name] end @@ -240,39 +269,26 @@ local function IsModuleTrue(self) return true end -- -- Create a module with a prototype -- local prototype = { OnEnable = function(self) print("OnEnable called!") end } -- MyModule = MyAddon:NewModule("MyModule", prototype, "AceEvent-3.0", "AceHook-3.0") -function NewModule(self, name, prototype, a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) - if type(name) ~= "string" then error(strfmt("Usage: NewModule(name, [prototype, [lib, lib, lib, ...]): 'name' - string expected got '%s'.", type(name)), 2) end - if type(prototype) ~= "string" and type(prototype) ~= "table" and type(prototype) ~= "nil" then error(strfmt("Usage: NewModule(name, [prototype, [lib, lib, lib, ...]): 'prototype' - table (prototype), string (lib) or nil expected got '%s'.", type(prototype)), 2) end +function NewModule(self, name, prototype, ...) + if type(name) ~= "string" then error(fmt("Usage: NewModule(name, [prototype, [lib, lib, lib, ...]): 'name' - string expected got '%s'.", type(name)), 2) end + if type(prototype) ~= "string" and type(prototype) ~= "table" and type(prototype) ~= "nil" then error(fmt("Usage: NewModule(name, [prototype, [lib, lib, lib, ...]): 'prototype' - table (prototype), string (lib) or nil expected got '%s'.", type(prototype)), 2) end - if self.modules[name] then error(strfmt("Usage: NewModule(name, [prototype, [lib, lib, lib, ...]): 'name' - Module '%s' already exists.", name), 2) end + if self.modules[name] then error(fmt("Usage: NewModule(name, [prototype, [lib, lib, lib, ...]): 'name' - Module '%s' already exists.", name), 2) end -- modules are basically addons. We treat them as such. They will be added to the initializequeue properly as well. -- NewModule can only be called after the parent addon is present thus the modules will be initialized after their parent is. - local module = AceAddon:NewAddon(strfmt("%s_%s", self.name or tostring(self), name)) + local module = AceAddon:NewAddon(fmt("%s_%s", self.name or tostring(self), name)) module.IsModule = IsModuleTrue module:SetEnabledState(self.defaultModuleState) module.moduleName = name - local args = new() - args[1] = a1 - args[2] = a2 - args[3] = a3 - args[4] = a4 - args[5] = a5 - args[6] = a6 - args[7] = a7 - args[8] = a8 - args[9] = a9 - args[10] = a10 - if type(prototype) == "string" then - AceAddon:EmbedLibraries(module, prototype, args) + AceAddon:EmbedLibraries(module, prototype, unpack(arg)) else - AceAddon:EmbedLibraries(module, nil, args) + AceAddon:EmbedLibraries(module, unpack(arg)) end - del(args) - AceAddon:EmbedLibraries(module, nil, self.defaultModuleLibraries) + AceAddon:EmbedLibraries(module, unpack(self.defaultModuleLibraries)) if not prototype or type(prototype) == "string" then prototype = self.defaultModulePrototype or nil @@ -284,7 +300,7 @@ function NewModule(self, name, prototype, a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) setmetatable(module, mt) -- More of a Base class type feel. end - safecall(self.OnModuleCreated, 2, self, module) -- Was in Ace2 and I think it could be a cool thing to have handy. + safecall(self.OnModuleCreated, self, module) -- Was in Ace2 and I think it could be a cool thing to have handy. self.modules[name] = module tinsert(self.orderedModules, module) @@ -385,23 +401,11 @@ end -- MyAddon:SetDefaultModuleLibraries("AceEvent-3.0") -- -- Create a module -- MyModule = MyAddon:NewModule("MyModule") -function SetDefaultModuleLibraries(self,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) +function SetDefaultModuleLibraries(self, ...) if next(self.modules) then error("Usage: SetDefaultModuleLibraries(...): cannot change the module defaults after a module has been registered.", 2) end - local args = self.defaultModuleLibraries or {} - args[1] = a1 - args[2] = a2 - args[3] = a3 - args[4] = a4 - args[5] = a5 - args[6] = a6 - args[7] = a7 - args[8] = a8 - args[9] = a9 - args[10] = a10 - - self.defaultModuleLibraries = args + self.defaultModuleLibraries = arg end --- Set the default state in which new modules are being created. @@ -444,7 +448,7 @@ function SetDefaultModulePrototype(self, prototype) error("Usage: SetDefaultModulePrototype(prototype): cannot change the module defaults after a module has been registered.", 2) end if type(prototype) ~= "table" then - error(strfmt("Usage: SetDefaultModulePrototype(prototype): 'prototype' - table expected got '%s'.", type(prototype)), 2) + error(fmt("Usage: SetDefaultModulePrototype(prototype): 'prototype' - table expected got '%s'.", type(prototype)), 2) end self.defaultModulePrototype = prototype end @@ -528,12 +532,12 @@ end -- **Note:** Do not call this function manually, unless you're absolutely sure that you know what you are doing. -- @param addon addon object to intialize function AceAddon:InitializeAddon(addon) - safecall(addon.OnInitialize, 1, addon) + safecall(addon.OnInitialize, addon) local embeds = self.embeds[addon] - for i = 1, tgetn(embeds) do + for i = 1, getn(embeds) do local lib = LibStub:GetLibrary(embeds[i], true) - if lib then safecall(lib.OnEmbedInitialize, 2, lib, addon) end + if lib then safecall(lib.OnEmbedInitialize, lib, addon) end end -- we don't call InitializeAddon on modules specifically, this is handled @@ -557,19 +561,19 @@ function AceAddon:EnableAddon(addon) -- set the statuses first, before calling the OnEnable. this allows for Disabling of the addon in OnEnable. self.statuses[addon.name] = true - safecall(addon.OnEnable, 1, addon) + safecall(addon.OnEnable, addon) -- make sure we're still enabled before continueing if self.statuses[addon.name] then local embeds = self.embeds[addon] - for i = 1, tgetn(embeds) do + for i = 1, getn(embeds) do local lib = LibStub:GetLibrary(embeds[i], true) - if lib then safecall(lib.OnEmbedEnable, 2, lib, addon) end + if lib then safecall(lib.OnEmbedEnable, lib, addon) end end -- enable possible modules. local modules = addon.orderedModules - for i = 1, tgetn(modules) do + for i = 1, getn(modules) do self:EnableAddon(modules[i]) end end @@ -592,18 +596,18 @@ function AceAddon:DisableAddon(addon) -- set statuses first before calling OnDisable, this allows for aborting the disable in OnDisable. self.statuses[addon.name] = false - safecall(addon.OnDisable, 1, addon) + safecall( addon.OnDisable, addon ) -- make sure we're still disabling... if not self.statuses[addon.name] then local embeds = self.embeds[addon] - for i = 1, tgetn(embeds) do + for i = 1, getn(embeds) do local lib = LibStub:GetLibrary(embeds[i], true) - if lib then safecall(lib.OnEmbedDisable, 2, lib, addon) end + if lib then safecall(lib.OnEmbedDisable, lib, addon) end end -- disable possible modules. local modules = addon.orderedModules - for i = 1, tgetn(modules) do + for i = 1, getn(modules) do self:DisableAddon(modules[i]) end end @@ -634,22 +638,13 @@ function AceAddon:IterateAddonStatus() return pairs(self.statuses) end function AceAddon:IterateEmbedsOnAddon(addon) return pairs(self.embeds[addon]) end function AceAddon:IterateModulesOfAddon(addon) return pairs(addon.modules) end - -local onEvent -do -local IsLoggedIn = false -- Event Handling -function onEvent() - -- 2011-08-17 nevcairiel - ignore the load event of Blizzard_DebugTools, so a potential startup error isn't swallowed up - -- Ace3v: When the ADDON_LOADED event is triggerd, global arg1 is the loaded addon name - -- so onEvent(event, arg1) won't work because it will cover the global variables - if (event == "ADDON_LOADED" and arg1 ~= "Blizzard_DebugTools") or event == "PLAYER_LOGIN" then +local IsLoggedIn +local function onEvent() + -- 2011-08-17 nevcairiel - ignore the load event of !DebugTools, so a potential startup error isn't swallowed up + if (event == "ADDON_LOADED" and arg1 ~= "!DebugTools") or event == "PLAYER_LOGIN" then -- if a addon loads another addon, recursion could happen here, so we need to validate the table on every iteration - -- Ace3v: When an Ace3 addons is loaded, then he initializeque should not be empty unless - -- the addon does not use the library. If an addon that does not use Ace3 library - -- is loaded, we will also receive the ADDON_LOADED event but in this case the - -- queue will be empty so we have nothing to do. - while(tgetn(AceAddon.initializequeue) > 0) do + while(getn(AceAddon.initializequeue) > 0) do local addon = tremove(AceAddon.initializequeue, 1) -- this might be an issue with recursion - TODO: validate if event == "ADDON_LOADED" then addon.baseName = arg1 end @@ -662,14 +657,13 @@ function onEvent() end if IsLoggedIn then - while(tgetn(AceAddon.enablequeue) > 0) do + while(getn(AceAddon.enablequeue) > 0) do local addon = tremove(AceAddon.enablequeue, 1) AceAddon:EnableAddon(addon) end end end end -end -- onEvent AceAddon.frame:RegisterEvent("ADDON_LOADED") AceAddon.frame:RegisterEvent("PLAYER_LOGIN") @@ -679,3 +673,13 @@ AceAddon.frame:SetScript("OnEvent", onEvent) for name, addon in pairs(AceAddon.addons) do Embed(addon, true) end + +-- 2010-10-27 nevcairiel - add new "orderedModules" table +if oldminor and oldminor < 10 then + for name, addon in pairs(AceAddon.addons) do + addon.orderedModules = {} + for module_name, module in pairs(addon.modules) do + tinsert(addon.orderedModules, module) + end + end +end diff --git a/ElvUI/Libraries/AceAddon-3.0/AceAddon-3.0.xml b/ElvUI/Libraries/AceAddon-3.0/AceAddon-3.0.xml index 0ae8501..e6ad639 100644 --- a/ElvUI/Libraries/AceAddon-3.0/AceAddon-3.0.xml +++ b/ElvUI/Libraries/AceAddon-3.0/AceAddon-3.0.xml @@ -1,3 +1,4 @@ - +