@ -406,24 +406,48 @@ function Grichelde:SetupOptions()
return options , dialog
return options , dialog
end
end
function Grichelde : RefreshOptions ( event , _ , profileName )
function Grichelde : RefreshProfiles ( event , _ , profileName )
self : DebugPrint ( " RefreshOptions : event: " , event )
local function replaceReplacements ( replacements )
-- do NOT set self.db.profile.replacements = {} it will break defaults
tWipe ( self.db . profile.replacements )
-- copy over sorted replacements
for replName , replTable in pairs ( replacements ) do
self.db . profile.replacements [ replName ] = replTable
end
self : DebugPrint ( " RefreshProfiles : reorderReplacements : sorted table " )
self : DebugPrint ( self.db . profile.replacements )
end
local function addEmptyMappingWithoutRefresh ( )
self : DebugPrint ( " RefreshProfiles : addEmptyMappingWithoutRefresh " )
self.db . profile.replacements . replacement_10.order = 10
end
self : DebugPrint ( " RefreshProfiles : event: " , event )
--- AceDB will call OnProfileShutdown, OnProfileChanged and OnNewProfile in this order
if ( event == " OnNewProfile " ) then
if ( event == " OnNewProfile " ) then
addEmptyMappingWithoutRefresh ( )
self : PrefixedPrint ( self.L . Profiles_Created , cGreen ( self.db : GetCurrentProfile ( ) ) )
self : PrefixedPrint ( self.L . Profiles_Created , cGreen ( self.db : GetCurrentProfile ( ) ) )
elseif ( event == " OnProfileChanged " ) then
elseif ( event == " OnProfileChanged " ) then
self : PrefixedPrint ( self.L . Profiles_Loaded , cGreen ( self.db : GetCurrentProfile ( ) ) )
self : Debug Print( self.L . Profiles_Loaded , cGreen ( self.db : GetCurrentProfile ( ) ) )
elseif ( event == " OnProfileDeleted " ) then
elseif ( event == " OnProfileDeleted " ) then
self : PrefixedPrint ( self.L . Profiles_Deleted , cRed ( profileName ) )
self : PrefixedPrint ( self.L . Profiles_Deleted , cRed ( profileName ) )
elseif ( event == " OnProfileCopied " ) then
elseif ( event == " OnProfileCopied " ) then
self : PrefixedPrint ( self.L . Profiles_Copied , cOrange ( profileName ) )
self : Debug Print( self.L . Profiles_Copied , cOrange ( profileName ) )
elseif ( event == " OnProfileReset " ) then
elseif ( event == " OnProfileReset " ) then
addEmptyMappingWithoutRefresh ( )
self : PrefixedPrint ( self.L . Profiles_Reset , cOrange ( self.db : GetCurrentProfile ( ) ) )
self : PrefixedPrint ( self.L . Profiles_Reset , cOrange ( self.db : GetCurrentProfile ( ) ) )
else
else
self : DebugPrint ( " Refreshing Profile %s on options change: %s " , self.db : GetCurrentProfile ( ) , event )
self : DebugPrint ( " Refreshing Profile %s on options change: %s " , self.db : GetCurrentProfile ( ) , event )
end
end
self : ReorderReplacements ( )
local repls = self : ReorderReplacements ( )
self : RefreshReplacements ( self.db . profile.replacements )
replaceReplacements ( repls )
self : RefreshOptions ( repls )
self : RefreshDialog ( )
self : RefreshMinimap ( )
end
end
function Grichelde : ToggleOptions ( )
function Grichelde : ToggleOptions ( )
@ -556,19 +580,17 @@ function Grichelde:ImportExample(num)
self.db : SetProfile ( profileName )
self.db : SetProfile ( profileName )
assert ( self.db : GetCurrentProfile ( ) == profileName , " profile was not loaded " )
assert ( self.db : GetCurrentProfile ( ) == profileName , " profile was not loaded " )
local exampleProfile = self.db . profile
tWipe ( self.db . profile.replacements )
tWipe ( exampleProfile.replacements )
for replName , replTable in spairs ( self.L . Options_Help_Examples [ num ] . replacements ) do
for replName , replTable in spairs ( self.L . Options_Help_Examples [ num ] . replacements ) do
self : TracePrint ( " ImportExample : replacement: %s " , replName )
self : TracePrint ( " ImportExample : replacement: %s " , replName )
self : TracePrint ( replTable )
self : TracePrint ( replTable )
if ( replName ~= nil ) and ( replTable ~= nil ) and ( replTable.searchText ~= nil ) then
if ( replName ~= nil ) and ( replTable ~= nil ) and ( replTable.searchText ~= nil ) then
exampleP rofile.replacements[ replName ] = tClone ( replTable )
self.db. p rofile.replacements[ replName ] = tClone ( replTable )
end
end
end
end
self : Refresh Replacements( self.db . profile.replacements )
self : Refresh Profiles( " ImportExample " .. num )
else
else
self : ErrorPrint ( self.L . Profiles_AlreadyExistsError , profileName )
self : ErrorPrint ( self.L . Profiles_AlreadyExistsError , profileName )
end
end
@ -577,8 +599,8 @@ end
--- Create UI options for the given replacement table (from DB).
--- Create UI options for the given replacement table (from DB).
--- Usually called with with self.db.profile.replacements
--- Usually called with with self.db.profile.replacements
-- @param replacementsTable
-- @param replacementsTable
function Grichelde : Refresh Replacement s( replacementsTable )
function Grichelde : Refresh Option s( replacementsTable )
self : TracePrint ( " Refresh Replacement s : DB table:" )
self : TracePrint ( " Refresh Option s : DB table:" )
self : TracePrint ( replacementsTable )
self : TracePrint ( replacementsTable )
-- remove all previous replacements from options (not DB), except header and buttons
-- remove all previous replacements from options (not DB), except header and buttons
@ -594,9 +616,11 @@ function Grichelde:RefreshReplacements(replacementsTable)
replacements [ replName ] = self : CreateMapping ( toNumber ( replNumber ) )
replacements [ replName ] = self : CreateMapping ( toNumber ( replNumber ) )
end
end
-- self:TracePrint("Refresh Replacement s : UI options:")
-- self:TracePrint("Refresh Option s : UI options:")
-- self:TracePrint(replacements)
-- self:TracePrint(replacements)
end
function Grichelde : RefreshDialog ( )
self.dialog : ConfigTableChanged ( nil , self.name )
self.dialog : ConfigTableChanged ( nil , self.name )
end
end
@ -606,7 +630,7 @@ function Grichelde:AddEmptyMapping()
self : DebugPrint ( " AddEmptyMapping : old DB entries: " )
self : DebugPrint ( " AddEmptyMapping : old DB entries: " )
self : DebugPrint ( replacements )
self : DebugPrint ( replacements )
local maxRepl = Grichelde.MAPPING_OFFSET
local maxRepl = Grichelde.MAPPING_OFFSET - 1
for replName , _ in pairs ( replacements ) do
for replName , _ in pairs ( replacements ) do
local num = match ( replName , " ^replacement_(%d+) " )
local num = match ( replName , " ^replacement_(%d+) " )
if ( num ~= nil ) and ( maxRepl < toNumber ( num ) ) then
if ( num ~= nil ) and ( maxRepl < toNumber ( num ) ) then
@ -622,7 +646,7 @@ function Grichelde:AddEmptyMapping()
self : DebugPrint ( " AddEmptyMapping : new DB entries: " )
self : DebugPrint ( " AddEmptyMapping : new DB entries: " )
self : DebugPrint ( replacements )
self : DebugPrint ( replacements )
self : Refresh Option s( " AddEmptyMapping " .. newMapping )
self : Refresh Profile s( " AddEmptyMapping " .. newMapping )
self.dialog : SelectGroup ( self.name , " replacements " , newMapping )
self.dialog : SelectGroup ( self.name , " replacements " , newMapping )
end
end
@ -651,7 +675,7 @@ function Grichelde:MoveUp(info)
replacements [ swapName ] . order = currentOrder
replacements [ swapName ] . order = currentOrder
replacements [ currentName ] . order = currentOrder - 1
replacements [ currentName ] . order = currentOrder - 1
self : Refresh Option s( " MoveUp " .. currentName )
self : Refresh Profile s( " MoveUp " .. currentName )
self : DebugPrint ( " MoveUp : refresh focus on %s " , swapName )
self : DebugPrint ( " MoveUp : refresh focus on %s " , swapName )
self.dialog : SelectGroup ( self.name , " replacements " , swapName )
self.dialog : SelectGroup ( self.name , " replacements " , swapName )
@ -694,7 +718,7 @@ function Grichelde:MoveDown(info)
replacements [ swapName ] . order = currentOrder
replacements [ swapName ] . order = currentOrder
replacements [ currentName ] . order = currentOrder + 1
replacements [ currentName ] . order = currentOrder + 1
self : Refresh Option s( " MoveDown " .. currentName )
self : Refresh Profile s( " MoveDown " .. currentName )
self : DebugPrint ( " MoveDown : refresh focus on %s " , swapName )
self : DebugPrint ( " MoveDown : refresh focus on %s " , swapName )
self.dialog : SelectGroup ( self.name , " replacements " , swapName )
self.dialog : SelectGroup ( self.name , " replacements " , swapName )
@ -774,7 +798,7 @@ function Grichelde:DeleteMapping(info)
self : DebugPrint ( " delete option: %s " , currentName )
self : DebugPrint ( " delete option: %s " , currentName )
self.db . profile.replacements [ currentName ] = nil
self.db . profile.replacements [ currentName ] = nil
self : Refresh Option s( " DeleteMapping " .. currentName )
self : Refresh Profile s( " DeleteMapping " .. currentName )
local _ , replNumber = self : SplitOnFirstMatch ( currentName , " _ " )
local _ , replNumber = self : SplitOnFirstMatch ( currentName , " _ " )
local newMapping = " replacement_ " .. toNumber ( replNumber - 1 )
local newMapping = " replacement_ " .. toNumber ( replNumber - 1 )
@ -788,5 +812,5 @@ function Grichelde:DeleteAllMappings()
tWipe ( self.db . profile.replacements )
tWipe ( self.db . profile.replacements )
self : AddEmptyMapping ( )
self : AddEmptyMapping ( )
self : Refresh Option s( " DeleteAllMappings " )
self : Refresh Profile s( " DeleteAllMappings " )
end
end