-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIO.lua
More file actions
164 lines (150 loc) · 4.27 KB
/
IO.lua
File metadata and controls
164 lines (150 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
local ADDON_NAME, ns = ...
local IO = {}
ns.IO = IO
function IO:Initialize(addon)
self.addon = addon
end
-- Export format (one item per line):
-- GuildMute v1
-- guild=<TargetGuildName>
-- <playername>
-- <playername>
-- ...
local function buildExportText(addon)
local lines = { "GuildMute v1", "guild=" .. (addon.db.realm.targetGuild or "") }
local names = {}
for k in pairs(addon.db.realm.muted) do
table.insert(names, k)
end
table.sort(names)
for _, n in ipairs(names) do
table.insert(lines, n)
end
return table.concat(lines, "\n"), #names
end
local function parseImport(text)
local names, header, guild = {}, false, nil
for raw in text:gmatch("[^\r\n]+") do
local line = raw:gsub("^%s+", ""):gsub("%s+$", "")
if line ~= "" and not line:match("^#") then
if not header and line:match("^GuildMute") then
header = true
elseif line:match("^guild=") then
guild = line:sub(7):gsub("^%s+", ""):gsub("%s+$", "")
else
table.insert(names, line)
end
end
end
return names, guild
end
local frame
local function ensureFrame()
if frame then
return frame
end
local f = CreateFrame("Frame", "GuildMuteIOFrame", UIParent, "BasicFrameTemplateWithInset")
f:SetSize(420, 360)
f:SetPoint("CENTER")
f:SetFrameStrata("DIALOG")
f:SetMovable(true)
f:EnableMouse(true)
f:RegisterForDrag("LeftButton")
f:SetScript("OnDragStart", f.StartMoving)
f:SetScript("OnDragStop", f.StopMovingOrSizing)
f:Hide()
f.title = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
f.title:SetPoint("TOP", 0, -5)
f.hint = f:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
f.hint:SetPoint("TOPLEFT", 14, -28)
f.hint:SetPoint("TOPRIGHT", -14, -28)
f.hint:SetJustifyH("LEFT")
local scroll = CreateFrame("ScrollFrame", nil, f, "UIPanelScrollFrameTemplate")
scroll:SetPoint("TOPLEFT", 14, -50)
scroll:SetPoint("BOTTOMRIGHT", -32, 44)
f.scroll = scroll
local edit = CreateFrame("EditBox", nil, scroll)
edit:SetMultiLine(true)
edit:SetMaxLetters(0)
edit:SetFontObject(ChatFontNormal)
edit:SetWidth(scroll:GetWidth())
edit:SetAutoFocus(false)
edit:SetScript("OnEscapePressed", function()
f:Hide()
end)
scroll:SetScrollChild(edit)
f.edit = edit
local action = CreateFrame("Button", nil, f, "UIPanelButtonTemplate")
action:SetSize(110, 22)
action:SetPoint("BOTTOMRIGHT", -10, 10)
f.action = action
local cancel = CreateFrame("Button", nil, f, "UIPanelButtonTemplate")
cancel:SetSize(80, 22)
cancel:SetPoint("RIGHT", action, "LEFT", -6, 0)
cancel:SetText("Close")
cancel:SetScript("OnClick", function()
f:Hide()
end)
f.cancel = cancel
frame = f
return f
end
function IO:ShowExport()
local f = ensureFrame()
local text, count = buildExportText(self.addon)
f.title:SetText("GuildMute — Export")
f.hint:SetText(("Copy this text (Ctrl+A, Ctrl+C). %d name(s)."):format(count))
f.edit:SetText(text)
f.edit:HighlightText()
f.edit:SetFocus()
f.action:SetText("Close")
f.action:SetScript("OnClick", function()
f:Hide()
end)
f:Show()
end
-- Read-only viewer for arbitrary text (used by /gm history all).
function IO:ShowText(title, hint, text)
local f = ensureFrame()
f.title:SetText(title or "GuildMute")
f.hint:SetText(hint or "")
f.edit:SetText(text or "")
f.edit:HighlightText(0, 0)
f.edit:SetCursorPosition(0)
f.edit:SetFocus()
f.action:SetText("Close")
f.action:SetScript("OnClick", function()
f:Hide()
end)
f:Show()
end
function IO:ShowImport()
local f = ensureFrame()
f.title:SetText("GuildMute — Import")
f.hint:SetText("Paste exported text (Ctrl+V) and press Import. Existing entries are kept.")
f.edit:SetText("")
f.edit:SetFocus()
f.action:SetText("Import")
f.action:SetScript("OnClick", function()
local raw = f.edit:GetText() or ""
local names, guild = parseImport(raw)
if guild and guild ~= "" then
self.addon.db.realm.targetGuild = guild
end
local added = 0
for _, n in ipairs(names) do
if ns.Roster:Add(n, "import") then
added = added + 1
end
end
self.addon:Print(
("import: +%d new (%d in payload). Guild: %s"):format(
added,
#names,
self.addon.db.realm.targetGuild or "<not set>"
)
)
f:Hide()
end)
f:Show()
end