/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
- local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
- -----------------------------------------------------------------------------
- -- Copy on chatframes feature
- -----------------------------------------------------------------------------
- if C["chat"].enable ~= true then return end
- local lines = {}
- local frame = nil
- local editBox = nil
- local isf = nil
- local sizes = {
- ":14:14",
- ":16:16",
- ":12:20",
- ":14",
- }
- local function CreatCopyFrame()
- frame = CreateFrame("Frame", "CopyFrame", UIParent)
- frame:SetTemplate("Default")
- if T.lowversion then
- frame:Width(TukuiBar1:GetWidth() + 10)
- else
- frame:Width((TukuiBar1:GetWidth() * 2) + 20)
- end
- frame:Height(250)
- frame:SetScale(1)
- frame:Point("BOTTOM", UIParent, "BOTTOM", 0, 10)
- frame:Hide()
- frame:SetFrameStrata("DIALOG")
- local scrollArea = CreateFrame("ScrollFrame", "CopyScroll", frame, "UIPanelScrollFrameTemplate")
- scrollArea:Point("TOPLEFT", frame, "TOPLEFT", 8, -30)
- scrollArea:Point("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -30, 8)
- editBox = CreateFrame("EditBox", "CopyBox", frame)
- editBox:SetMultiLine(true)
- editBox:SetMaxLetters(99999)
- editBox:EnableMouse(true)
- editBox:SetAutoFocus(false)
- editBox:SetFontObject(ChatFontNormal)
- if T.lowversion then
- editBox:Width(TukuiBar1:GetWidth() + 10)
- else
- editBox:Width((TukuiBar1:GetWidth() * 2) + 20)
- end
- editBox:Height(250)
- editBox:SetScript("OnEscapePressed", function() frame:Hide() end)
- --EXTREME HACK..
- editBox:SetScript("OnTextSet", function(self)
- local text = self:GetText()
- for _, size in pairs(sizes) do
- if string.find(text, size) then
- self:SetText(string.gsub(text, size, ":12:12"))
- end
- end
- end)
-
- scrollArea:SetScrollChild(editBox)
- local close = CreateFrame("Button", "CopyCloseButton", frame, "UIPanelCloseButton")
- close:SetPoint("TOPRIGHT", frame, "TOPRIGHT")
- isf = true
- end
- local function GetLines(...)
- --[[ Grab all those lines ]]--
- local ct = 1
- for i = select("#", ...), 1, -1 do
- local region = select(i, ...)
- if region:GetObjectType() == "FontString" then
- lines[ct] = tostring(region:GetText())
- ct = ct + 1
- end
- end
- return ct - 1
- end
- local function Copy(cf)
- local _, size = cf:GetFont()
- FCF_SetChatWindowFontSize(cf, cf, 0.01)
- local lineCt = GetLines(cf:GetRegions())
- local text = table.concat(lines, "\n", 1, lineCt)
- FCF_SetChatWindowFontSize(cf, cf, size)
- if not isf then CreatCopyFrame() end
- if frame:IsShown() then frame:Hide() return end
- frame:Show()
- editBox:SetText(text)
- end
- local function ChatCopyButtons()
- for i = 1, NUM_CHAT_WINDOWS do
- local cf = _G[format("ChatFrame%d", i)]
- local button = CreateFrame("Button", format("TukuiButtonCF%d", i), cf)
- if i == 2 then
- button:Point("BOTTOMRIGHT", 0, 0)
- elseif i == 4 then
- button:Point("TOPRIGHT", 0, 0)
- else
- button:Point("TOPRIGHT", 0, 0)
- end
- button:Size(20, 20)
- button:SetNormalTexture(C.media.copyicon)
- button:SetAlpha(0)
- button:SetTemplate("Default")
- button:SetScript("OnMouseUp", function(self)
- Copy(cf)
- end)
- button:SetScript("OnEnter", function()
- button:SetAlpha(1)
- end)
- button:SetScript("OnLeave", function() button:SetAlpha(0) end)
- end
- end
- ChatCopyButtons()