annotate Libs/AceDBOptions-3.0/AceDBOptions-3.0.lua @ 25:ac501d71c890 tip

Added tag v8.2.0.024 for changeset 389dcaeebc47
author Tercioo
date Fri, 28 Jun 2019 20:07:27 -0300
parents 371e14cd2feb
children
rev   line source
tercio@0 1 --- AceDBOptions-3.0 provides a universal AceConfig options screen for managing AceDB-3.0 profiles.
tercio@0 2 -- @class file
tercio@0 3 -- @name AceDBOptions-3.0
Tercio@11 4 -- @release $Id: AceDBOptions-3.0.lua 1140 2016-07-03 07:53:29Z nevcairiel $
Tercio@11 5 local ACEDBO_MAJOR, ACEDBO_MINOR = "AceDBOptions-3.0", 15
tercio@0 6 local AceDBOptions, oldminor = LibStub:NewLibrary(ACEDBO_MAJOR, ACEDBO_MINOR)
tercio@0 7
tercio@0 8 if not AceDBOptions then return end -- No upgrade needed
tercio@0 9
tercio@0 10 -- Lua APIs
tercio@0 11 local pairs, next = pairs, next
tercio@0 12
tercio@0 13 -- WoW APIs
tercio@0 14 local UnitClass = UnitClass
tercio@0 15
tercio@0 16 -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
tercio@0 17 -- List them here for Mikk's FindGlobals script
tercio@0 18 -- GLOBALS: NORMAL_FONT_COLOR_CODE, FONT_COLOR_CODE_CLOSE
tercio@0 19
tercio@0 20 AceDBOptions.optionTables = AceDBOptions.optionTables or {}
tercio@0 21 AceDBOptions.handlers = AceDBOptions.handlers or {}
tercio@0 22
tercio@0 23 --[[
tercio@0 24 Localization of AceDBOptions-3.0
tercio@0 25 ]]
tercio@0 26
tercio@0 27 local L = {
tercio@0 28 choose = "Existing Profiles",
tercio@0 29 choose_desc = "You can either create a new profile by entering a name in the editbox, or choose one of the already existing profiles.",
tercio@0 30 choose_sub = "Select one of your currently available profiles.",
tercio@0 31 copy = "Copy From",
tercio@0 32 copy_desc = "Copy the settings from one existing profile into the currently active profile.",
tercio@0 33 current = "Current Profile:",
tercio@0 34 default = "Default",
tercio@0 35 delete = "Delete a Profile",
tercio@0 36 delete_confirm = "Are you sure you want to delete the selected profile?",
tercio@0 37 delete_desc = "Delete existing and unused profiles from the database to save space, and cleanup the SavedVariables file.",
tercio@0 38 delete_sub = "Deletes a profile from the database.",
tercio@0 39 intro = "You can change the active database profile, so you can have different settings for every character.",
tercio@0 40 new = "New",
tercio@0 41 new_sub = "Create a new empty profile.",
tercio@0 42 profiles = "Profiles",
tercio@0 43 profiles_sub = "Manage Profiles",
tercio@0 44 reset = "Reset Profile",
tercio@0 45 reset_desc = "Reset the current profile back to its default values, in case your configuration is broken, or you simply want to start over.",
tercio@0 46 reset_sub = "Reset the current profile to the default",
tercio@0 47 }
tercio@0 48
tercio@0 49 local LOCALE = GetLocale()
tercio@0 50 if LOCALE == "deDE" then
tercio@0 51 L["choose"] = "Vorhandene Profile"
tercio@0 52 L["choose_desc"] = "Du kannst ein neues Profil erstellen, indem du einen neuen Namen in der Eingabebox 'Neu' eingibst, oder wähle eines der vorhandenen Profile aus."
tercio@0 53 L["choose_sub"] = "Wählt ein bereits vorhandenes Profil aus."
tercio@0 54 L["copy"] = "Kopieren von..."
tercio@0 55 L["copy_desc"] = "Kopiere die Einstellungen von einem vorhandenen Profil in das aktive Profil."
Tercio@11 56 L["current"] = "Aktuelles Profil:"
tercio@0 57 L["default"] = "Standard"
tercio@0 58 L["delete"] = "Profil löschen"
tercio@0 59 L["delete_confirm"] = "Willst du das ausgewählte Profil wirklich löschen?"
Tercio@11 60 L["delete_desc"] = "Lösche vorhandene oder unbenutzte Profile aus der Datenbank, um Platz zu sparen und die SavedVariables-Datei 'sauber' zu halten."
tercio@0 61 L["delete_sub"] = "Löscht ein Profil aus der Datenbank."
Tercio@11 62 L["intro"] = "Hier kannst du das aktive Datenbankprofil ändern, damit du verschiedene Einstellungen für jeden Charakter erstellen kannst, wodurch eine sehr flexible Konfiguration möglich wird."
tercio@0 63 L["new"] = "Neu"
tercio@0 64 L["new_sub"] = "Ein neues Profil erstellen."
tercio@0 65 L["profiles"] = "Profile"
tercio@0 66 L["profiles_sub"] = "Profile verwalten"
tercio@0 67 L["reset"] = "Profil zurücksetzen"
Tercio@11 68 L["reset_desc"] = "Setzt das momentane Profil auf Standardwerte zurück, für den Fall, dass mit der Konfiguration etwas schief lief oder weil du einfach neu starten willst."
tercio@0 69 L["reset_sub"] = "Das aktuelle Profil auf Standard zurücksetzen."
tercio@0 70 elseif LOCALE == "frFR" then
tercio@0 71 L["choose"] = "Profils existants"
tercio@0 72 L["choose_desc"] = "Vous pouvez créer un nouveau profil en entrant un nouveau nom dans la boîte de saisie, ou en choississant un des profils déjà existants."
tercio@0 73 L["choose_sub"] = "Permet de choisir un des profils déjà disponibles."
tercio@0 74 L["copy"] = "Copier à partir de"
tercio@0 75 L["copy_desc"] = "Copie les paramètres d'un profil déjà existant dans le profil actuellement actif."
Tercio@11 76 L["current"] = "Profil actuel :"
tercio@0 77 L["default"] = "Défaut"
tercio@0 78 L["delete"] = "Supprimer un profil"
tercio@0 79 L["delete_confirm"] = "Etes-vous sûr de vouloir supprimer le profil sélectionné ?"
tercio@0 80 L["delete_desc"] = "Supprime les profils existants inutilisés de la base de données afin de gagner de la place et de nettoyer le fichier SavedVariables."
tercio@0 81 L["delete_sub"] = "Supprime un profil de la base de données."
tercio@0 82 L["intro"] = "Vous pouvez changer le profil actuel afin d'avoir des paramètres différents pour chaque personnage, permettant ainsi d'avoir une configuration très flexible."
tercio@0 83 L["new"] = "Nouveau"
tercio@0 84 L["new_sub"] = "Créée un nouveau profil vierge."
tercio@0 85 L["profiles"] = "Profils"
tercio@0 86 L["profiles_sub"] = "Gestion des profils"
tercio@0 87 L["reset"] = "Réinitialiser le profil"
tercio@0 88 L["reset_desc"] = "Réinitialise le profil actuel au cas où votre configuration est corrompue ou si vous voulez tout simplement faire table rase."
tercio@0 89 L["reset_sub"] = "Réinitialise le profil actuel avec les paramètres par défaut."
tercio@0 90 elseif LOCALE == "koKR" then
Tercio@11 91 L["choose"] = "저장 중인 프로필"
Tercio@11 92 L["choose_desc"] = "입력창에 새로운 이름을 입력하거나 저장 중인 프로필 중 하나를 선택하여 새로운 프로필을 만들 수 있습니다."
Tercio@11 93 L["choose_sub"] = "현재 이용할 수 있는 프로필 중 하나를 선택합니다."
Tercio@11 94 L["copy"] = "복사해오기"
Tercio@11 95 L["copy_desc"] = "현재 사용 중인 프로필에 선택한 프로필의 설정을 복사합니다."
Tercio@11 96 L["current"] = "현재 프로필:"
tercio@0 97 L["default"] = "기본값"
tercio@0 98 L["delete"] = "프로필 삭제"
Tercio@11 99 L["delete_confirm"] = "정말로 선택한 프로필을 삭제할까요?"
Tercio@11 100 L["delete_desc"] = "저장 공간 절약과 SavedVariables 파일의 정리를 위해 데이터베이스에서 사용하지 않는 프로필을 삭제하세요."
tercio@0 101 L["delete_sub"] = "데이터베이스의 프로필을 삭제합니다."
Tercio@11 102 L["intro"] = "활성 데이터베이스 프로필을 변경할 수 있고, 각 캐릭터 별로 다른 설정을 할 수 있습니다."
tercio@0 103 L["new"] = "새로운 프로필"
tercio@0 104 L["new_sub"] = "새로운 프로필을 만듭니다."
tercio@0 105 L["profiles"] = "프로필"
Tercio@11 106 L["profiles_sub"] = "프로필 관리"
tercio@0 107 L["reset"] = "프로필 초기화"
Tercio@11 108 L["reset_desc"] = "설정이 깨졌거나 처음부터 다시 설정을 원하는 경우, 현재 프로필을 기본값으로 초기화하세요."
Tercio@11 109 L["reset_sub"] = "현재 프로필을 기본값으로 초기화합니다"
tercio@0 110 elseif LOCALE == "esES" or LOCALE == "esMX" then
tercio@0 111 L["choose"] = "Perfiles existentes"
tercio@0 112 L["choose_desc"] = "Puedes crear un nuevo perfil introduciendo un nombre en el recuadro o puedes seleccionar un perfil de los ya existentes."
tercio@0 113 L["choose_sub"] = "Selecciona uno de los perfiles disponibles."
tercio@0 114 L["copy"] = "Copiar de"
tercio@0 115 L["copy_desc"] = "Copia los ajustes de un perfil existente al perfil actual."
Tercio@11 116 L["current"] = "Perfil actual:"
tercio@0 117 L["default"] = "Por defecto"
tercio@0 118 L["delete"] = "Borrar un Perfil"
tercio@0 119 L["delete_confirm"] = "¿Estas seguro que quieres borrar el perfil seleccionado?"
tercio@0 120 L["delete_desc"] = "Borra los perfiles existentes y sin uso de la base de datos para ganar espacio y limpiar el archivo SavedVariables."
tercio@0 121 L["delete_sub"] = "Borra un perfil de la base de datos."
tercio@0 122 L["intro"] = "Puedes cambiar el perfil activo de tal manera que cada personaje tenga diferentes configuraciones."
tercio@0 123 L["new"] = "Nuevo"
tercio@0 124 L["new_sub"] = "Crear un nuevo perfil vacio."
tercio@0 125 L["profiles"] = "Perfiles"
tercio@0 126 L["profiles_sub"] = "Manejar Perfiles"
tercio@0 127 L["reset"] = "Reiniciar Perfil"
tercio@0 128 L["reset_desc"] = "Reinicia el perfil actual a los valores por defectos, en caso de que se haya estropeado la configuración o quieras volver a empezar de nuevo."
tercio@0 129 L["reset_sub"] = "Reinicar el perfil actual al de por defecto"
tercio@0 130 elseif LOCALE == "zhTW" then
tercio@0 131 L["choose"] = "現有的設定檔"
Tercio@11 132 L["choose_desc"] = "您可以在文字方塊內輸入名字以建立新的設定檔,或是選擇一個現有的設定檔使用。"
Tercio@11 133 L["choose_sub"] = "從當前可用的設定檔裡面選擇一個。"
tercio@0 134 L["copy"] = "複製自"
Tercio@11 135 L["copy_desc"] = "從一個現有的設定檔,將設定複製到現在使用中的設定檔。"
Tercio@11 136 L["current"] = "目前設定檔:"
tercio@0 137 L["default"] = "預設"
tercio@0 138 L["delete"] = "刪除一個設定檔"
Tercio@11 139 L["delete_confirm"] = "確定要刪除所選擇的設定檔嗎?"
Tercio@11 140 L["delete_desc"] = "從資料庫裡刪除不再使用的設定檔,以節省空間,並且清理 SavedVariables 檔案。"
Tercio@11 141 L["delete_sub"] = "從資料庫裡刪除一個設定檔。"
Tercio@11 142 L["intro"] = "您可以從資料庫中選擇一個設定檔來使用,如此就可以讓每個角色使用不同的設定。"
tercio@0 143 L["new"] = "新建"
tercio@0 144 L["new_sub"] = "新建一個空的設定檔。"
tercio@0 145 L["profiles"] = "設定檔"
tercio@0 146 L["profiles_sub"] = "管理設定檔"
tercio@0 147 L["reset"] = "重置設定檔"
Tercio@11 148 L["reset_desc"] = "將現用的設定檔重置為預設值;用於設定檔損壞,或者單純想要重來的情況。"
Tercio@11 149 L["reset_sub"] = "將目前的設定檔重置為預設值"
tercio@0 150 elseif LOCALE == "zhCN" then
tercio@0 151 L["choose"] = "现有的配置文件"
tercio@0 152 L["choose_desc"] = "你可以通过在文本框内输入一个名字创立一个新的配置文件,也可以选择一个已经存在的配置文件。"
tercio@0 153 L["choose_sub"] = "从当前可用的配置文件里面选择一个。"
tercio@0 154 L["copy"] = "复制自"
tercio@0 155 L["copy_desc"] = "从当前某个已保存的配置文件复制到当前正使用的配置文件。"
Tercio@11 156 L["current"] = "当前配置文件:"
tercio@0 157 L["default"] = "默认"
tercio@0 158 L["delete"] = "删除一个配置文件"
tercio@0 159 L["delete_confirm"] = "你确定要删除所选择的配置文件么?"
tercio@0 160 L["delete_desc"] = "从数据库里删除不再使用的配置文件,以节省空间,并且清理SavedVariables文件。"
tercio@0 161 L["delete_sub"] = "从数据库里删除一个配置文件。"
tercio@0 162 L["intro"] = "你可以选择一个活动的数据配置文件,这样你的每个角色就可以拥有不同的设置值,可以给你的插件配置带来极大的灵活性。"
tercio@0 163 L["new"] = "新建"
tercio@0 164 L["new_sub"] = "新建一个空的配置文件。"
tercio@0 165 L["profiles"] = "配置文件"
tercio@0 166 L["profiles_sub"] = "管理配置文件"
tercio@0 167 L["reset"] = "重置配置文件"
tercio@0 168 L["reset_desc"] = "将当前的配置文件恢复到它的默认值,用于你的配置文件损坏,或者你只是想重来的情况。"
tercio@0 169 L["reset_sub"] = "将当前的配置文件恢复为默认值"
tercio@0 170 elseif LOCALE == "ruRU" then
tercio@0 171 L["choose"] = "Существующие профили"
tercio@0 172 L["choose_desc"] = "Вы можете создать новый профиль, введя название в поле ввода, или выбрать один из уже существующих профилей."
tercio@0 173 L["choose_sub"] = "Выбор одиного из уже доступных профилей"
tercio@0 174 L["copy"] = "Скопировать из"
tercio@0 175 L["copy_desc"] = "Скопировать настройки из выбранного профиля в активный."
Tercio@11 176 L["current"] = "Текущий профиль:"
tercio@0 177 L["default"] = "По умолчанию"
tercio@0 178 L["delete"] = "Удалить профиль"
tercio@0 179 L["delete_confirm"] = "Вы уверены, что вы хотите удалить выбранный профиль?"
tercio@0 180 L["delete_desc"] = "Удалить существующий и неиспользуемый профиль из БД для сохранения места, и очистить SavedVariables файл."
tercio@0 181 L["delete_sub"] = "Удаление профиля из БД"
tercio@0 182 L["intro"] = "Изменяя активный профиль, вы можете задать различные настройки модификаций для каждого персонажа."
tercio@0 183 L["new"] = "Новый"
tercio@0 184 L["new_sub"] = "Создать новый чистый профиль"
tercio@0 185 L["profiles"] = "Профили"
tercio@0 186 L["profiles_sub"] = "Управление профилями"
tercio@0 187 L["reset"] = "Сброс профиля"
Tercio@11 188 L["reset_desc"] = "Сбросить текущий профиль к стандартным настройкам, если ваша конфигурация испорчена или вы хотите настроить всё заново."
tercio@0 189 L["reset_sub"] = "Сброс текущего профиля на стандартный"
tercio@0 190 elseif LOCALE == "itIT" then
Tercio@11 191 L["choose"] = "Profili Esistenti"
Tercio@11 192 L["choose_desc"] = "Puoi creare un nuovo profilo digitando il nome della casella di testo, oppure scegliendone uno tra i profili già esistenti."
Tercio@11 193 L["choose_sub"] = "Seleziona uno dei profili attualmente disponibili."
tercio@0 194 L["copy"] = "Copia Da"
tercio@0 195 L["copy_desc"] = "Copia le impostazioni da un profilo esistente, nel profilo attivo in questo momento."
tercio@0 196 L["current"] = "Profilo Attivo:"
tercio@0 197 L["default"] = "Standard"
Tercio@11 198 L["delete"] = "Cancella un Profilo"
tercio@0 199 L["delete_confirm"] = "Sei sicuro di voler cancellare il profilo selezionato?"
tercio@0 200 L["delete_desc"] = "Cancella i profili non utilizzati dal database per risparmiare spazio e mantenere puliti i file di configurazione SavedVariables."
tercio@0 201 L["delete_sub"] = "Cancella un profilo dal Database."
tercio@0 202 L["intro"] = "Puoi cambiare il profilo attivo, in modo da usare impostazioni diverse per ogni personaggio."
tercio@0 203 L["new"] = "Nuovo"
tercio@0 204 L["new_sub"] = "Crea un nuovo profilo vuoto."
tercio@0 205 L["profiles"] = "Profili"
tercio@0 206 L["profiles_sub"] = "Gestisci Profili"
tercio@0 207 L["reset"] = "Reimposta Profilo"
Tercio@11 208 L["reset_desc"] = "Riporta il tuo profilo attivo alle sue impostazioni predefinite, nel caso in cui la tua configurazione si sia corrotta, o semplicemente tu voglia re-inizializzarla."
Tercio@11 209 L["reset_sub"] = "Reimposta il profilo ai suoi valori predefiniti."
Tercio@11 210 elseif LOCALE == "ptBR" then
Tercio@11 211 L["choose"] = "Perfis Existentes"
Tercio@11 212 L["choose_desc"] = "Você pode tanto criar um perfil novo tanto digitando um nome na caixa de texto, quanto escolher um dos perfis já existentes."
Tercio@11 213 L["choose_sub"] = "Selecione um de seus perfis atualmente disponíveis."
Tercio@11 214 L["copy"] = "Copiar De"
Tercio@11 215 L["copy_desc"] = "Copia as definições de um perfil existente no perfil atualmente ativo."
Tercio@11 216 L["current"] = "Perfil Autal:"
Tercio@11 217 L["default"] = "Padrão"
Tercio@11 218 L["delete"] = "Remover um Perfil"
Tercio@11 219 L["delete_confirm"] = "Tem certeza que deseja remover o perfil selecionado?"
Tercio@11 220 L["delete_desc"] = "Remove perfis existentes e inutilizados do banco de dados para economizar espaço, e limpar o arquivo SavedVariables."
Tercio@11 221 L["delete_sub"] = "Remove um perfil do banco de dados."
Tercio@11 222 L["intro"] = "Você pode alterar o perfil do banco de dados ativo, para que possa ter definições diferentes para cada personagem."
Tercio@11 223 L["new"] = "Novo"
Tercio@11 224 L["new_sub"] = "Cria um novo perfil vazio."
Tercio@11 225 L["profiles"] = "Perfis"
Tercio@11 226 L["profiles_sub"] = "Gerenciar Perfis"
Tercio@11 227 L["reset"] = "Resetar Perfil"
Tercio@11 228 L["reset_desc"] = "Reseta o perfil atual para os valores padrões, no caso de sua configuração estar quebrada, ou simplesmente se deseja começar novamente."
Tercio@11 229 L["reset_sub"] = "Resetar o perfil atual ao padrão"
tercio@0 230 end
tercio@0 231
tercio@0 232 local defaultProfiles
tercio@0 233 local tmpprofiles = {}
tercio@0 234
tercio@0 235 -- Get a list of available profiles for the specified database.
tercio@0 236 -- You can specify which profiles to include/exclude in the list using the two boolean parameters listed below.
tercio@0 237 -- @param db The db object to retrieve the profiles from
tercio@0 238 -- @param common If true, getProfileList will add the default profiles to the return list, even if they have not been created yet
tercio@0 239 -- @param nocurrent If true, then getProfileList will not display the current profile in the list
tercio@0 240 -- @return Hashtable of all profiles with the internal name as keys and the display name as value.
tercio@0 241 local function getProfileList(db, common, nocurrent)
tercio@0 242 local profiles = {}
tercio@0 243
tercio@0 244 -- copy existing profiles into the table
tercio@0 245 local currentProfile = db:GetCurrentProfile()
tercio@0 246 for i,v in pairs(db:GetProfiles(tmpprofiles)) do
tercio@0 247 if not (nocurrent and v == currentProfile) then
tercio@0 248 profiles[v] = v
tercio@0 249 end
tercio@0 250 end
tercio@0 251
tercio@0 252 -- add our default profiles to choose from ( or rename existing profiles)
tercio@0 253 for k,v in pairs(defaultProfiles) do
tercio@0 254 if (common or profiles[k]) and not (nocurrent and k == currentProfile) then
tercio@0 255 profiles[k] = v
tercio@0 256 end
tercio@0 257 end
tercio@0 258
tercio@0 259 return profiles
tercio@0 260 end
tercio@0 261
tercio@0 262 --[[
tercio@0 263 OptionsHandlerPrototype
tercio@0 264 prototype class for handling the options in a sane way
tercio@0 265 ]]
tercio@0 266 local OptionsHandlerPrototype = {}
tercio@0 267
tercio@0 268 --[[ Reset the profile ]]
tercio@0 269 function OptionsHandlerPrototype:Reset()
tercio@0 270 self.db:ResetProfile()
tercio@0 271 end
tercio@0 272
tercio@0 273 --[[ Set the profile to value ]]
tercio@0 274 function OptionsHandlerPrototype:SetProfile(info, value)
tercio@0 275 self.db:SetProfile(value)
tercio@0 276 end
tercio@0 277
tercio@0 278 --[[ returns the currently active profile ]]
tercio@0 279 function OptionsHandlerPrototype:GetCurrentProfile()
tercio@0 280 return self.db:GetCurrentProfile()
tercio@0 281 end
tercio@0 282
tercio@0 283 --[[
tercio@0 284 List all active profiles
tercio@0 285 you can control the output with the .arg variable
tercio@0 286 currently four modes are supported
tercio@0 287
tercio@0 288 (empty) - return all available profiles
tercio@0 289 "nocurrent" - returns all available profiles except the currently active profile
tercio@0 290 "common" - returns all avaialble profiles + some commonly used profiles ("char - realm", "realm", "class", "Default")
tercio@0 291 "both" - common except the active profile
tercio@0 292 ]]
tercio@0 293 function OptionsHandlerPrototype:ListProfiles(info)
tercio@0 294 local arg = info.arg
tercio@0 295 local profiles
tercio@0 296 if arg == "common" and not self.noDefaultProfiles then
tercio@0 297 profiles = getProfileList(self.db, true, nil)
tercio@0 298 elseif arg == "nocurrent" then
tercio@0 299 profiles = getProfileList(self.db, nil, true)
tercio@0 300 elseif arg == "both" then -- currently not used
tercio@0 301 profiles = getProfileList(self.db, (not self.noDefaultProfiles) and true, true)
tercio@0 302 else
tercio@0 303 profiles = getProfileList(self.db)
tercio@0 304 end
tercio@0 305
tercio@0 306 return profiles
tercio@0 307 end
tercio@0 308
tercio@0 309 function OptionsHandlerPrototype:HasNoProfiles(info)
tercio@0 310 local profiles = self:ListProfiles(info)
tercio@0 311 return ((not next(profiles)) and true or false)
tercio@0 312 end
tercio@0 313
tercio@0 314 --[[ Copy a profile ]]
tercio@0 315 function OptionsHandlerPrototype:CopyProfile(info, value)
tercio@0 316 self.db:CopyProfile(value)
tercio@0 317 end
tercio@0 318
tercio@0 319 --[[ Delete a profile from the db ]]
tercio@0 320 function OptionsHandlerPrototype:DeleteProfile(info, value)
tercio@0 321 self.db:DeleteProfile(value)
tercio@0 322 end
tercio@0 323
tercio@0 324 --[[ fill defaultProfiles with some generic values ]]
tercio@0 325 local function generateDefaultProfiles(db)
tercio@0 326 defaultProfiles = {
tercio@0 327 ["Default"] = L["default"],
tercio@0 328 [db.keys.char] = db.keys.char,
tercio@0 329 [db.keys.realm] = db.keys.realm,
tercio@0 330 [db.keys.class] = UnitClass("player")
tercio@0 331 }
tercio@0 332 end
tercio@0 333
tercio@0 334 --[[ create and return a handler object for the db, or upgrade it if it already existed ]]
tercio@0 335 local function getOptionsHandler(db, noDefaultProfiles)
tercio@0 336 if not defaultProfiles then
tercio@0 337 generateDefaultProfiles(db)
tercio@0 338 end
tercio@0 339
tercio@0 340 local handler = AceDBOptions.handlers[db] or { db = db, noDefaultProfiles = noDefaultProfiles }
tercio@0 341
tercio@0 342 for k,v in pairs(OptionsHandlerPrototype) do
tercio@0 343 handler[k] = v
tercio@0 344 end
tercio@0 345
tercio@0 346 AceDBOptions.handlers[db] = handler
tercio@0 347 return handler
tercio@0 348 end
tercio@0 349
tercio@0 350 --[[
tercio@0 351 the real options table
tercio@0 352 ]]
tercio@0 353 local optionsTable = {
tercio@0 354 desc = {
tercio@0 355 order = 1,
tercio@0 356 type = "description",
tercio@0 357 name = L["intro"] .. "\n",
tercio@0 358 },
tercio@0 359 descreset = {
tercio@0 360 order = 9,
tercio@0 361 type = "description",
tercio@0 362 name = L["reset_desc"],
tercio@0 363 },
tercio@0 364 reset = {
tercio@0 365 order = 10,
tercio@0 366 type = "execute",
tercio@0 367 name = L["reset"],
tercio@0 368 desc = L["reset_sub"],
tercio@0 369 func = "Reset",
tercio@0 370 },
tercio@0 371 current = {
tercio@0 372 order = 11,
tercio@0 373 type = "description",
tercio@0 374 name = function(info) return L["current"] .. " " .. NORMAL_FONT_COLOR_CODE .. info.handler:GetCurrentProfile() .. FONT_COLOR_CODE_CLOSE end,
tercio@0 375 width = "default",
tercio@0 376 },
tercio@0 377 choosedesc = {
tercio@0 378 order = 20,
tercio@0 379 type = "description",
tercio@0 380 name = "\n" .. L["choose_desc"],
tercio@0 381 },
tercio@0 382 new = {
tercio@0 383 name = L["new"],
tercio@0 384 desc = L["new_sub"],
tercio@0 385 type = "input",
tercio@0 386 order = 30,
tercio@0 387 get = false,
tercio@0 388 set = "SetProfile",
tercio@0 389 },
tercio@0 390 choose = {
tercio@0 391 name = L["choose"],
tercio@0 392 desc = L["choose_sub"],
tercio@0 393 type = "select",
tercio@0 394 order = 40,
tercio@0 395 get = "GetCurrentProfile",
tercio@0 396 set = "SetProfile",
tercio@0 397 values = "ListProfiles",
tercio@0 398 arg = "common",
tercio@0 399 },
tercio@0 400 copydesc = {
tercio@0 401 order = 50,
tercio@0 402 type = "description",
tercio@0 403 name = "\n" .. L["copy_desc"],
tercio@0 404 },
tercio@0 405 copyfrom = {
tercio@0 406 order = 60,
tercio@0 407 type = "select",
tercio@0 408 name = L["copy"],
tercio@0 409 desc = L["copy_desc"],
tercio@0 410 get = false,
tercio@0 411 set = "CopyProfile",
tercio@0 412 values = "ListProfiles",
tercio@0 413 disabled = "HasNoProfiles",
tercio@0 414 arg = "nocurrent",
tercio@0 415 },
tercio@0 416 deldesc = {
tercio@0 417 order = 70,
tercio@0 418 type = "description",
tercio@0 419 name = "\n" .. L["delete_desc"],
tercio@0 420 },
tercio@0 421 delete = {
tercio@0 422 order = 80,
tercio@0 423 type = "select",
tercio@0 424 name = L["delete"],
tercio@0 425 desc = L["delete_sub"],
tercio@0 426 get = false,
tercio@0 427 set = "DeleteProfile",
tercio@0 428 values = "ListProfiles",
tercio@0 429 disabled = "HasNoProfiles",
tercio@0 430 arg = "nocurrent",
tercio@0 431 confirm = true,
tercio@0 432 confirmText = L["delete_confirm"],
tercio@0 433 },
tercio@0 434 }
tercio@0 435
tercio@0 436 --- Get/Create a option table that you can use in your addon to control the profiles of AceDB-3.0.
tercio@0 437 -- @param db The database object to create the options table for.
tercio@0 438 -- @return The options table to be used in AceConfig-3.0
tercio@0 439 -- @usage
tercio@0 440 -- -- Assuming `options` is your top-level options table and `self.db` is your database:
tercio@0 441 -- options.args.profiles = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
tercio@0 442 function AceDBOptions:GetOptionsTable(db, noDefaultProfiles)
tercio@0 443 local tbl = AceDBOptions.optionTables[db] or {
tercio@0 444 type = "group",
tercio@0 445 name = L["profiles"],
tercio@0 446 desc = L["profiles_sub"],
tercio@0 447 }
tercio@0 448
tercio@0 449 tbl.handler = getOptionsHandler(db, noDefaultProfiles)
tercio@0 450 tbl.args = optionsTable
tercio@0 451
tercio@0 452 AceDBOptions.optionTables[db] = tbl
tercio@0 453 return tbl
tercio@0 454 end
tercio@0 455
tercio@0 456 -- upgrade existing tables
tercio@0 457 for db,tbl in pairs(AceDBOptions.optionTables) do
tercio@0 458 tbl.handler = getOptionsHandler(db)
tercio@0 459 tbl.args = optionsTable
tercio@0 460 end