annotate Libs/AceDBOptions-3.0/AceDBOptions-3.0.lua @ 63:3552946c0b9a tip

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