Skip to content

Commit

Permalink
Fix preset index bug and slash command bug (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mctalian authored Jul 25, 2024
1 parent 6853148 commit 38c473b
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions Core.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
DLP = LibStub("AceAddon-3.0"):NewAddon("DeviceLayoutPreset", "AceConsole-3.0", "AceEvent-3.0")
local addonName = "DeviceLayoutPreset"
DLP = LibStub("AceAddon-3.0"):NewAddon(addonName, "AceConsole-3.0", "AceEvent-3.0")

local options = {
name = "DeviceLayoutPreset",
name = addonName,
handler = DLP,
type = "group",
args = {
Expand Down Expand Up @@ -49,7 +50,7 @@ function DLP:OnInitialize()
self.db.global.presetIndexOnLogin = self.db.profile.presetIndexOnLogin
self.db.global.migratedFromProfile = true
end
LibStub("AceConfig-3.0"):RegisterOptionsTable("DeviceLayoutPreset", options)
LibStub("AceConfig-3.0"):RegisterOptionsTable(addonName, options)
self.initialized = false
self:RegisterEvent("EDIT_MODE_LAYOUTS_UPDATED")
self:RegisterChatCommand("dlp", "SlashCommand")
Expand All @@ -60,30 +61,24 @@ end
function DLP:EDIT_MODE_LAYOUTS_UPDATED(eventName, layoutInfo, reconcileLayouts)
layouts = EditModeManagerFrame:GetLayouts()
self:InitializeOptions()
if self.db.global.presetIndexOnLogin == 0 or self.db.global.presetIndexOnLogin > table.getn(layouts) - 1 then
if self.db.global.presetIndexOnLogin == 0 or self.db.global.presetIndexOnLogin > table.getn(layouts) then
self:Print("Visit the addon options (/dlp) to select the Edit Mode preset for this device")
self.db.global.presetIndexOnLogin = 0
else
self:Print(
"Configured to select Edit Mode preset \"" .. layouts[self.db.global.presetIndexOnLogin].layoutName ..
"\" on this device")
self:Print("Configured to select Edit Mode preset \"" .. layouts[self.db.global.presetIndexOnLogin].layoutName .. "\" on this device")
end
if self.db.global.presetIndexOnLogin > 0 then
EditModeManagerFrame:SelectLayout(self.db.global.presetIndexOnLogin)
end
end

function DLP:EDIT_MODE_LAYOUT_REMOVED(eventName, ...)
self:Print(eventName)
end

function DLP:InitializeOptions()
options.args.preset.values = {}
for i, l in ipairs(layouts) do
options.args.preset.values[i] = l.layoutName
end
if self.optionsFrame == nil then
self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("DeviceLayoutPreset", "DeviceLayoutPreset")
self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions(addonName, addonName)
end
end

Expand All @@ -96,6 +91,5 @@ function DLP:GetPreset(info)
end

function DLP:SlashCommand(msg, editBox)
InterfaceOptionsFrame_OpenToCategory(self.optionsFrame)
InterfaceOptionsFrame_OpenToCategory(self.optionsFrame)
LibStub("AceConfigDialog-3.0"):Open(addonName)
end

0 comments on commit 38c473b

Please sign in to comment.