From 941de6d3db8651cf614199a3124d1c61aeb1e550 Mon Sep 17 00:00:00 2001 From: Hendrik Leppkes Date: Fri, 11 Jan 2008 15:20:55 +0000 Subject: [PATCH] profile handling --- ActionBars.lua | 2 +- Bartender4.lua | 6 ++- Options.lua | 107 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 112 insertions(+), 3 deletions(-) diff --git a/ActionBars.lua b/ActionBars.lua index 78e42b1..4fbff24 100644 --- a/ActionBars.lua +++ b/ActionBars.lua @@ -236,7 +236,7 @@ end function BT4ActionBars:EnableBar(id) id = tonumber(id) local bar = self.actionbars[id] - local config = self.db.profile.ActionBars[id] + local config = self.db.profile.actionbars[id] config.enabled = true if not bar then bar = self:Create(id, config) diff --git a/Bartender4.lua b/Bartender4.lua index e53d603..48b0817 100644 --- a/Bartender4.lua +++ b/Bartender4.lua @@ -1,6 +1,6 @@ --[[ $Id$ ]] local AceAddon = LibStub("AceAddon-3.0") -Bartender4 = AceAddon:NewAddon("Bartender4", "AceConsole-3.0", "AceEvent-3.0") +Bartender4 = AceAddon:NewAddon("Bartender4", "AceConsole-3.0", "AceEvent-3.0", "AceHook-3.0") local defaults = { profile = { @@ -19,6 +19,8 @@ function Bartender4:OnInitialize() self.Locked = true self:RegisterEvent("PLAYER_REGEN_DISABLED", "CombatLockdown") + MainMenuBarArtFrame:Hide() + MainMenuBar:Hide() end function Bartender4:RegisterDefaultsKey(key, subdefaults) @@ -29,7 +31,7 @@ end function Bartender4:UpdateModuleConfigs() self:Lock() - for k,v in AceAddon:IterateModulesOfAddon("Bartender4") do + for k,v in AceAddon:IterateModulesOfAddon(self) do if type(v.ApplyConfig) == "function" then v:ApplyConfig() end diff --git a/Options.lua b/Options.lua index e6d58ce..37c8525 100644 --- a/Options.lua +++ b/Options.lua @@ -14,6 +14,109 @@ do end end +local getProfilesOptionsTable +do + local defaultProfiles + --[[ Utility functions ]] + -- get exisiting profiles + some default entries + local tmpprofiles = {} + local function getProfileList(db, common, nocurrent) + -- clear old profile table + local profiles = {} + + -- copy existing profiles into the table + local curr = db:GetCurrentProfile() + for i,v in pairs(db:GetProfiles(tmpprofiles)) do if not (nocurrent and v == curr) then profiles[v] = v end end + + -- add our default profiles to choose from + for k,v in pairs(defaultProfiles) do + if (common or profiles[k]) and not (k == curr and nocurrent) then + profiles[k] = v + end + end + return profiles + end + + function getProfilesOptionsTable(db) + defaultProfiles = { + ["Default"] = "Default", + [db.keys.char] = "Char: " .. db.keys.char, + [db.keys.realm] = "Realm: " .. db.keys.realm, + [db.keys.class] = "Class: " .. UnitClass("player") + } + + local tbl = { + profiles = { + type = "group", + name = "Profiles", + desc = "Manage Profiles", + args = { + reset = { + order = 1, + type = "execute", + name = "Reset Profile", + desc = "Reset the current profile to the default", + func = function() db:ResetProfile() end, + }, + spacer1 = { + order = 2, + type = "header", + name = "Choose a Profile", + desc = "Set the active profile of this character.", + }, + new = { + name = "New", + type = "input", + order = 3, + get = function() return false end, + set = function(info, value) db:SetProfile(value) end, + }, + choose = { + name = "Current", + type = "select", + order = 4, + get = function() return db:GetCurrentProfile() end, + set = function(info, value) db:SetProfile(value) end, + values = function() return getProfileList(db, true) end, + }, + spacer2 = { + type = "header", + order = 5, + name = "Copy a Profile", + }, + copyfrom = { + order = 6, + type = "select", + name = "Copy From", + desc = "Copy the settings from another profile", + get = function() return false end, + set = function(info, value) db:CopyProfile(value) end, + values = function() return getProfileList(db, nil, true) end, + }, + spacer3 = { + type = "header", + order = 7, + name = "Delete a Profile", + }, + delete = { + order = 8, + type = "select", + name = "Delete a Profile", + desc = "Deletes a profile from the database.", + get = function() return false end, + set = function(info, value) db:DeleteProfile(value) end, + values = function() return getProfileList(db, nil, true) end, + confirm = true, + confirmText = "Are you sure you want to delete the selected profile?", + }, + }, + }, + } + + return tbl + end +end + function Bartender4:SetupOptions() self.options = { type = "group", @@ -40,6 +143,10 @@ function Bartender4:SetupOptions() }, }, } + + self.options.plugins.profiles = getProfilesOptionsTable(Bartender4.db) + + LibStub("AceConfig-3.0"):RegisterOptionsTable("Bartender4", self.options, "bttest") local optFunc = function() AceConfigDialog:Open("Bartender4")