I was debugging TSM_StringConverter and found an oddity. If the saved variables are wiped, or the addon is freshly installed, the GUI and chat messages are not displayed. If I /reload my UI and don't change any of settings, the slash commands work.
Further, the slash commands do not work at all during a fresh installation. It is like they aren't being initialized when they are called. The test prints in PEW are not doing anything during the first install either. They work after a /reload.
And I don't know why I am getting this behaviour.
Code:
local title, addon = ...
local L = addon.L
local gui = LibStub("AceGUI-3.0")
local text_store = "" -- store the edit box text
local main_frame
addon.frame = CreateFrame("Frame")
addon.frame:RegisterEvent("PLAYER_LOGIN")
addon.frame:RegisterEvent("PLAYER_ENTERING_WORLD")
addon.frame:SetScript("OnEvent", function(self, event, ...)
addon[event](self, ...)
end)
local function PrintCommands()
print(L["/tsmsc slash commands:"])
print(" " .. HELP_LABEL:lower() .. " " .. L["or ? prints this menu."])
print(" " .. L["login toggles showing the frame when you first log into WoW."])
print(" " .. L["reload toggles showing the frame when you reload your UI."])
print(" " .. L["message toggles displaying this message when you log into WoW."])
print(" " .. L["Any other entry toggles the frame"])
print(L["Example: /tsmsc login"])
end
local function ToggleFrame()
if main_frame and main_frame:IsShown() then return end
main_frame = main_frame or gui:Create("Frame")
main_frame:SetTitle(L["TSM String Converter"])
main_frame:SetStatusText(L["TradeSkillMaster itemID String Fixer"])
main_frame:SetCallback("OnClose", function(widget)
text_store = ""
gui:Release(widget)
end)
main_frame:SetLayout("Flow")
local edit_box = gui:Create("MultiLineEditBox")
edit_box:SetLabel(L["Insert itemIDs"])
edit_box:SetRelativeWidth(1.0)
edit_box:SetNumLines(25)
edit_box:SetMaxLetters(0) -- no limit to the number of characters entered
edit_box:DisableButton(true) -- disables the "Okay" button
edit_box:SetCallback("OnTextChanged", function(widget, event, text)
edit_box:SetLabel(L["Insert itemIDs"])
text_store = text
end)
main_frame:AddChild(edit_box)
local button = gui:Create("Button")
button:SetText(CONVERT)
button:SetRelativeWidth(1.0)
button:SetCallback("OnClick", function()
-- strip out all spaces, just in case
text_store = text_store:trim()
text_store = string.gsub(text_store, " ", "")
-- break text_store entirely, and fix it (credit to krowbar71 on the Wowinterface forums)
text_store = string.gsub(string.gsub(text_store, "[iI]:", ""), "(%d+)", "i:%1")
print("|cff32cd32TSMSC: |r" .. DONE_EDITING)
edit_box:SetText(text_store)
edit_box:HighlightText()
edit_box:SetFocus()
edit_box:SetLabel(DONE_EDITING)
end)
main_frame:AddChild(button)
end -- end of ToggleFrame()
-- create and handle slash command
SLASH_TSMSC1 = L["/tsmsc"]
SlashCmdList["TSMSC"] = function(msg, editBox) -- the edit box that originated the command, not the input field for itemIDs
msg = msg and strtrim(strlower(msg))
if msg == L["message"] then
TSMSC_DB.showMessage = not TSMSC_DB.showMessage
if TSMSC_DB.showMessage then
print(L["TSMSC: showing help menu during log in."])
else
print(L["TSMSC: no help menu during log in."])
end
elseif msg == L["login"] then
TSMSC_DB.login = not TSMSC_DB.login
if TSMSC_DB.login then
print(L["TSMSC: will show the frame during log in."])
else
print(L["TSMSC: won't show the frame during log in."])
end
elseif msg == L["reload"] then
TSMSC_DB.reload = not TSMSC_DB.reload
if TSMSC_DB.reload then
print(L["TSMSC: will show the frame when you relod your UI."])
else
print(L["TSMSC: won't show the frame when you reload your UI."])
end
elseif msg == HELP_LABEL:lower() or msg == L["?"] then
PrintCommands()
else
if main_frame and main_frame:IsShown() then
text_store = ""
main_frame:Release()
else
ToggleFrame()
end
end
end
function addon:PLAYER_LOGIN()
addon.frame:UnregisterEvent("PLAYER_LOGIN")
if TSMSC_DB == nil then TSMSC_DB = {} end
if TSMSC_DB.login == nil then TSMSC_DB.login = true end
if TSMSC_DB.reload == nil then TSMSC_DB.reload = false end
if TSMSC_DB.showMessage == nil then TSMSC_DB.showMessage = true end
end
function addon:PLAYER_ENTERING_WORLD(isInitialLogin, isReloadingUI)
print("Initial login:", isInitialLogin)
print("UI reload:", isReloadingUI)
if isInitialLogin then
if TSMSC_DB.login then
ToggleFrame()
end
if TSMSC_DB.showMessage then
PrintCommands()
end
end
if isReloadingUI then
if TSMSC_DB.reload then
ToggleFrame()
end
end
end