Ask if want to import Auto Run Scripts within the profile imported

This commit is contained in:
Tercio Jose
2022-12-31 16:41:55 -03:00
parent f9093a5476
commit 7c83f58794
2 changed files with 122 additions and 12 deletions
+22 -6
View File
@@ -4027,19 +4027,35 @@ do
icontexcoords = {1, 0, 0, 1},
},
{--import profile
type = "execute",
func = function(self)
_detalhes:ShowImportWindow("", function(profileString)
--[=[
function(profileString)
if (type(profileString) ~= "string" or string.len(profileString) < 2) then
return
end
--prompt text panel returns what the user inserted in the text field in the first argument
DF:ShowTextPromptPanel(Loc["STRING_OPTIONS_IMPORT_PROFILE_NAME"] .. ":", function(newProfileName)
Details:ImportProfile (profileString, newProfileName)
Details:ImportProfile (profileString, newProfileName, importAutoRunCode)
end)
end, Loc["STRING_OPTIONS_IMPORT_PROFILE_PASTE"])
end
--]=]
{--import profile
type = "execute",
func = function(self)
local importConfirmationCallback = function(profileString)
if (type(profileString) ~= "string" or string.len(profileString) < 2) then
return
end
--prompt text panel returns what the user inserted in the text field in the first argument
local askForNewProfileName = function(newProfileName, importAutoRunCode)
Details:ImportProfile(profileString, newProfileName, importAutoRunCode, true)
end
Details.ShowImportProfileConfirmation(Loc["STRING_OPTIONS_IMPORT_PROFILE_NAME"] .. ":", askForNewProfileName)
end
Details:ShowImportWindow("", importConfirmationCallback, Loc["STRING_OPTIONS_IMPORT_PROFILE_PASTE"])
end,
name = Loc["STRING_OPTIONS_IMPORT_PROFILE"],
icontexture = [[Interface\BUTTONS\UI-GuildButton-OfficerNote-Up]],
+100 -6
View File
@@ -5,6 +5,7 @@
local Loc = LibStub("AceLocale-3.0"):GetLocale ( "Details" )
local _
local addonName, Details222 = ...
local detailsFramework = DetailsFramework
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--Profiles:
@@ -1788,11 +1789,16 @@ function Details:ExportCurrentProfile()
return compressedData
end
function Details:ImportProfile (profileString, newProfileName)
---bIsFromImportPrompt is true when the import call is from the import window
---@param profileString string
---@param newProfileName string
---@param bImportAutoRunCode boolean
---@param bIsFromImportPrompt boolean
---@return boolean
function Details:ImportProfile (profileString, newProfileName, bImportAutoRunCode, bIsFromImportPrompt)
if (not newProfileName or type(newProfileName) ~= "string" or string.len(newProfileName) < 2) then
Details:Msg("invalid profile name or profile name is too short.") --localize-me
return
return false
end
profileString = DetailsFramework:Trim (profileString)
@@ -1824,6 +1830,10 @@ function Details:ImportProfile (profileString, newProfileName)
--profile defaults
local defaultProfileData = Details.default_profile
if (not bImportAutoRunCode or not bIsFromImportPrompt) then
globalData.run_code = nil
end
--transfer player and global data tables from the profile to details object
for key, _ in pairs(defaultPlayerData) do
local importedValue = playerData[key]
@@ -1888,15 +1898,99 @@ function Details:ImportProfile (profileString, newProfileName)
DetailsFramework.table.copy(instance.hide_on_context, Details.instance_defaults.hide_on_context)
end
Details:Msg("profile successfully imported.")--localize-me
return true
else
Details:Msg("failed to decompress profile data.")--localize-me
return false
end
end
--create a import profile confirmation dialog with a text box to enter the profile name and a checkbox to select if should import auto run scripts
function Details.ShowImportProfileConfirmation(message, callback)
if (not Details.profileConfirmationDialog) then
local promptFrame = CreateFrame("frame", "DetailsImportProfileDialog", UIParent, "BackdropTemplate")
promptFrame:SetSize(400, 170)
promptFrame:SetFrameStrata("FULLSCREEN")
promptFrame:SetPoint("center", UIParent, "center", 0, 100)
promptFrame:EnableMouse(true)
promptFrame:SetMovable(true)
promptFrame:RegisterForDrag ("LeftButton")
promptFrame:SetScript("OnDragStart", function() promptFrame:StartMoving() end)
promptFrame:SetScript("OnDragStop", function() promptFrame:StopMovingOrSizing() end)
promptFrame:SetScript("OnMouseDown", function(self, button) if (button == "RightButton") then promptFrame.EntryBox:ClearFocus() promptFrame:Hide() end end)
tinsert(UISpecialFrames, "DetailsImportProfileDialog")
detailsFramework:CreateTitleBar(promptFrame, "Import Profile Confirmation")
detailsFramework:ApplyStandardBackdrop(promptFrame)
local prompt = promptFrame:CreateFontString(nil, "overlay", "GameFontNormal")
prompt:SetPoint("top", promptFrame, "top", 0, -25)
prompt:SetJustifyH("center")
prompt:SetSize(360, 36)
promptFrame.prompt = prompt
local button_text_template = detailsFramework:GetTemplate("font", "OPTIONS_FONT_TEMPLATE")
local options_dropdown_template = detailsFramework:GetTemplate("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")
local textbox = detailsFramework:CreateTextEntry(promptFrame, function()end, 380, 20, "textbox", nil, nil, options_dropdown_template)
textbox:SetPoint("topleft", promptFrame, "topleft", 10, -60)
promptFrame.EntryBox = textbox
--create a detailsframework checkbox to select if want to import the auto run scripts
local checkbox = detailsFramework:CreateSwitch(promptFrame, function()end, false, _, _, _, _, _, _, _, _, _, _, DetailsFramework:GetTemplate("switch", "OPTIONS_CHECKBOX_BRIGHT_TEMPLATE"))
checkbox:SetPoint("topleft", promptFrame, "topleft", 10, -90)
checkbox:SetAsCheckBox()
promptFrame.checkbox = checkbox
--create the checkbox label with the text: "Import Auto Run Scripts"
local checkboxLabel = promptFrame:CreateFontString(nil, "overlay", "GameFontNormal")
checkboxLabel:SetPoint("left", checkbox.widget, "right", 2, 0)
checkboxLabel:SetText("Import Auto Run Scripts")
checkboxLabel:SetJustifyH("left")
promptFrame.checkboxLabel = checkboxLabel
local buttonTrue = detailsFramework:CreateButton(promptFrame, nil, 60, 20, "Okey", nil, nil, nil, nil, nil, nil, options_dropdown_template)
buttonTrue:SetPoint("bottomright", promptFrame, "bottomright", -10, 5)
promptFrame.button_true = buttonTrue
local buttonFalse = detailsFramework:CreateButton(promptFrame, function() promptFrame.textbox:ClearFocus() promptFrame:Hide() end, 60, 20, "Cancel", nil, nil, nil, nil, nil, nil, options_dropdown_template)
buttonFalse:SetPoint("bottomleft", promptFrame, "bottomleft", 10, 5)
promptFrame.button_false = buttonFalse
local executeCallback = function()
local bCanImportAutoRunCode = promptFrame.checkbox:GetValue()
local myFunc = buttonTrue.true_function
if (myFunc) then
local okey, errormessage = pcall(myFunc, textbox:GetText(), bCanImportAutoRunCode)
textbox:ClearFocus()
if (not okey) then
print("error:", errormessage)
end
promptFrame:Hide()
end
end
buttonTrue:SetClickFunction(function()
executeCallback()
end)
textbox:SetHook("OnEnterPressed", function()
executeCallback()
end)
promptFrame:Hide()
Details.profileConfirmationDialog = promptFrame
end
Details.profileConfirmationDialog:Show()
Details.profileConfirmationDialog.EntryBox:SetText("")
Details.profileConfirmationDialog.EntryBox:SetFocus(false)
Details.profileConfirmationDialog.prompt:SetText(message)
Details.profileConfirmationDialog.button_true.true_function = callback
Details.profileConfirmationDialog.textbox:SetFocus(true)
end