View Single Post
01-13-19, 05:35 PM   #4
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Ah ha, I found a comment on the AceGUI-3.0 Tutorial page that worked. Like him, I am not sure if it is the best solution, but it works, huzzah!
Lua Code:
  1. local title, addon = ...
  2. local L = addon.L
  3. local gui = LibStub("AceGUI-3.0")
  4.  
  5. local text_store = "" -- store the edit box text
  6. local isShown = false -- toggle for main_frame
  7.  
  8. local function ShowFrame()
  9.     if isShown then return end
  10.  
  11.     isShown = true
  12.  
  13.     -- create the GUI and make it useful
  14.     local main_frame = gui:Create("Frame")
  15.     main_frame:SetTitle(L["TSM String Converter"])
  16.     main_frame:SetStatusText(L["TradeSkillMaster itemID String Fixer"])
  17.     main_frame:SetCallback("OnClose", function(widget)
  18.         text_store = ""
  19.         isShown = false
  20.         gui:Release(widget)
  21.     end)
  22.     main_frame:SetLayout("Flow")
  23.  
  24.     local edit_box = gui:Create("MultiLineEditBox")
  25.     edit_box:SetLabel(L["Insert itemIDs"])
  26.     edit_box:SetRelativeWidth(1.0)
  27.     edit_box:SetNumLines(25)
  28.     edit_box:SetMaxLetters(0) -- no limit to the number of characters entered
  29.     edit_box:DisableButton(true) -- disables the "Okay" button
  30.     edit_box:SetCallback("OnTextChanged", function(widget, event, text)
  31.         edit_box:SetLabel(L["Insert itemIDs"])
  32.         text_store = text
  33.     end)
  34.     main_frame:AddChild(edit_box)
  35.  
  36.     local button = gui:Create("Button")
  37.     button:SetText(CONVERT)
  38.     button:SetRelativeWidth(1.0)
  39.     button:SetCallback("OnClick", function()
  40.         -- strip out all spaces, just in case
  41.         text_store = text_store:trim()
  42.         text_store = string.gsub(text_store, " ", "")
  43.  
  44.         -- break text_store entirely, and fix it (credit to krowbar71 on the Wowinterface forums)
  45.         text_store = string.gsub(string.gsub(text_store, "[iI]:", ""), "(%d+)", "i:%1")
  46.  
  47.         print("|cff32cd32TSMSC: |r" .. DONE_EDITING)
  48.  
  49.         edit_box:SetText(text_store)
  50.         edit_box:HighlightText()
  51.         edit_box:SetFocus()
  52.         edit_box:SetLabel(DONE_EDITING)
  53.     end)
  54.     main_frame:AddChild(button)
  55. end -- end of ShowFrame()
  56.  
  57. ShowFrame()
  58.  
  59. -- create and handle slash command
  60. SLASH_TSMSC1 = L["/tsmsc"]
  61. SlashCmdList["TSMSC"] = function(msg, editBox) -- the edit box that originated the command, not the input field for itemIDs
  62.     ShowFrame()
  63. end
  Reply With Quote