Version 0.7.0-beta

- order buttons

- use numeric LogLevel over booleans
- exact case option reversed (again)
- smart case handling if replacement is longer than match

- Deletion of all mappings
This commit is contained in:
2020-06-06 14:33:06 +02:00
parent a29f6486fe
commit cb2c995a82
11 changed files with 564 additions and 357 deletions

View File

@@ -2,8 +2,8 @@
local _G = _G
local Grichelde = _G.Grichelde
local spairs, unpack, join, toString
= Grichelde.functions.spairs, Grichelde.functions.unpack, Grichelde.functions.join, Grichelde.functions.toString
local pairs, tInsert, tClone, unpack, join, toString
= Grichelde.functions.pairs, Grichelde.functions.tInsert, Grichelde.functions.tClone, Grichelde.functions.unpack, Grichelde.functions.join, Grichelde.functions.toString
function Grichelde:GetDefaultConfig()
return {
@@ -24,21 +24,28 @@ function Grichelde:GetDefaultConfig()
order = 9999,
searchText = "",
replaceText = "",
ignoreCase = true,
exactCase = false,
consolidate = true,
},
replacement_0 = {
order = 5,
replacement_10 = {
order = 10,
searchText = "s",
replaceText = "ch",
ignoreCase = true,
exactCase = false,
consolidate = true,
},
replacement_1 = {
order = 9,
replacement_11 = {
order = 11,
searchText = "t",
replaceText = "ck",
ignoreCase = true,
exactCase = false,
consolidate = true,
},
replacement_12 = {
order = 12,
searchText = "Zark",
replaceText = "toter Schamane",
exactCase = false,
consolidate = true,
}
}
@@ -59,10 +66,17 @@ function Grichelde:LoadDatabase()
end
function Grichelde:SyncToDatabase(info, val)
self:TracePrint("SyncToDatabase : info")
for i = 0, #info do
self:TracePrint("%d = %s", i, info[i])
end
local option = self.db.profile
local path = 1
while (path < #info) do
option = option[info[path]] -- or nil
if info[path] ~= "mappings" then
option = option[info[path]] -- or nil
end
path = path + 1
end
local optionPath = join(".", unpack(info, 1, #info))
@@ -71,36 +85,72 @@ function Grichelde:SyncToDatabase(info, val)
end
function Grichelde:ReadFromDatabase(info)
self:TracePrint("ReadFromDatabase : info")
for i = 0, #info do
self:TracePrint("%d = %s", i, info[i])
end
local option = self.db.profile
local path = 1
while (path <= #info) do
option = option[info[path]] -- or nil
if info[path] ~= "mappings" then
option = option[info[path]] -- or nil
end
path = path + 1
end
local optionPath = join(".", unpack(info, 1, #info))
self:TracePrint("read option \"%s\": %s", optionPath, toString(option))
self:DebugPrint("read option \"%s\": %s", optionPath, toString(option))
return option
end
--- Sorts a replacements table by order sub-field.
--- Usually called with with self.db.profile.replacements
-- @param replacementsTable table
-- @return table
function Grichelde:ReorderReplacements(replacementsTable)
local replacements = replacementsTable or {}
--- Sorts a replacements table by order sub-field and rename.
--- Do NOT reassign self.db.profile.replacements here or with its output as it will break defaults
function Grichelde:ReorderReplacements()
local replacements = self.db.profile.replacements or {}
self:TracePrint("ReorderReplacements : unsorted table")
self:TracePrint(replacementsTable)
self:TracePrint(replacements)
local sortedReplacements = {}
local index = 0
for _, replTable in spairs(replacements) do
sortedReplacements["replacement_" .. index] = replTable
sortedReplacements["replacement_" .. index].order = index
index = index + 1
local orderToName = {}
local size = 0
for replName, replTable in pairs(replacements) do
size = size + 1
tInsert(orderToName, replTable.order, replName)
end
self:TracePrint("ReorderReplacements : sorted table")
self:TracePrint(sortedReplacements)
return sortedReplacements
self:TracePrint("ReorderReplacements : size: %d, orderToName", size)
self:TracePrint(orderToName)
local sorted = {}
local index, count = 0, 0
while count < size do
local replName = orderToName[index]
if replName and replacements[replName] then
self:TracePrint("ReorderReplacements : replName: %s, replTable", replName)
self:TracePrint(replacements[replName])
local order = Grichelde.MAPPING_OFFSET + count
sorted["replacement_" .. order] = tClone(replacements[replName])
sorted["replacement_" .. order].order = order
count = count + 1
end
index = index + 1
if ( index > 10000) then break end
end
-- self:TracePrint("ReorderReplacements : sorted")
-- self:TracePrint(sorted)
-- do NOT set self.db.profile.replacements = {} it will break defaults
for replName, _ in pairs(replacements) do
replacements[replName] = nil
end
-- copy over sorted replacements
for replName, replTable in pairs(sorted) do
replacements[replName] = replTable
end
self:DebugPrint("ReorderReplacements : sorted table")
self:DebugPrint(self.db.profile.replacements)
end