/Tukui/modules/chat/copychat.lua

http://github.com/Asphyxia/Tukui · Lua · 121 lines · 101 code · 15 blank · 5 comment · 16 complexity · fa576856bad90ae931c3c1bbde49be77 MD5 · raw file

  1. local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2. -----------------------------------------------------------------------------
  3. -- Copy on chatframes feature
  4. -----------------------------------------------------------------------------
  5. if C["chat"].enable ~= true then return end
  6. local lines = {}
  7. local frame = nil
  8. local editBox = nil
  9. local isf = nil
  10. local sizes = {
  11. ":14:14",
  12. ":16:16",
  13. ":12:20",
  14. ":14",
  15. }
  16. local function CreatCopyFrame()
  17. frame = CreateFrame("Frame", "CopyFrame", UIParent)
  18. frame:SetTemplate("Default")
  19. if T.lowversion then
  20. frame:Width(TukuiBar1:GetWidth() + 10)
  21. else
  22. frame:Width((TukuiBar1:GetWidth() * 2) + 20)
  23. end
  24. frame:Height(250)
  25. frame:SetScale(1)
  26. frame:Point("BOTTOM", UIParent, "BOTTOM", 0, 10)
  27. frame:Hide()
  28. frame:SetFrameStrata("DIALOG")
  29. local scrollArea = CreateFrame("ScrollFrame", "CopyScroll", frame, "UIPanelScrollFrameTemplate")
  30. scrollArea:Point("TOPLEFT", frame, "TOPLEFT", 8, -30)
  31. scrollArea:Point("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -30, 8)
  32. editBox = CreateFrame("EditBox", "CopyBox", frame)
  33. editBox:SetMultiLine(true)
  34. editBox:SetMaxLetters(99999)
  35. editBox:EnableMouse(true)
  36. editBox:SetAutoFocus(false)
  37. editBox:SetFontObject(ChatFontNormal)
  38. if T.lowversion then
  39. editBox:Width(TukuiBar1:GetWidth() + 10)
  40. else
  41. editBox:Width((TukuiBar1:GetWidth() * 2) + 20)
  42. end
  43. editBox:Height(250)
  44. editBox:SetScript("OnEscapePressed", function() frame:Hide() end)
  45. --EXTREME HACK..
  46. editBox:SetScript("OnTextSet", function(self)
  47. local text = self:GetText()
  48. for _, size in pairs(sizes) do
  49. if string.find(text, size) then
  50. self:SetText(string.gsub(text, size, ":12:12"))
  51. end
  52. end
  53. end)
  54. scrollArea:SetScrollChild(editBox)
  55. local close = CreateFrame("Button", "CopyCloseButton", frame, "UIPanelCloseButton")
  56. close:SetPoint("TOPRIGHT", frame, "TOPRIGHT")
  57. isf = true
  58. end
  59. local function GetLines(...)
  60. --[[ Grab all those lines ]]--
  61. local ct = 1
  62. for i = select("#", ...), 1, -1 do
  63. local region = select(i, ...)
  64. if region:GetObjectType() == "FontString" then
  65. lines[ct] = tostring(region:GetText())
  66. ct = ct + 1
  67. end
  68. end
  69. return ct - 1
  70. end
  71. local function Copy(cf)
  72. local _, size = cf:GetFont()
  73. FCF_SetChatWindowFontSize(cf, cf, 0.01)
  74. local lineCt = GetLines(cf:GetRegions())
  75. local text = table.concat(lines, "\n", 1, lineCt)
  76. FCF_SetChatWindowFontSize(cf, cf, size)
  77. if not isf then CreatCopyFrame() end
  78. if frame:IsShown() then frame:Hide() return end
  79. frame:Show()
  80. editBox:SetText(text)
  81. end
  82. local function ChatCopyButtons()
  83. for i = 1, NUM_CHAT_WINDOWS do
  84. local cf = _G[format("ChatFrame%d", i)]
  85. local button = CreateFrame("Button", format("TukuiButtonCF%d", i), cf)
  86. if i == 2 then
  87. button:Point("BOTTOMRIGHT", 0, 0)
  88. elseif i == 4 then
  89. button:Point("TOPRIGHT", 0, 0)
  90. else
  91. button:Point("TOPRIGHT", 0, 0)
  92. end
  93. button:Size(20, 20)
  94. button:SetNormalTexture(C.media.copyicon)
  95. button:SetAlpha(0)
  96. button:SetTemplate("Default")
  97. button:SetScript("OnMouseUp", function(self)
  98. Copy(cf)
  99. end)
  100. button:SetScript("OnEnter", function()
  101. button:SetAlpha(1)
  102. end)
  103. button:SetScript("OnLeave", function() button:SetAlpha(0) end)
  104. end
  105. end
  106. ChatCopyButtons()