Skip to content

Commit

Permalink
QuickDispatch now uses xpcall instead of pcall, fixed search box erro…
Browse files Browse the repository at this point in the history
…ring on some searchs
  • Loading branch information
Tercioo committed Oct 14, 2022
1 parent 50ed1cf commit 3f3d4db
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 63 deletions.
2 changes: 1 addition & 1 deletion Libs/DF/addon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function DF:CreateAddOn (name, global_saved, global_table, options_table, broker
end

if (addon.OnInit) then
xpcall (addon.OnInit, geterrorhandler(), addon)
xpcall(addon.OnInit, geterrorhandler(), addon)
end

end
Expand Down
28 changes: 14 additions & 14 deletions Libs/DF/auras.lua
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ function DF:CreateAuraConfigPanel (parent, name, db, change_callback, options, t

f.db.aura_tracker.track_method = method
if (change_callback) then
DF:QuickDispatch (change_callback)
DF:QuickDispatch(change_callback)
end

if (method == 0x1) then
Expand Down Expand Up @@ -427,7 +427,7 @@ function DF:CreateAuraConfigPanel (parent, name, db, change_callback, options, t
--refresh the buff blacklist frame
f.buff_ignored:DoRefresh()

DF:QuickDispatch (change_callback)
DF:QuickDispatch(change_callback)

--add to spells with the same name cache
same_name_spells_add (spellId)
Expand Down Expand Up @@ -458,7 +458,7 @@ function DF:CreateAuraConfigPanel (parent, name, db, change_callback, options, t
--refresh the buff blacklist frame
f.buff_ignored:DoRefresh()

DF:QuickDispatch (change_callback)
DF:QuickDispatch(change_callback)

--add to spells with the same name cache
same_name_spells_add (spellId)
Expand All @@ -485,7 +485,7 @@ function DF:CreateAuraConfigPanel (parent, name, db, change_callback, options, t
--refresh the buff blacklist frame
f.debuff_ignored:DoRefresh()

DF:QuickDispatch (change_callback)
DF:QuickDispatch(change_callback)

--add to spells with the same name cache
same_name_spells_add (spellId)
Expand Down Expand Up @@ -515,7 +515,7 @@ function DF:CreateAuraConfigPanel (parent, name, db, change_callback, options, t
--refresh the buff blacklist frame
f.debuff_ignored:DoRefresh()

DF:QuickDispatch (change_callback)
DF:QuickDispatch(change_callback)

--add to spells with the same name cache
same_name_spells_add (spellId)
Expand Down Expand Up @@ -558,7 +558,7 @@ function DF:CreateAuraConfigPanel (parent, name, db, change_callback, options, t
--refresh the buff blacklist frame
f.debuff_tracked:DoRefresh()

DF:QuickDispatch (change_callback)
DF:QuickDispatch(change_callback)

--add to spells with the same name cache
same_name_spells_add (spellId)
Expand Down Expand Up @@ -587,7 +587,7 @@ function DF:CreateAuraConfigPanel (parent, name, db, change_callback, options, t
--refresh the buff blacklist frame
f.debuff_tracked:DoRefresh()

DF:QuickDispatch (change_callback)
DF:QuickDispatch(change_callback)

--add to spells with the same name cache
same_name_spells_add (spellId)
Expand All @@ -614,7 +614,7 @@ function DF:CreateAuraConfigPanel (parent, name, db, change_callback, options, t
f.buff_tracked:DoRefresh()

--callback the addon
DF:QuickDispatch (change_callback)
DF:QuickDispatch(change_callback)

--add to spells with the same name cache
same_name_spells_add (spellId)
Expand Down Expand Up @@ -646,7 +646,7 @@ function DF:CreateAuraConfigPanel (parent, name, db, change_callback, options, t
f.buff_tracked:DoRefresh()

--callback the addon
DF:QuickDispatch (change_callback)
DF:QuickDispatch(change_callback)

--add to spells with the same name cache
same_name_spells_add (spellId)
Expand Down Expand Up @@ -793,7 +793,7 @@ function DF:CreateAuraConfigPanel (parent, name, db, change_callback, options, t
db ["".. (spellID or "")] = nil -- cleanup...
parent [member]:DoRefresh()
if (removeFunc) then
DF:QuickDispatch (removeFunc)
DF:QuickDispatch(removeFunc)
end
end

Expand Down Expand Up @@ -874,23 +874,23 @@ function DF:CreateAuraConfigPanel (parent, name, db, change_callback, options, t

local buff_tracked = createAuraScrollBox (f_auto, "$parentBuffTracked", "BuffTrackerScroll", f.LocTexts.BUFFS_TRACKED, f.db.aura_tracker.buff_tracked, function()
if (change_callback) then
DF:QuickDispatch (change_callback)
DF:QuickDispatch(change_callback)
end
end)
local debuff_tracked = createAuraScrollBox (f_auto, "$parentDebuffTracked", "DebuffTrackerScroll", f.LocTexts.DEBUFFS_TRACKED, f.db.aura_tracker.debuff_tracked, function()
if (change_callback) then
DF:QuickDispatch (change_callback)
DF:QuickDispatch(change_callback)
end
end)

local buff_ignored = createAuraScrollBox (f_auto, "$parentBuffIgnored", "BuffIgnoredScroll", f.LocTexts.BUFFS_IGNORED, f.db.aura_tracker.buff_banned, function()
if (change_callback) then
DF:QuickDispatch (change_callback)
DF:QuickDispatch(change_callback)
end
end)
local debuff_ignored = createAuraScrollBox (f_auto, "$parentDebuffIgnored", "DebuffIgnoredScroll", f.LocTexts.DEBUFFS_IGNORED, f.db.aura_tracker.debuff_banned, function()
if (change_callback) then
DF:QuickDispatch (change_callback)
DF:QuickDispatch(change_callback)
end
end)

Expand Down
25 changes: 14 additions & 11 deletions Libs/DF/fw.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


local dversion = 380
local dversion = 381
local major, minor = "DetailsFramework-1.0", dversion
local DF, oldminor = LibStub:NewLibrary(major, minor)

Expand Down Expand Up @@ -1770,6 +1770,9 @@ end
label.text = (languageTable and languageTable[widgetTable.namePhraseId]) or formatOptionNameWithColon(widgetTable.name, useColon) or widgetTable.namePhraseId or ""
label:SetTemplate(widgetTable.text_template or textTemplate)

label:ClearAllPoints()
colorpick:ClearAllPoints()

if (widgetTable.boxfirst or useBoxFirstOnAllWidgets) then
label:SetPoint("left", colorpick, "right", 2)
colorpick:SetPoint(currentXOffset, currentYOffset)
Expand Down Expand Up @@ -3934,7 +3937,7 @@ local specs_per_class = {
["EVOKER"] = {1467, 1468},
}

function DF:GetClassSpecIDs (class)
function DF:GetClassSpecIDs(class)
return specs_per_class [class]
end

Expand All @@ -3943,19 +3946,19 @@ local dispatch_error = function(context, errortext)
end

--safe call an external func with payload and without telling who is calling
function DF:QuickDispatch (func, ...)
function DF:QuickDispatch(func, ...)
if (type(func) ~= "function") then
return
end
local okay, errortext = pcall(func, ...)

local okay, errortext = xpcall(func, geterrorhandler(), ...)

if (not okay) then
--trigger an error msg
dispatch_error (_, errortext)
dispatch_error(_, errortext)
return
end

return true
end

Expand All @@ -3964,7 +3967,7 @@ function DF:Dispatch(func, ...)
return dispatch_error (_, "DF:Dispatch expect a function as parameter 1.")
end

local dispatchResult = {xpcall (func, geterrorhandler(), ...)}
local dispatchResult = {xpcall(func, geterrorhandler(), ...)}
local okay = dispatchResult[1]

if (not okay) then
Expand All @@ -3977,14 +3980,14 @@ function DF:Dispatch(func, ...)
end

--[=[
DF:CoreDispatch (func, context, ...)
DF:CoreDispatch(func, context, ...)
safe call a function making a error window with what caused, the context and traceback of the error
this func is only used inside the framework for sensitive calls where the func must run without errors
@func = the function which will be called
@context = what made the function be called
... parameters to pass in the function call
--]=]
function DF:CoreDispatch (context, func, ...)
function DF:CoreDispatch(context, func, ...)
if (type(func) ~= "function") then
local stack = debugstack(2)
local errortext = "D!Framework " .. context .. " error: invalid function to call\n====================\n" .. stack .. "\n====================\n"
Expand Down
8 changes: 5 additions & 3 deletions Libs/DF/mixins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ detailsFramework.TooltipHandlerMixin = {

if (type(tooltipText) == "function") then
local tooltipFunction = tooltipText
local gotTooltip, tooltipString = pcall(tooltipFunction)
local gotTooltip, tooltipString = xpcall(tooltipFunction, geterrorhandler())
if (gotTooltip) then
tooltipText = tooltipString
end
Expand Down Expand Up @@ -353,9 +353,11 @@ detailsFramework.ScriptHookMixin = {
end

for i, func in ipairs(hooks) do
local success, canInterrupt = pcall(func, ...)
local success, canInterrupt = xpcall(func, geterrorhandler(), ...)

if (not success) then
error("Details! Framework: " .. event .. " hook for " .. self:GetName() .. ": " .. canInterrupt)
--error("Details! Framework: " .. event .. " hook for " .. self:GetName() .. ": " .. canInterrupt)
return false

elseif (canInterrupt) then
return true
Expand Down
32 changes: 16 additions & 16 deletions Libs/DF/panel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1589,7 +1589,7 @@ function detailsFramework:IconPick (callback, close_when_select, param1, param2)
local accept_custom_icon = function()
local path = detailsFramework.IconPickFrame.customIconEntry:GetText()

detailsFramework:QuickDispatch (detailsFramework.IconPickFrame.callback, path, detailsFramework.IconPickFrame.param1, detailsFramework.IconPickFrame.param2)
detailsFramework:QuickDispatch(detailsFramework.IconPickFrame.callback, path, detailsFramework.IconPickFrame.param1, detailsFramework.IconPickFrame.param2)

if (detailsFramework.IconPickFrame.click_close) then
close_button:Click()
Expand Down Expand Up @@ -1658,7 +1658,7 @@ function detailsFramework:IconPick (callback, close_when_select, param1, param2)

local onClickFunction = function(self)

detailsFramework:QuickDispatch (detailsFramework.IconPickFrame.callback, self.icon:GetTexture(), detailsFramework.IconPickFrame.param1, detailsFramework.IconPickFrame.param2)
detailsFramework:QuickDispatch(detailsFramework.IconPickFrame.callback, self.icon:GetTexture(), detailsFramework.IconPickFrame.param1, detailsFramework.IconPickFrame.param2)

if (detailsFramework.IconPickFrame.click_close) then
close_button:Click()
Expand Down Expand Up @@ -3782,7 +3782,7 @@ function detailsFramework:CreateSimpleListBox (parent, name, title, empty_text,
f.list_table = list_table
f.func = function(self, button, value)
--onclick (value)
detailsFramework:QuickDispatch (onclick, value)
detailsFramework:QuickDispatch(onclick, value)
f:Refresh()
end
f.widgets = {}
Expand All @@ -3795,7 +3795,7 @@ function detailsFramework:CreateSimpleListBox (parent, name, title, empty_text,
if (f.options.x_button_func) then
local original_X_function = f.options.x_button_func
f.options.x_button_func = function(self, button, value)
detailsFramework:QuickDispatch (original_X_function, value)
detailsFramework:QuickDispatch(original_X_function, value)
f:Refresh()
end
end
Expand Down Expand Up @@ -3976,7 +3976,7 @@ function detailsFramework:CreateKeybindBox (parent, name, data, callback, width,
--build data table for the character class
local _, unitClass = UnitClass("player")
if (unitClass) then
local specIds = detailsFramework:GetClassSpecIDs (unitClass)
local specIds = detailsFramework:GetClassSpecIDs(unitClass)
if (specIds) then
for _, specId in ipairs(specIds) do
data [specId] = {}
Expand Down Expand Up @@ -4018,7 +4018,7 @@ function detailsFramework:CreateKeybindBox (parent, name, data, callback, width,
--format the button label and icon with the spec information
local className, class = UnitClass("player")
local i = 1
local specIds = detailsFramework:GetClassSpecIDs (class)
local specIds = detailsFramework:GetClassSpecIDs(class)

for index, specId in ipairs(specIds) do
local button = new_keybind_frame ["SpecButton" .. index]
Expand Down Expand Up @@ -4086,7 +4086,7 @@ function detailsFramework:CreateKeybindBox (parent, name, data, callback, width,
enter_the_key:Hide()
new_keybind_frame.keybindScroll:UpdateScroll()

detailsFramework:QuickDispatch (callback)
detailsFramework:QuickDispatch(callback)
end

local set_keybind_key = function(self, button, keybindIndex)
Expand All @@ -4111,14 +4111,14 @@ function detailsFramework:CreateKeybindBox (parent, name, data, callback, width,
local set_action_text = function(keybindIndex, _, text)
local keybind = new_keybind_frame.CurrentKeybindEditingSet [keybindIndex]
keybind.actiontext = text
detailsFramework:QuickDispatch (callback)
detailsFramework:QuickDispatch(callback)
end

local set_action_on_espace_press = function(textentry, capsule)
capsule = capsule or textentry.MyObject
local keybind = new_keybind_frame.CurrentKeybindEditingSet [capsule.CurIndex]
textentry:SetText(keybind.actiontext)
detailsFramework:QuickDispatch (callback)
detailsFramework:QuickDispatch(callback)
end

local lock_textentry = {
Expand All @@ -4134,7 +4134,7 @@ function detailsFramework:CreateKeybindBox (parent, name, data, callback, width,
local keybind = new_keybind_frame.CurrentKeybindEditingSet [keybindIndex]
keybind.action = value
new_keybind_frame.keybindScroll:UpdateScroll()
detailsFramework:QuickDispatch (callback)
detailsFramework:QuickDispatch(callback)
end
local fill_action_dropdown = function()

Expand Down Expand Up @@ -4176,13 +4176,13 @@ function detailsFramework:CreateKeybindBox (parent, name, data, callback, width,
detailsFramework:Msg("Keybind copied to " .. (specName or ""))
end
end
detailsFramework:QuickDispatch (callback)
detailsFramework:QuickDispatch(callback)
end

local delete_keybind = function(self, button, keybindIndex)
tremove(new_keybind_frame.CurrentKeybindEditingSet, keybindIndex)
new_keybind_frame.keybindScroll:UpdateScroll()
detailsFramework:QuickDispatch (callback)
detailsFramework:QuickDispatch(callback)
end

local newTitle = detailsFramework:CreateLabel(new_keybind_frame, "Create a new Keybind:", 12, "silver")
Expand Down Expand Up @@ -5710,7 +5710,7 @@ function detailsFramework:CreateLoadFilterParser (callback)

--print("Plater Script Update:", event, ...)

detailsFramework:QuickDispatch (callback, f.EncounterIDCached)
detailsFramework:QuickDispatch(callback, f.EncounterIDCached)
end)
end

Expand All @@ -5733,7 +5733,7 @@ function detailsFramework:PassLoadFilters(loadTable, encounterID)
if (passLoadClass) then
--if is allowed to load on this class, check if the talents isn't from another class
local _, classFileName = UnitClass("player")
local specsForThisClass = detailsFramework:GetClassSpecIDs (classFileName)
local specsForThisClass = detailsFramework:GetClassSpecIDs(classFileName)

canCheckTalents = false

Expand Down Expand Up @@ -5970,7 +5970,7 @@ function detailsFramework:OpenLoadConditionsPanel(optionsTable, callback, frameO
--create the radio group for character spec
if IS_WOW_PROJECT_MAINLINE then
local specs = {}
for _, specID in ipairs(detailsFramework:GetClassSpecIDs (select(2, UnitClass("player")))) do
for _, specID in ipairs(detailsFramework:GetClassSpecIDs(select(2, UnitClass("player")))) do
local specID, specName, specDescription, specIcon, specBackground, specRole, specClass = DetailsFramework.GetSpecializationInfoByID (specID)
tinsert(specs, {
name = specName,
Expand Down Expand Up @@ -6474,7 +6474,7 @@ detailsFramework.DataScrollFunctions = {
end

if (line:GetParent().OnUpdateLineHook) then
detailsFramework:CoreDispatch ((line:GetName() or "ScrollBoxDataScrollUpdateLineHook") .. ":UpdateLineHook()", line:GetParent().OnUpdateLineHook, line, lineIndex, data)
detailsFramework:CoreDispatch((line:GetName() or "ScrollBoxDataScrollUpdateLineHook") .. ":UpdateLineHook()", line:GetParent().OnUpdateLineHook, line, lineIndex, data)
end
end,
}
Expand Down
2 changes: 1 addition & 1 deletion Libs/DF/slider.lua
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ local SwitchOnClick = function(self, button, forced_value, value)
value = slider:return_func (value)
end

local success, errorText = xpcall (slider.OnSwitch, geterrorhandler(), slider, slider.FixedValue, value)
local success, errorText = xpcall(slider.OnSwitch, geterrorhandler(), slider, slider.FixedValue, value)
if (not success) then
return
end
Expand Down
Loading

0 comments on commit 3f3d4db

Please sign in to comment.