Version 0.9.0-rc1

- enable/disable from slash command
- matching conditions (never, always, start, end, start or end)
- support capturing groups
- import examples
- testing capabilities
- compatibility with WoW Retail
- adapted help texts
- spelling errors
This commit is contained in:
2020-07-16 12:54:06 +02:00
parent cc4df96bac
commit bafb116bb9
39 changed files with 3043 additions and 1049 deletions

View File

@@ -1,9 +1,9 @@
-- read namespace from global env
local _G = _G
local Grichelde = _G.Grichelde
local Grichelde = _G.Grichelde or {}
local nilOrEmpty, pairs, tContains, tWipe, find, match, color, toString, toNumber
= Grichelde.functions.nilOrEmpty, Grichelde.functions.pairs, Grichelde.functions.tContains, Grichelde.functions.tWipe, Grichelde.functions.find, Grichelde.functions.match, Grichelde.functions.color, Grichelde.functions.toString, Grichelde.functions.toNumber
local assert, nilOrEmpty, pairs, ipairs, spairs, tContains, tInsert, tClone, tWipe, find, match, cPrefix, cGray, cGreen, cOrange, cRed, format, toString, toNumber
= Grichelde.F.assert, Grichelde.F.nilOrEmpty, Grichelde.F.pairs, Grichelde.F.ipairs, Grichelde.F.spairs, Grichelde.F.tContains, Grichelde.F.tInsert, Grichelde.F.tClone, Grichelde.F.tWipe, Grichelde.F.find, Grichelde.F.match, Grichelde.F.cPrefix, Grichelde.F.cGray, Grichelde.F.cGreen, Grichelde.F.cOrange, Grichelde.F.cRed, Grichelde.F.format, Grichelde.F.toString, Grichelde.F.toNumber
local selectedExample = 1
@@ -206,41 +206,52 @@ function Grichelde:CreateOptionsUI()
header = {
order = 2,
type = "description",
name = self.L.Options_Help_Examples0_Header,
name = self.L.Options_Help_Examples_Header,
fontSize = "medium",
width = 2.5,
width = 2.1
},
dropDown = {
order = 3,
type = "select",
name = "",
--width = 1,
values = {
self.L.Options_Help_Examples1_Select,
self.L.Options_Help_Examples2_Select,
self.L.Options_Help_Examples3_Select,
self.L.Options_Help_Examples4_Select,
self.L.Options_Help_Examples5_Select,
self.L.Options_Help_Examples6_Select,
-- self.L.Options_Help_Examples7_Select,
},
set = function(info, val) selectedExample = val end,
width = 1.2,
values = function(_) return self:ExtractExampleNames() end,
set = function(_, val) selectedExample = val end,
get = function(_)
self.options.args.help.args.examples.args.header.name = self.L["Options_Help_Examples" .. selectedExample .. "_Header"]
self.options.args.help.args.examples.args.example.name = self.L["Options_Help_Examples" .. selectedExample .. "_Text"]
self.options.args.help.args.examples.args.header.name = self.L.Options_Help_Examples[selectedExample].desc
self.options.args.help.args.examples.args.example.name = self:ExtractExampleCodes(selectedExample),
self.dialog:SelectGroup(self.name, "help", "examples", "header.name")
return selectedExample
end,
},
spacer3 = {
order = 3,
type = "description",
name = "",
desc = "",
width = 2.3,
},
import = {
order = 4,
type = "execute",
width = 1,
confirm = selectedExample > 0,
name = self.L.Options_Help_Examples_Import_Name,
-- desc = self.L.Options_Help_Examples_Import_Desc,
desc = function() return format(self.L.Options_Help_Examples_Import_Desc, cPrefix(self.L.Options_Help_Examples[selectedExample].name)) end,
func = function(info) self:ImportExample(selectedExample) end,
},
spacer4 = {
order = 6,
type = "header",
name = "",
},
example = {
order = 5,
order = 7,
type = "description",
name = self.L.Options_Help_Examples0_Text,
name = self.L.Options_Help_Examples_Text,
fontSize = "medium",
},
},
@@ -283,14 +294,14 @@ function Grichelde:CreateMapping(offset)
width = 0.15,
func = function(info) self:MoveDown(info) end,
},
--[[
spacer4 = {
spacer5 = {
order = 2,
type = "description",
name = "",
width = 0.1,
desc = "",
width = 0.05,
},
]]
--[[
active = {
order = 3,
type = "toggle",
@@ -298,8 +309,40 @@ function Grichelde:CreateMapping(offset)
desc = self.L.Options_Mapping_Enabled_Desc,
width = 2.2,
},
delete = {
]]
matchWhenLabel = {
order = 3,
type = "description",
name = self.L.Options_Mapping_MatchWhen_Name,
desc = self.L.Options_Mapping_MatchWhen_Desc,
fontSize = "medium",
width = 0.3,
},
matchWhen = {
order = 4,
type = "select",
name = " ",
desc = self.L.Options_Mapping_MatchWhen_Desc,
values = {
self.L.Options_Mapping_MatchWhen_Select1,
self.L.Options_Mapping_MatchWhen_Select2,
self.L.Options_Mapping_MatchWhen_Select3,
self.L.Options_Mapping_MatchWhen_Select4,
self.L.Options_Mapping_MatchWhen_Select5,
self.L.Options_Mapping_MatchWhen_Select6,
},
width = 1.4,
},
spacer6 = {
order = 5,
type = "description",
name = "",
desc = "",
width = 0.1,
},
delete = {
order = 6,
type = "execute",
confirm = true,
confirmText = self.L.Options_Mapping_Delete_ConfirmText,
@@ -324,21 +367,21 @@ function Grichelde:CreateMapping(offset)
},
exactCase = {
order = 20,
order = 21,
type = "toggle",
name = self.L.Options_Mapping_ExactCase_Name,
desc = self.L.Options_Mapping_ExactCase_Desc,
width = "full",
},
consolidate = {
order = 21,
order = 22,
type = "toggle",
name = self.L.Options_Mapping_Consolidate_Name,
desc = self.L.Options_Mapping_Consolidate_Desc,
width = "full",
},
stopOnMatch = {
order = 22,
order = 23,
type = "toggle",
name = self.L.Options_Mapping_StopOnMatch_Name,
desc = self.L.Options_Mapping_StopOnMatch_Desc,
@@ -350,7 +393,7 @@ end
function Grichelde:SetupOptions()
-- add DB-backed profiles to UI options
local options = self:CreateOptionsUI()
local options = self:CreateOptionsUI(self)
options.args.profiles = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
options.args.profiles.order = 8
options.args.profiles.disabled = false
@@ -363,19 +406,18 @@ function Grichelde:SetupOptions()
return options, dialog
end
function Grichelde:RefreshOptions(event)
function Grichelde:RefreshOptions(event, _, profileName)
self:DebugPrint("RefreshOptions : event:", event)
local currentProfile = color(Grichelde.COLOR_CODES.GREEN, self.db:GetCurrentProfile())
if event == "OnNewProfile" then
self:PrefixedPrint(self.L.Profiles_Created, currentProfile)
elseif event == "OnProfileChanged" then
self:PrefixedPrint(self.L.Profiles_Loaded, currentProfile)
elseif event == "OnProfileDeleted" then
self:PrefixedPrint(self.L.Profiles_Deleted, currentProfile)
elseif event == "OnProfileCopied" then
self:PrefixedPrint(self.L.Profiles_Copied, currentProfile)
elseif event == "OnProfileReset" then
self:PrefixedPrint(self.L.Profiles_Reset, currentProfile)
if (event == "OnNewProfile") then
self:PrefixedPrint(self.L.Profiles_Created, cGreen(self.db:GetCurrentProfile()))
elseif (event == "OnProfileChanged") then
self:PrefixedPrint(self.L.Profiles_Loaded, cGreen(self.db:GetCurrentProfile()))
elseif (event == "OnProfileDeleted") then
self:PrefixedPrint(self.L.Profiles_Deleted, cRed(profileName))
elseif (event == "OnProfileCopied") then
self:PrefixedPrint(self.L.Profiles_Copied, cOrange(profileName))
elseif (event == "OnProfileReset") then
self:PrefixedPrint(self.L.Profiles_Reset, cOrange(self.db:GetCurrentProfile()))
else
self:DebugPrint("Refreshing Profile %s on options change: %s", self.db:GetCurrentProfile(), event)
end
@@ -386,7 +428,7 @@ end
function Grichelde:ToggleOptions()
self:DebugPrint("ToggleOptions : options open: ", not not self.dialog.OpenFrames[self.name])
if self.dialog ~= nil and self.dialog.OpenFrames[self.name] ~= nil then
if (self.dialog ~= nil) and (self.dialog.OpenFrames[self.name] ~= nil) then
self:CloseOptions()
else
self:OpenOptions()
@@ -394,11 +436,11 @@ function Grichelde:ToggleOptions()
end
function Grichelde:OpenOptions()
if self.dialog ~= nil then
if (self.dialog ~= nil) then
self.dialog:Open(self.name)
local formatString = self.L.AddonLoaded
if not self.db.profile.enabled then
if (self.db.profile.enabled == false) then
formatString = self.L.AddonUnloaded
end
@@ -409,7 +451,7 @@ function Grichelde:OpenOptions()
end
function Grichelde:CloseOptions()
if self.dialog ~= nil then
if (self.dialog ~= nil) then
self.dialog:Close(self.name)
end
end
@@ -417,7 +459,7 @@ end
--- If all replacements were disabled
-- @return (boolean)
function Grichelde:IsDisabled(info)
if info and info.option.type == "group" then
if (info and (info.option.type == "group")) then
return false
end
return not self.db.profile.enabled
@@ -428,13 +470,13 @@ end
function Grichelde:IsMappingActive(info)
self:TracePrint("IsMappingActive : info")
for i = 0, #info do
self:TracePrint("%d = %s", i, info[i])
self:TracePrint("IsMappingActive : info[%d] = %s", i, info[i])
end
if info and info.option.type == "group" then
if (info and (info.option.type == "group")) then
return true
end
if not self.db.profile.enabled then
if (self.db.profile.enabled == false) then
return false
end
@@ -445,10 +487,10 @@ function Grichelde:IsMappingActive(info)
self:DebugPrint("IsMappingActive : \"%s\"", currentName)
self:DebugPrint(replacements[currentName])
if (tContains({"moveUp", "moveDown", "active", "delete"}, uiElem)) then
if (tContains({"moveUp", "moveDown", "matchWhen", "delete"}, uiElem)) then
return true
else
return not not replacements[currentName].active
return replacements[currentName].matchWhen > 1
end
end
@@ -457,20 +499,82 @@ function Grichelde:MappingName(info)
-- self:TracePrint(info)
local option = self.db.profile.replacements[info[2]]
if nilOrEmpty(option.searchText) and nilOrEmpty(option.replaceText) then
return color(Grichelde.COLOR_CODES.GRAY, self.L.Options_Mapping_EmptyMapping)
if (nilOrEmpty(option.searchText) and nilOrEmpty(option.replaceText)) then
return cGray(self.L.Options_Mapping_EmptyMapping)
else
local name = self:Format(self.L.Options_Mapping_Group_Name, option.searchText or "", option.replaceText or "")
if option.active == true then
if (option.matchWhen > 1) then
return name
else
return color(Grichelde.COLOR_CODES.GRAY, name)
return cGray(name)
end
end
end
function Grichelde:ExtractExampleNames()
local exampleNames = {}
for _, example in ipairs(self.L.Options_Help_Examples) do
tInsert(exampleNames, example.name)
end
return exampleNames
end
--- Create UI options for rhe given replacement table (from DB).
function Grichelde:ExtractExampleCodes(num)
self:TracePrint("ExtractExampleCodes : number is: %d", num)
if (self.L.Options_Help_Examples[num] == nil) or (#self.L.Options_Help_Examples < num) then
self:DebugPrint("ExtractExampleCodes : invalid number: %d", num)
return self.L.Options_Help_Examples_Text
end
local exampleCodes = ""
for replName, replTable in spairs(self.L.Options_Help_Examples[num].replacements) do
self:TracePrint("ExtractExampleCodes : replacement: %s", replName)
self:TracePrint(replTable)
if (replTable ~= nil) and (replTable.searchText ~= nil) then
if (exampleCodes ~= "") then
exampleCodes = exampleCodes .. "|n|n"
end
exampleCodes = exampleCodes .. cPrefix(format("%s => %s", replTable.searchText, replTable.replaceText))
end
end
return exampleCodes
end
function Grichelde:ImportExample(num)
self:TracePrint("ImportExample : number is: %d", num)
if (self.L.Options_Help_Examples[num] == nil) or (#self.L.Options_Help_Examples < num) then
self:DebugPrint("ImportExample : invalid number: %d", num)
end
local profileName = self.L.Options_Help_Examples[num].name
self:DebugPrint("ImportExample : profile name: %s", profileName)
local allProfiles = self.db:GetProfiles()
if (not tContains(allProfiles, profileName)) then
-- create new profile if not exists
self.db:SetProfile(profileName)
assert(self.db:GetCurrentProfile() == profileName, "profile was not loaded")
local exampleProfile = self.db.profile
tWipe(exampleProfile.replacements)
for replName, replTable in spairs(self.L.Options_Help_Examples[num].replacements) do
self:TracePrint("ImportExample : replacement: %s", replName)
self:TracePrint(replTable)
if (replName ~= nil) and (replTable ~= nil) and (replTable.searchText ~= nil) then
exampleProfile.replacements[replName] = tClone(replTable)
end
end
self:RefreshReplacements(self.db.profile.replacements)
else
self:ErrorPrint(self.L.Profiles_AlreadyExistsError, profileName)
end
end
--- Create UI options for the given replacement table (from DB).
--- Usually called with with self.db.profile.replacements
-- @param replacementsTable
function Grichelde:RefreshReplacements(replacementsTable)
@@ -480,7 +584,7 @@ function Grichelde:RefreshReplacements(replacementsTable)
-- remove all previous replacements from options (not DB), except header and buttons
local replacements = self.options.args.replacements.args or {}
for k, _ in pairs(replacements) do
if k and find(k, "^replacement_") then
if (k and (find(k, "^replacement_") ~= nil)) then
replacements[k] = nil
end
end
@@ -505,7 +609,7 @@ function Grichelde:AddEmptyMapping()
local maxRepl = Grichelde.MAPPING_OFFSET
for replName, _ in pairs(replacements) do
local num = match(replName, "^replacement_(%d+)")
if num and maxRepl < toNumber(num) then
if (num ~= nil) and (maxRepl < toNumber(num)) then
maxRepl = toNumber(num)
end
end
@@ -538,7 +642,7 @@ function Grichelde:MoveUp(info)
local currentOrder = toNumber(replNumber)
-- if not on top
if currentOrder ~= Grichelde.MAPPING_OFFSET then
if (currentOrder ~= Grichelde.MAPPING_OFFSET) then
local swapName = "replacement_" .. toString(currentOrder - 1)
-- swap ordering
@@ -581,7 +685,7 @@ function Grichelde:MoveDown(info)
-- if not last element
self:DebugPrint("MoveDown : maxRepl: %d", maxRepl)
if currentOrder < maxRepl then
if (currentOrder < maxRepl) then
local swapName = "replacement_" .. toString(currentOrder + 1)
-- swap ordering
@@ -611,7 +715,7 @@ function Grichelde:GetMoveUpImage(info)
local _, replNumber = self:SplitOnFirstMatch(currentName, "_")
local currentOrder = toNumber(replNumber)
if (self:IsMappingActive(info) and currentOrder > Grichelde.MAPPING_OFFSET ) then
if (self:IsMappingActive(info) and (currentOrder > Grichelde.MAPPING_OFFSET)) then
return Grichelde.ICONS.MOVE_UP
else
return Grichelde.ICONS.MOVE_UP_DISABLED
@@ -634,12 +738,12 @@ function Grichelde:GetMoveDownImage(info)
local replacements = self.db.profile.replacements or {}
for replName, _ in pairs(replacements) do
local num = match(replName, "^replacement_(%d+)")
if num and maxRepl < toNumber(num) then
if (num ~= nil) and (maxRepl < toNumber(num)) then
maxRepl = toNumber(num)
end
end
if (self:IsMappingActive(info) and currentOrder < maxRepl) then
if (self:IsMappingActive(info) and (currentOrder < maxRepl)) then
return Grichelde.ICONS.MOVE_DOWN
else
return Grichelde.ICONS.MOVE_DOWN_DISABLED