Skip to content

Commit

Permalink
finish implementing copyLayoutFrom
Browse files Browse the repository at this point in the history
  • Loading branch information
Krealle committed Aug 31, 2024
1 parent 81a6646 commit 0c248cf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
6 changes: 4 additions & 2 deletions Locales/enUS.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ Selecting |cffffb5c5None|r will Auto Switch to use the
currently active layout in |cFFFFD700Cell|r.]]

L.CopyLayoutFrom = "Copy Layout From"
L.CopyFromTooltip = "Copy settings from another layout"
L.CopyFromPopUp = ""
L.CopyFromTooltip = [[|cFFFF0000This will overwrite all settings in the current layout!|r
Copy settings from another layout]]
L.CopyFromPopUp = "Copy settings from |cFFFFD700%s|r to |cFFFFD700%s|r?"

-- Units
L.targettarget = "TargetTarget"
Expand Down
25 changes: 20 additions & 5 deletions Menu/GeneralTab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ function generalTab:IsShown()
return generalTab.window and generalTab.window:IsShown()
end

--- Replaces "default" with _G.DEFAULT
---@param layoutName string
---@return string
local function normalizeLayoutName(layoutName)
---@diagnostic disable-next-line: undefined-field
return layoutName == "default" and _G.DEFAULT or layoutName
end

-------------------------------------------------
-- MARK: Copy From
-------------------------------------------------
Expand All @@ -36,13 +44,19 @@ function copyLayoutFrom.SetLayoutItems()
for layoutName, _ in pairs(CellDB.layouts) do
if layoutName ~= DB.GetMasterLayout() then
tinsert(dropdownItems, {
---@diagnostic disable-next-line: undefined-field
["text"] = layoutName == "default" and _G.DEFAULT or layoutName,
["text"] = normalizeLayoutName(layoutName),
["value"] = layoutName,
["onClick"] = function()
local popup = CUF:CreateConfirmPopup(Menu.window, 300,
string.format(L.CopyFromPopUp, normalizeLayoutName(layoutName),
normalizeLayoutName(DB.GetMasterLayout())),
function()
DB.CopyFullLayout(layoutName, DB.GetMasterLayout())
CUF:Fire("UpdateUnitButtons")
CUF:Fire("UpdateWidget", DB.GetMasterLayout())
end, nil, true)
popup:SetPoint("TOP", 0, -70)
copyLayoutFrom.layoutDropdown:ClearSelected()
CUF:Fire("UpdateUnitButtons")
CUF:Fire("UpdateWidget", layoutName)
end,
})
end
Expand All @@ -66,7 +80,7 @@ function copyLayoutFrom:Create()
---@type CellDropdown
self.layoutDropdown = Cell:CreateDropdown(generalTab.window, sectionWidth - 10)
self.layoutDropdown:SetPoint("TOPLEFT", pane, "BOTTOMLEFT", 5, -10)
CUF:SetTooltips(self.layoutDropdown, "ANCHOR_TOPLEFT", 0, 3, L.MasterLayout, L.MasterLayoutTooltip)
CUF:SetTooltips(self.layoutDropdown, "ANCHOR_TOPLEFT", 0, 3, L.CopyLayoutFrom, L.CopyFromTooltip)
end

-------------------------------------------------
Expand Down Expand Up @@ -100,6 +114,7 @@ function layoutProfile:SetLayoutItems()
DB.SetMasterLayout(layoutName)
CUF:Fire("UpdateUnitButtons")
CUF:Fire("UpdateWidget", layoutName)
copyLayoutFrom.SetLayoutItems()
end,
})
end
Expand Down

0 comments on commit 0c248cf

Please sign in to comment.