Optimize Open Mail recovery and bump to 1.4.10
- Remove Open Mail layout repair from MAIL_INBOX_UPDATE - Avoid repeated SetParent/SetPoint/frame-level work during inbox refresh bursts - Only repair the Open Mail button when its state is actually wrong - Keep recovery on addon load and mailbox open - Bump version to 1.4.10
This commit is contained in:
+71
-21
@@ -8,7 +8,7 @@ local m = TurtleMail
|
||||
local getn = table.getn
|
||||
local function pack( ... ) return arg end
|
||||
|
||||
m.compat_version = "1.4.9"
|
||||
m.compat_version = "1.4.10"
|
||||
|
||||
local DEFAULT_SENT_FILTERS = {
|
||||
Money = 1,
|
||||
@@ -181,40 +181,92 @@ end
|
||||
|
||||
-- The upstream Open Mail button is created only once in inbox_load(). If that
|
||||
-- creation is skipped/interrupted, or another UI addon hides/re-parents the
|
||||
-- button afterwards, TurtleMail never recreates it. Keep the button recoverable
|
||||
-- whenever the mailbox/inbox is shown or refreshed.
|
||||
-- button afterwards, TurtleMail never recreates it. Keep the button recoverable,
|
||||
-- but only mutate its layout when something is actually wrong. This avoids doing
|
||||
-- repeated SetParent/ClearAllPoints/SetPoint work during inbox refresh bursts.
|
||||
local function ensure_open_mail_button()
|
||||
local inbox = m.api.InboxFrame
|
||||
if not inbox or not m.api.CreateFrame then return nil end
|
||||
|
||||
local button = m.api.TurtleMailOpenMailButton
|
||||
local created = false
|
||||
if not button or type( button.SetPoint ) ~= "function" then
|
||||
button = m.api.CreateFrame( "Button", "TurtleMailOpenMailButton", inbox, "UIPanelButtonTemplate" )
|
||||
m.api.TurtleMailOpenMailButton = button
|
||||
created = true
|
||||
end
|
||||
|
||||
if button.SetParent then button:SetParent( inbox ) end
|
||||
if button.ClearAllPoints then button:ClearAllPoints() end
|
||||
button:SetPoint( "BOTTOM", inbox, "BOTTOM", -10, 90 )
|
||||
|
||||
if button.SetText then button:SetText( m.api.OPENMAIL or "Open Mail" ) end
|
||||
|
||||
local width = 120
|
||||
local font_string = button.GetFontString and button:GetFontString()
|
||||
if font_string and font_string.GetStringWidth then
|
||||
width = math.max( 120, 30 + (font_string:GetStringWidth() or 0) )
|
||||
local parent_changed = false
|
||||
if button.GetParent and button.SetParent then
|
||||
if button:GetParent() ~= inbox then
|
||||
button:SetParent( inbox )
|
||||
parent_changed = true
|
||||
end
|
||||
elseif created and button.SetParent then
|
||||
button:SetParent( inbox )
|
||||
parent_changed = true
|
||||
end
|
||||
|
||||
if button.SetWidth then button:SetWidth( width ) end
|
||||
if button.SetHeight then button:SetHeight( 25 ) end
|
||||
if button.SetScript then button:SetScript( "OnClick", m.inbox_open_all ) end
|
||||
local needs_anchor = created or parent_changed
|
||||
if not needs_anchor and button.GetPoint then
|
||||
local point, relative_to, relative_point, x, y = button:GetPoint()
|
||||
needs_anchor = point ~= "BOTTOM"
|
||||
or (relative_to and relative_to ~= inbox)
|
||||
or relative_point ~= "BOTTOM"
|
||||
or x ~= -10
|
||||
or y ~= 90
|
||||
end
|
||||
|
||||
if needs_anchor then
|
||||
if button.ClearAllPoints then button:ClearAllPoints() end
|
||||
button:SetPoint( "BOTTOM", inbox, "BOTTOM", -10, 90 )
|
||||
end
|
||||
|
||||
local wanted_text = m.api.OPENMAIL or "Open Mail"
|
||||
local text_changed = created
|
||||
if button.GetText then
|
||||
text_changed = button:GetText() ~= wanted_text
|
||||
end
|
||||
if text_changed and button.SetText then
|
||||
button:SetText( wanted_text )
|
||||
end
|
||||
|
||||
-- Recalculate dimensions only when the button was created or its label changed.
|
||||
if created or text_changed then
|
||||
local width = 120
|
||||
local font_string = button.GetFontString and button:GetFontString()
|
||||
if font_string and font_string.GetStringWidth then
|
||||
width = math.max( 120, 30 + (font_string:GetStringWidth() or 0) )
|
||||
end
|
||||
if button.SetWidth then button:SetWidth( width ) end
|
||||
if button.SetHeight then button:SetHeight( 25 ) end
|
||||
end
|
||||
|
||||
if button.SetScript then
|
||||
local onclick = button.GetScript and button:GetScript( "OnClick" ) or nil
|
||||
if created or onclick ~= m.inbox_open_all then
|
||||
button:SetScript( "OnClick", m.inbox_open_all )
|
||||
end
|
||||
end
|
||||
|
||||
if inbox.GetFrameLevel and button.SetFrameLevel then
|
||||
button:SetFrameLevel( (inbox:GetFrameLevel() or 0) + 5 )
|
||||
local target_level = (inbox:GetFrameLevel() or 0) + 5
|
||||
local current_level = button.GetFrameLevel and button:GetFrameLevel() or nil
|
||||
if current_level ~= target_level then
|
||||
button:SetFrameLevel( target_level )
|
||||
end
|
||||
end
|
||||
|
||||
if button.Enable then button:Enable() end
|
||||
if button.Show then button:Show() end
|
||||
if button.Enable then
|
||||
if not button.IsEnabled or not button:IsEnabled() then
|
||||
button:Enable()
|
||||
end
|
||||
end
|
||||
if button.Show then
|
||||
if not button.IsShown or not button:IsShown() then
|
||||
button:Show()
|
||||
end
|
||||
end
|
||||
return button
|
||||
end
|
||||
|
||||
@@ -530,8 +582,6 @@ end
|
||||
|
||||
-- Hide stale AH/returned icons on rows that no longer contain mail.
|
||||
function m.MAIL_INBOX_UPDATE()
|
||||
ensure_open_mail_button()
|
||||
|
||||
if m.inbox_opening then
|
||||
m.inbox_update = true
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user