@ -1,13 +1,11 @@
--[[--------------------------------------------------------------------------
--[[-------------------------------------------------------------------------- -
Grichelde
Grichelde
Copyright 2020 Teilzeit - Jedi < tj @ teilzeit - jedi.de >
Copyright 2020 Teilzeit - Jedi < tj @ teilzeit - jedi.de >
based on Misspelled developed by Nathan Pieper - nrpieper ( @ ) gmail ( dot ) com
based on Misspelled developed by Nathan Pieper - nrpieper ( @ ) gmail ( dot ) com
This code freely distributed for your use in any GPL compliant project .
This code freely distributed for your use in any GPL compliant project .
You may obtain a copy of the License at
See conditions in the LICENSE file attached .
http : // www.apache . org / licenses / LICENSE - 2.0
Unless required by applicable law or agreed to in writing , software
Unless required by applicable law or agreed to in writing , software
distributed under the License is distributed on an " AS IS " BASIS ,
distributed under the License is distributed on an " AS IS " BASIS ,
@ -17,29 +15,34 @@
--------------------------------------------------------------------------]] --
--------------------------------------------------------------------------]] --
local Grichelde = { }
local AddonName , AddonTable = ...
Grichelde = LibStub ( " AceAddon-3.0 " ) : NewAddon ( " Grichelde " , " AceEvent-3.0 " , " AceHook-3.0 " )
Grichelde.Version = " 0.1.0 "
local Grichelde = LibStub ( " AceAddon-3.0 " ) : NewAddon ( " Grichelde " , " AceEvent-3.0 " , " AceHook-3.0 " )
Grichelde.version = GetAddOnMetadata ( AddonName , " Version " )
Grichelde.build = GetAddOnMetadata ( AddonName , " X-Build " ) or " UNKNOWN "
local AceGUI = LibStub ( " AceGUI-3.0 " )
local L = LibStub ( " AceLocale-3.0 " ) : GetLocale ( " Grichelde " , true )
local L = LibStub ( " AceLocale-3.0 " ) : GetLocale ( " Grichelde " , true )
local Grichelde_Debug = false
-- faster function lookups by mapping to local refs
-- faster function lookups by mapping to local refs
local string_find = string.find
local string_find = string.find
local string_gsub = string.gsub
local string_gsub = string.gsub
local string_len = string.len
local string_len = string.len
local string_rep = string.rep
local string_rep = string.rep
local string_sub = string.sub
local string_sub = string.sub
local tostring = string.tostring
local tContains = tContains
local strtrim = strtrim
local strtrim = strtrim
local pairs = table.pairs
local strmatch = strmatch
local ipairs = table.ipairs
local tostring = tostring
local tInsert = table.insert
local tContains = tContains
local pairs = pairs
local ipairs = ipairs
local Grichelde_Saved_CTL_SendChatMessage
local Grichelde_Hooks = { }
local Grichelde_CTL_hookedversion = 0
local Grichelde_ChatTypes = { " SAY " , " EMOTE " , " YELL " , " PARTY " , " GUILD " , " OFFICER " , " RAID " , " RAID_WARNING " , " INSTANCE_CHAT " , " BATTLEGROUND " , " WHISPER " }
--local Grichelde_ChatTypes = { "SAY", "EMOTE", "YELL", "PARTY", "GUILD", "OFFICER", "RAID", "RAID_WARNING", "INSTANCE_CHAT", "BATTLEGROUND", "WHISPER" }
local Grichelde_ChatTypes = { " SAY " , " EMOTE " , " YELL " , " PARTY " , " GUILD " }
local Grichelde_ChatCommands = { " /s " , " /e " , " /me " , " /y " , " /p " , " /pl " , " /g " , " /o " , " /raid " , " /rl " , " /rw " , " /i " , " bg " , " /w " , " /r " , " /tt " }
local Grichelde_ChatCommands = { " /s " , " /e " , " /me " , " /y " , " /p " , " /pl " , " /g " , " /o " , " /raid " , " /rl " , " /rw " , " /i " , " bg " , " /w " , " /r " , " /tt " }
-- do not replace these patterns
-- do not replace these patterns
@ -62,62 +65,91 @@ local Grichelde_IgnorePatterns = {
}
}
function Grichelde : OnInitialize ( )
function Grichelde : OnInitialize ( )
-- print("Grichelde was loaded")
-- Build Interface Options window
-- Build Interface Options window
self : CreateInterfaceOptions ( )
--self:CreateInterfaceOptions()
-- Watch for WIM and Prat to Load, then integrate
-- Watch for WIM and Prat to Load, then integrate
Grichelde : RegisterEvent ( " ADDON_LOADED " )
self : RegisterEvent ( " ADDON_LOADED " , " HookIntoForOtherChatAddons " )
end
function Grichelde : OnEnable ( )
-- Hook in before message is sent to replace all character occurrences where replacements have been defined in the options
self : RawHook ( " SendChatMessage " , true )
if ( Misspelled ) then
print ( " Misspelled detected, Grichelde will have any messsage being cleansed " )
end
-- tell the world we are listening
print ( L.AddonLoaded )
end
-- hooks for removing any misspelled word highlighting in the text before the chat message is sent
function Grichelde : OnDisable ( )
-- The WoW client will disconnect if you attempt to send a color tags in a chat message.
self : Unhook ( " SendChatMessage " )
Grichelde : RawHook ( " SendChatMessage " , true )
end
end
--- @param event string
--- @param event string
--- @param addonName string
--- @param addonName string
function Grichelde : ADDON_LOADED ( event , addonName )
function Grichelde : HookIntoForOtherChatAddons ( event , addonName )
if event == " ADDON_LOADED " and addonName == " WIM " then
if event == " ADDON_LOADED " then
if addonName == " WIM " then
WIM.RegisterWidgetTrigger ( " msg_box " , " whisper,chat,w2w " , " OnEnterPressed " , Grichelde.EditBox_OnEnterPressed )
WIM.RegisterWidgetTrigger ( " msg_box " , " whisper,chat,w2w " , " OnEnterPressed " , Grichelde.EditBox_OnEnterPressed )
-- WIM sends its chat messages via the API ChatThrottleLib, which itself hooks the default SendChatMessage api
-- If available use the WIM API
-- many times before Grichelde will. ChatThrottleLib might potentially load before Grichelde, so we just hook
-- into ChatThrottleLib to be on the safe side.
if ( WIM.RegisterPreSendFilterText ) then -- avoid error if WIM not up to date.
if ( WIM.RegisterPreSendFilterText ) then -- avoid error if WIM not up to date.
WIM.RegisterPreSendFilterText ( function ( text )
WIM.RegisterPreSendFilterText ( function ( text )
return Grichelde : ReplaceText ( text )
return Grichelde : CheckAndReplace ( text )
end )
end )
else
else
if ( ChatThrottleLib and Grichelde_CTL_hookedversion < ChatThrottleLib.version ) then
-- WIM sends its chat messages via the API ChatThrottleLib, which itself hooks the default SendChatMessage api
Grichelde_Saved_CTL_SendChatMessage = ChatThrottleLib.SendChatMessage
-- many times before Grichelde will. ChatThrottleLib might potentially load before Grichelde, so we just hook
-- into ChatThrottleLib to be on the safe side.
if ( ChatThrottleLib ) then
Grichelde_Hooks [ " ChatThrottleLib " ] = ChatThrottleLib.SendChatMessage
function ChatThrottleLib : SendChatMessage ( prio , prefix , text , ... )
function ChatThrottleLib : SendChatMessage ( prio , prefix , text , ... )
text = Grichelde : ReplaceText ( text )
Grichelde : DebugPrint ( " ChatThrottleLib:SendChatMessage : Hook called " )
-- print("Grichelde Hooked ChatThrottleLib_SendChatMessaged called")
local replacedText = Grichelde : CheckAndReplace ( text )
return Grichelde_Saved_CTL_SendChatMessage ( ChatThrottleLib , prio , prefix , text , ... )
return Grichelde_Hooks [ " ChatThrottleLib " ] ( ChatThrottleLib , prio , prefix , replacedText , ... )
end
end
end
Grichelde_CTL_hookedversion = ChatThrottleLib.version
end
end
end
end
end
end
end
end
--- Before a chat message is sent, check if replacement is required and replace the text accordingly.
--- Before a f chat message is sent, check if replacement is required and replace the text accordingly.
--- @param message string
--- @param message string
--- @param type string
--- @param type string
--- @param language string
--- @param language string
--- @param channel string
--- @param channel string
function Grichelde : SendChatMessage ( message , type , language , channel , ... )
function Grichelde : SendChatMessage ( message , type , language , channel , ... )
local text = strtrim ( message )
local replacedText = self : CheckAndReplace ( message , type )
self : DebugPrint ( " SendChatMessage : replacedText: " .. replacedText )
-- Send text in chunks if length exceeds 255 bytes after replacement
local chunks = self : SplitText ( replacedText )
self : DebugPrint ( " SendChatMessage : #chunks: " .. # chunks )
if ( Grichelde : CheckReplacement ( message , type ) ) then
for _ , chunk in ipairs ( chunks ) do
text = Grichelde : ReplaceText ( text )
self.hooks[ " SendChatMessage " ] ( chunk , type , language , channel , ... ) ;
end
end
end
function Grichelde : CheckAndReplace ( message , type )
local text = message
if ( Misspelled ) then
self : DebugPrint ( " Misspelled detected: cleansing message " )
text = Misspelled : RemoveHighlighting ( text )
end
text = strtrim ( text )
self.hooks [ " SendChatMessage " ] ( text , type , language , channel , ... ) ;
if ( self : CheckReplacement ( text , type ) ) then
text = self : ReplaceText ( text )
end
return text
end
end
function Grichelde : CheckReplacement ( text , type )
function Grichelde : CheckReplacement ( text , type )
@ -125,20 +157,41 @@ function Grichelde:CheckReplacement(text, type)
-- check type
-- check type
if ( not tContains ( Grichelde_ChatTypes , type ) ) then
if ( not tContains ( Grichelde_ChatTypes , type ) ) then
self : DebugPrint ( " CheckReplacement : skip channel type " )
return false
return false
end
end
-- don't replace slash commands except chat related commands
-- don't replace slash commands except chat related commands
if string_sub ( text , 1 , 1 ) == " / " then
if string_sub ( text , 1 , 1 ) == " / " then
local firstWord , _ = Grichelde: GetNextWord ( text )
local firstWord , _ = self: SplitOnFirstMatch ( text )
if ( firstWord == nil or not tContains ( Grichelde_ChatCommands , firstWord ) ) then
if ( firstWord == nil or not tContains ( Grichelde_ChatCommands , firstWord ) ) then
self : DebugPrint ( " CheckReplacement : ignore slash command " )
return false
return false
end
end
end
end
-- in any other case
return true
return true
end
end
--- Checks if the text starts with a preversable ignore pattern, such as itemLinks, textures or raid target icons
--- and returns the end location of the match, or 0 if no pattern was found
--- @param text string
--- @return number
function Grichelde : CheckForPreversableText ( text )
self : DebugPrint ( " CheckForPreversableText : text is " .. text )
-- Calling find on ever pattern might be inefficient but its way less code.
for _ , pattern in ipairs ( Grichelde_IgnorePatterns ) do
local pos1 , pos2 = string_find ( text , pattern )
if pos1 == 1 and pos2 ~= nil then
self : DebugPrint ( " CheckForPreversableText : Found ignore pattern " .. pattern .. " at ( " .. pos1 .. " , " .. pos2 .. " ) " )
return pos2
end
end
self : DebugPrint ( " CheckForPreversableText : no ignore pattern found " )
return 0
end
--- Replaces all character occurrences for which replacements have been defined in the options,
--- Replaces all character occurrences for which replacements have been defined in the options,
--- while preserving any itemLinks or textures. (http://www.wowwiki.com/ItemLink)
--- while preserving any itemLinks or textures. (http://www.wowwiki.com/ItemLink)
--- @param text string
--- @param text string
@ -148,8 +201,9 @@ function Grichelde:ReplaceText(text)
local newText = text
local newText = text
-- don't replace non-chat related slash commands
-- don't replace non-chat related slash commands
local firstWord , line = Grichelde : GetNextWord ( text )
local firstWord , line = self : SplitOnFirstMatch ( text )
if ( tContains ( Grichelde_ChatCommands , firstWord ) ) then
if ( firstWord ~= nil and tContains ( Grichelde_ChatCommands , firstWord ) ) then
self : DebugPrint ( " ReplaceText : Found slash command " .. ( firstWord + " " ) )
-- skip chat slash command
-- skip chat slash command
finalText = finalText .. firstWord .. ' '
finalText = finalText .. firstWord .. ' '
newText = line
newText = line
@ -158,22 +212,28 @@ function Grichelde:ReplaceText(text)
local current = 1
local current = 1
local lastStart = 1
local lastStart = 1
while current < string_len ( newText ) do
while current < = string_len ( newText ) do
local currentChar = string_sub ( newText , current , current )
local currentChar = string_sub ( newText , current , current )
self : DebugPrint ( " current/char : " .. current .. " , " .. currentChar )
if currentChar ~= ' | ' and currentChar ~= ' { ' then
if currentChar ~= ' | ' and currentChar ~= ' { ' then
current = current + 1
current = current + 1
else
else
-- lookahead-check for itemLinks, textures and raid target icons
-- lookahead-check for itemLinks, textures and raid target icons
local textAhead = string_sub ( newText , current )
local textAhead = string_sub ( newText , current )
local posEnd = Grichelde : CheckForPreversableText ( textAhead )
local posEnd = self : CheckForPreversableText ( textAhead )
if posEnd > 0 then
if posEnd > 0 then
self : DebugPrint ( " ReplaceText : Found an ignore pattern " )
local textBehind = string_sub ( newText , lastStart , current - 1 )
local textBehind = string_sub ( newText , lastStart , current - 1 )
local replacement = Grichelde : ReplaceCharacters ( textBehind )
local replacement = self : ReplaceCharacters ( textBehind )
local preservedText = string_sub ( textAhead , 1 , posEnd )
local preservedText = string_sub ( textAhead , 1 , posEnd )
finalText = finalText .. replacement .. preservedText
finalText = finalText .. replacement .. preservedText
current = current + posEnd
current = current + posEnd
lastStart = current
lastStart = current
self : DebugPrint ( " ReplaceText : restarting at " .. lastStart )
else
else
-- no corresponding end was found to start pattern, continue loop with next char
-- no corresponding end was found to start pattern, continue loop with next char
current = current + 1
current = current + 1
@ -181,29 +241,14 @@ function Grichelde:ReplaceText(text)
end
end
end
end
-- cleanup to the end
-- cleanup remaining text to the end
local remainingText = newText
local remainingText = string_sub ( newText , lastStart )
if lastStart ~= 1 then
local replacement = self : ReplaceCharacters ( remainingText )
remainingText = string_sub ( newText , lastStart )
end
local replacement = Grichelde : ReplaceCharacters ( remainingText )
finalText = finalText .. replacement
finalText = finalText .. replacement
return finalText
end
--- Checks if the text starts with a preversable ignore pattern, such as itemLinks, textures or raid target icons
self : DebugPrint ( " ReplaceText : replaced \" " .. text .. " \" " )
--- @param text string
self : DebugPrint ( " ReplaceText : with \" " .. finalText .. " \" " )
--- @return number
return finalText
function Grichelde : CheckForPreversableText ( text )
-- Calling find on ever pattern might be inefficient but its way less code.
for _ , pattern in ipairs ( Grichelde_IgnorePatterns ) do
local pos1 , pos2 = string_find ( text , pattern )
if pos1 == 1 and pos2 ~= nil then
return pos2
end
end
return 0
end
end
--- Replaces all character occurrences for which replacements have been defined in the options
--- Replaces all character occurrences for which replacements have been defined in the options
@ -217,258 +262,82 @@ function Grichelde:ReplaceCharacters(text)
replacement = string_gsub ( replacement , " S " , " Ch " )
replacement = string_gsub ( replacement , " S " , " Ch " )
replacement = string_gsub ( replacement , " t " , " k " )
replacement = string_gsub ( replacement , " t " , " k " )
replacement = string_gsub ( replacement , " T " , " K " )
replacement = string_gsub ( replacement , " T " , " K " )
self : DebugPrint ( " ReplaceCharacters : replaced \" " .. text .. " \" with \" " .. replacement .. " \" " )
return replacement
return replacement
end
end
--- Splits a long text in longest possible chunks of <= 255 length, split at last available space
--- @param text string
--- @return table
function Grichelde : SplitText ( text )
local chunks = { }
local splitText = text
local textSize = string_len ( splitText )
--[[ Interface Options Window ]] --
while textSize > 255 do
function Grichelde : CreateInterfaceOptions ( )
local chunk = string_sub ( splitText , 1 , 255 )
local cfgFrame = CreateFrame ( " FRAME " , nil , UIParent )
local remaining = " "
cfgFrame.name = " Grichelde "
local cfgFrameHeader = cfgFrame : CreateFontString ( " OVERLAY " , nil , " GameFontNormalLarge " )
cfgFrameHeader : SetPoint ( " TOPLEFT " , 15 , - 15 )
cfgFrameHeader : SetText ( self.Version )
local cfgAutoSelectDict = CreateFrame ( " CHECKBUTTON " , " Misspelled_cfgAutoSelectDict " , cfgFrame , " InterfaceOptionsCheckButtonTemplate " )
-- special case: if space is the start of the next chunk, don't split this chunk
Misspelled_cfgAutoSelectDict : SetPoint ( " TOPLEFT " , 20 , - 40 )
if string_sub ( splitText , 256 , 256 ) ~= ' ' then
Misspelled_cfgAutoSelectDictText : SetText ( L [ " Auto Select Dictionary to Load " ] )
-- split at last space, don't assign directly as nil might be returned
Misspelled_cfgAutoSelectDict : SetChecked ( Misspelled_DB.AutoSelectDictionary )
local left , right = self : SplitOnLastMatch ( chunk )
Misspelled_cfgAutoSelectDict : SetScript ( " OnClick " , function ( self )
if left ~= nil then
if self : GetChecked ( ) then
chunk = left
PlaySound ( 856 ) -- SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON
else
PlaySound ( 857 ) -- SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_OFF
end
Misspelled_DB.AutoSelectDictionary = not Misspelled_DB.AutoSelectDictionary
--Toggle the sub options
if Misspelled_DB.AutoSelectDictionary == true then
Misspelled_cfgDictdeDE : Disable ( )
Misspelled_cfgDictenGB : Disable ( )
Misspelled_cfgDictenUS : Disable ( )
Misspelled_cfgDictesES : Disable ( )
Misspelled_cfgDictfrFR : Disable ( )
Misspelled_cfgDictruRU : Disable ( )
Misspelled_cfgDictitIT : Disable ( )
else
Misspelled_cfgDictdeDE : Enable ( )
Misspelled_cfgDictenGB : Enable ( )
Misspelled_cfgDictenUS : Enable ( )
Misspelled_cfgDictesES : Enable ( )
Misspelled_cfgDictfrFR : Enable ( )
Misspelled_cfgDictruRU : Enable ( )
Misspelled_cfgDictitIT : Enable ( )
if Misspelled_DB.LoadDictionary == nil or # Misspelled_DB.LoadDictionary == 0 then
Misspelled_DB.LoadDictionary = " enUS "
Misspelled_cfgDictenUS : setChecked ( true )
end
end
if right ~= nil then
remaining = right
end
end
end )
local cfgDictdeDE = CreateFrame ( " CHECKBUTTON " , " Misspelled_cfgDictdeDE " , cfgFrame , " InterfaceOptionsCheckButtonTemplate " )
Misspelled_cfgDictdeDE : SetPoint ( " TOPLEFT " , 40 , - 64 )
Misspelled_cfgDictdeDEText : SetText ( " deDE " )
Misspelled_cfgDictdeDE : SetChecked ( Misspelled_DB.LoadDictionary == " deDE " )
Misspelled_cfgDictdeDE : SetScript ( " OnClick " , function ( self )
if self : GetChecked ( ) then
PlaySound ( 856 ) -- SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON
Misspelled_DB.LoadDictionary = " deDE "
Misspelled_cfgDictenGB : SetChecked ( false )
Misspelled_cfgDictenUS : SetChecked ( false )
Misspelled_cfgDictesES : SetChecked ( false )
Misspelled_cfgDictfrFR : SetChecked ( false )
Misspelled_cfgDictruRU : SetChecked ( false )
Misspelled_cfgDictitIT : SetChecked ( false )
else
PlaySound ( 857 ) -- SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_OFF
end
end
end )
local cfgDictenGB = CreateFrame ( " CHECKBUTTON " , " Misspelled_cfgDictenGB " , cfgFrame , " InterfaceOptionsCheckButtonTemplate " )
self : DebugPrint ( " SplitText : chunk: " .. chunk )
Misspelled_cfgDictenGB : SetPoint ( " TOPLEFT " , 40 , - 88 )
Misspelled_cfgDictenGBText : SetText ( " enGB " )
Misspelled_cfgDictenGB : SetChecked ( Misspelled_DB.LoadDictionary == " enGB " )
Misspelled_cfgDictenGB : SetScript ( " OnClick " , function ( self )
if self : GetChecked ( ) then
PlaySound ( 856 ) -- SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON
Misspelled_DB.LoadDictionary = " enGB "
Misspelled_cfgDictdeDE : SetChecked ( false )
Misspelled_cfgDictenUS : SetChecked ( false )
Misspelled_cfgDictesES : SetChecked ( false )
Misspelled_cfgDictfrFR : SetChecked ( false )
Misspelled_cfgDictruRU : SetChecked ( false )
Misspelled_cfgDictitIT : SetChecked ( false )
else
PlaySound ( 857 ) -- SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_OFF
end
end )
local cfgDictenUS = CreateFrame ( " CHECKBUTTON " , " Misspelled_cfgDictenUS " , cfgFrame , " InterfaceOptionsCheckButtonTemplate " )
tInsert ( chunks , chunk )
Misspelled_cfgDictenUS : SetPoint ( " TOPLEFT " , 40 , - 112 )
splitText = remaining .. string_sub ( splitText , 256 )
Misspelled_cfgDictenUSText : SetText ( " enUS " )
textSize = string_len ( splitText )
Misspelled_cfgDictenUS : SetChecked ( Misspelled_DB.LoadDictionary == " enUS " )
Misspelled_cfgDictenUS : SetScript ( " OnClick " , function ( self )
if self : GetChecked ( ) then
PlaySound ( 856 ) -- SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON
Misspelled_DB.LoadDictionary = " enUS "
Misspelled_cfgDictdeDE : SetChecked ( false )
Misspelled_cfgDictenGB : SetChecked ( false )
Misspelled_cfgDictesES : SetChecked ( false )
Misspelled_cfgDictfrFR : SetChecked ( false )
Misspelled_cfgDictruRU : SetChecked ( false )
Misspelled_cfgDictitIT : SetChecked ( false )
else
PlaySound ( 857 ) -- SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_OFF
end
end
end )
local cfgDictesES = CreateFrame ( " CHECKBUTTON " , " Misspelled_cfgDictesES " , cfgFrame , " InterfaceOptionsCheckButtonTemplate " )
-- pickup remaining text < 255
Misspelled_cfgDictesES : SetPoint ( " TOPLEFT " , 40 , - 136 )
self : DebugPrint ( " SplitText : last chunk: " .. splitText )
Misspelled_cfgDictesESText : SetText ( " esES " )
tInsert ( chunks , splitText )
Misspelled_cfgDictesES : SetChecked ( Misspelled_DB.LoadDictionary == " esES " )
Misspelled_cfgDictesES : SetScript ( " OnClick " , function ( self )
if self : GetChecked ( ) then
PlaySound ( 856 ) -- SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON
Misspelled_DB.LoadDictionary = " esES "
Misspelled_cfgDictdeDE : SetChecked ( false )
Misspelled_cfgDictenGB : SetChecked ( false )
Misspelled_cfgDictenUS : SetChecked ( false )
Misspelled_cfgDictfrFR : SetChecked ( false )
Misspelled_cfgDictruRU : SetChecked ( false )
Misspelled_cfgDictitIT : SetChecked ( false )
else
PlaySound ( 857 ) -- SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_OFF
end
end )
local cfgDictfrFR = CreateFrame ( " CHECKBUTTON " , " Misspelled_cfgDictfrFR " , cfgFrame , " InterfaceOptionsCheckButtonTemplate " )
return chunks
Misspelled_cfgDictfrFR : SetPoint ( " TOPLEFT " , 40 , - 160 )
Misspelled_cfgDictfrFRText : SetText ( " frFR " )
Misspelled_cfgDictfrFR : SetChecked ( Misspelled_DB.LoadDictionary == " frFR " )
Misspelled_cfgDictfrFR : SetScript ( " OnClick " , function ( self )
if self : GetChecked ( ) then
PlaySound ( 856 ) -- SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON
Misspelled_DB.LoadDictionary = " frFR "
Misspelled_cfgDictdeDE : SetChecked ( false )
Misspelled_cfgDictenGB : SetChecked ( false )
Misspelled_cfgDictenUS : SetChecked ( false )
Misspelled_cfgDictesES : SetChecked ( false )
Misspelled_cfgDictruRU : SetChecked ( false )
Misspelled_cfgDictitIT : SetChecked ( false )
else
PlaySound ( 857 ) -- SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_OFF
end
end
end )
local cfgDictruRU = CreateFrame ( " CHECKBUTTON " , " Misspelled_cfgDictruRU " , cfgFrame , " InterfaceOptionsCheckButtonTemplate " )
-- split first word of a text line
Misspelled_cfgDictruRU : SetPoint ( " TOPLEFT " , 40 , - 184 )
function Grichelde : SplitOnFirstMatch ( text , start )
Misspelled_cfgDictruRUText : SetText ( " ruRU " )
self : DebugPrint ( " SplitOnFirstMatch : text: " .. text .. " , start: " .. self : EmptyIfNil ( start ) )
Misspelled_cfgDictruRU : SetChecked ( Misspelled_DB.LoadDictionary == " ruRU " )
local pos = 1
Misspelled_cfgDictruRU : SetScript ( " OnClick " , function ( self )
if start ~= nil then pos = start end
if self : GetChecked ( ) then
local left , right = strmatch ( text , " ^.- .+ " , pos )
PlaySound ( 856 ) -- SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON
self : DebugPrint ( " SplitOnFirstMatch : left: " .. self : EmptyIfNil ( left ) .. " , right: " .. self : EmptyIfNil ( right ) )
Misspelled_DB.LoadDictionary = " ruRU "
return left , right
Misspelled_cfgDictdeDE : SetChecked ( false )
Misspelled_cfgDictenGB : SetChecked ( false )
Misspelled_cfgDictenUS : SetChecked ( false )
Misspelled_cfgDictfrFR : SetChecked ( false )
Misspelled_cfgDictesES : SetChecked ( false )
Misspelled_cfgDictitIT : SetChecked ( false )
else
PlaySound ( 857 ) -- SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_OFF
end
end
end )
local cfgDictitIT = CreateFrame ( " CHECKBUTTON " , " Misspelled_cfgDictitIT " , cfgFrame , " InterfaceOptionsCheckButtonTemplate " )
function Grichelde : SplitOnLastMatch ( text , start )
Misspelled_cfgDictitIT : SetPoint ( " TOPLEFT " , 40 , - 208 )
self : DebugPrint ( " SplitOnLastMatch : text: " .. text .. " , start: " .. self : EmptyIfNil ( start ) )
Misspelled_cfgDictitITText : SetText ( " itIT " )
local pos = 1
Misspelled_cfgDictitIT : SetChecked ( Misspelled_DB.LoadDictionary == " itIT " )
if start ~= nil then pos = start end
Misspelled_cfgDictitIT : SetScript ( " OnClick " , function ( self )
local left , right = strmatch ( text , " .+ .-$ " , pos )
if self : GetChecked ( ) then
self : DebugPrint ( " SplitOnLastMatch : left: " .. self : EmptyIfNil ( left ) .. " , right: " .. self : EmptyIfNil ( right ) )
PlaySound ( 856 ) -- SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON
return left , right
Misspelled_DB.LoadDictionary = " itIT "
Misspelled_cfgDictdeDE : SetChecked ( false )
Misspelled_cfgDictenGB : SetChecked ( false )
Misspelled_cfgDictenUS : SetChecked ( false )
Misspelled_cfgDictfrFR : SetChecked ( false )
Misspelled_cfgDictesES : SetChecked ( false )
Misspelled_cfgDictruRU : SetChecked ( false )
else
PlaySound ( 857 ) -- SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_OFF
end
end
end )
--Edit User Dictionary Button
function Grichelde : DebugPrint ( message )
local cfgEditUserDict = CreateFrame ( " Button " , " EdutUserDictButton " , cfgFrame , " UIPanelButtonTemplate " )
if ( Grichelde_Debug ) then
cfgEditUserDict : SetPoint ( " TOPLEFT " , 20 , - 287 )
print ( GRAY_FONT_COLOR_CODE .. " Grichelde: " .. FONT_COLOR_CODE_CLOSE .. " " .. message )
cfgEditUserDict : SetText ( L [ " Edit User Dictionary... " ] )
cfgEditUserDict : SetWidth ( 200 )
cfgEditUserDict : SetHeight ( 24 )
cfgEditUserDict : SetScript ( " OnClick " , function ( self )
--PlaySound("igMainMenuOptionCheckBoxOn")
Misspelled : EditUserDict ( )
end )
--set options on startup
Misspelled_cfgDictdeDE : SetChecked ( false )
Misspelled_cfgDictenUS : SetChecked ( false )
Misspelled_cfgDictenGB : SetChecked ( false )
Misspelled_cfgDictesES : SetChecked ( false )
Misspelled_cfgDictfrFR : SetChecked ( false )
Misspelled_cfgDictruRU : SetChecked ( false )
Misspelled_cfgDictitIT : SetChecked ( false )
if Misspelled_DB.LoadDictionary == " deDE " then
Misspelled_cfgDictdeDE : SetChecked ( true )
elseif Misspelled_DB.LoadDictionary == " enGB " then
Misspelled_cfgDictenGB : SetChecked ( true )
elseif Misspelled_DB.LoadDictionary == " enUS " then
Misspelled_cfgDictenUS : SetChecked ( true )
elseif Misspelled_DB.LoadDictionary == " esES " then
Misspelled_cfgDictesES : SetChecked ( true )
elseif Misspelled_DB.LoadDictionary == " frFR " then
Misspelled_cfgDictfrFR : SetChecked ( true )
elseif Misspelled_DB.LoadDictionary == " ruRU " then
Misspelled_cfgDictruRU : SetChecked ( true )
elseif Misspelled_DB.LoadDictionary == " itIT " then
Misspelled_cfgDictitIT : SetChecked ( true )
end
if Misspelled_DB.AutoSelectDictionary == true then
Misspelled_cfgDictdeDE : Disable ( )
Misspelled_cfgDictenGB : Disable ( )
Misspelled_cfgDictenUS : Disable ( )
Misspelled_cfgDictesES : Disable ( )
Misspelled_cfgDictfrFR : Disable ( )
Misspelled_cfgDictruRU : Disable ( )
Misspelled_cfgDictitIT : Disable ( )
else
Misspelled_cfgDictdeDE : Enable ( )
Misspelled_cfgDictenGB : Enable ( )
Misspelled_cfgDictenUS : Enable ( )
Misspelled_cfgDictesES : Enable ( )
Misspelled_cfgDictfrFR : Enable ( )
Misspelled_cfgDictruRU : Enable ( )
Misspelled_cfgDictitIT : Enable ( )
end
end
InterfaceOptions_AddCategory ( cfgFrame )
end
end
function Grichelde : EmptyIfNil ( value )
-- split first word of a text line
if value == nil then return " " end
function Grichelde : GetNextWord ( line )
return tostring ( value )
-- need to add a trailing separator to catch the last value.
local wordPattern = " [%s%c]*(%w+)[%s%c]* "
local s , e = string_find ( line , wordPattern )
local word = string_sub ( line , s , e )
local rest = string_sub ( line , e )
return word , rest
end
end
function Grichelde : tprint ( t , indent , done )
function Grichelde : tprint ( t , indent , done )
-- in case we run it standalone
-- in case we run it standalone
local Note = Note or print
local Note = Note or print
-- local Tell = Tell or io.write
-- show strings differently to distinguish them from numbers
-- show strings differently to distinguish them from numbers
local function show ( val )
local function show ( val )
@ -487,14 +356,10 @@ function Grichelde:tprint(t, indent, done)
if type ( value ) == " table " and not done [ value ] then
if type ( value ) == " table " and not done [ value ] then
done [ value ] = true
done [ value ] = true
Note ( show ( key ) , " : " ) ;
Note ( show ( key ) , " : " ) ;
Grichelde : tprint ( value , indent + 2 , done )
self : tprint ( value , indent + 2 , done )
else
else
print ( show ( key ) , " = " )
print ( show ( key ) , " = " )
print ( show ( value ) )
print ( show ( value ) )
end
end
end
end
end
end
function Grichelde : print ( ... )
SELECTED_DOCK_FRAME : AddMessage ( ... )
end