view Config.lua @ 83:80ad43c94033

- 7.0.3 function changes
author Nenue
date Tue, 19 Jul 2016 13:47:47 -0400
parents 516ceb31703d
children
line wrap: on
line source
--- Devian - Config.lua
-- @file-author@
-- @project-revision@ @project-hash@
-- @file-revision@ @file-hash@
-- Created: 12/30/2015 1:35 AM
local _, D = ...
DevCon = D:NewModule("Config")
local Cf, tinsert, ipairs, tostring = DevCon, table.insert, ipairs, tostring
local PLAYER_REALM = UnitName("player") .. '-' .. GetRealmName()
local db
local print = D.print


local SetOpt = function(info, value)
  db[info[#info]] = value
end
local GetOpt = function(info)
  return db[info[#info]]
end
local GetProfileList = function(info)
  local select = {}
  for i, profile in ipairs(db.profiles) do
    if i == db.workspace then
      profile[1] = '|cFFFFFF00'..profile[1]..'|r'
    elseif i == db.last_workspace then
      profile[1] =  '|cFF00FF00'..profile[1]..'|r'
    end
    tinsert(select,tostring(i)..':'..profile[1])
  end
  return select
end
local GetAddOnList = function(id)
  local t = Cf.opts.args.addon.args
  for k, v in pairs(t) do
    k:match("addon_")
    t[k] = nil
  end


end
local SetSelectedToProfile = function(info, value)
  GetAddOnList(value)
end
local SetLoadedToProfile = function(info, value) end
local SetProfile = function(info, value) end
local LoadSelectedProfile = function() print('Load #', Cf.selected_profile) end
function Cf:OnInitialize()
  db = DevianDB
  self.selected_profile = db.primary_channel
end

function Cf:OnEnable()

  D:Print('Options UI loaded')
  self.opts = {
    type = 'group',
    name = 'Devian',
    desc = 'Devkit in a nutshell',
    handler = Cf,
    set = SetOpt,
    get = GetOpt,
    args = {
      enabled = {
        type = 'toggle',
        name = 'Enable Print Handler',
        desc = 'Allows Devian to handle print() calls.',
        order = 10,
      },
      addon = {
        type = 'group',
        name = 'AddOns',
        order = 20,
        args= {
          selected_profile = {
            type = 'select',
            name = 'Profile',
            values = GetProfileList,
            set = function(info, value, ...) self.selected_profile = value print('select', value, ...) end,
            get = function(info) return self.selected_profile or 1 end,
            order = 10
          },
          load_selected = {
            func = LoadSelectedProfile,
            type = 'execute',
            name = 'Load Selected',
            desc = 'Save currently loaded AddOns as a profile.',
            order = 13,
          },
          t_header = {
            type = 'header',
            name = 'Addons',
            width = 'full',
            order = 15,
          },
          save_loaded = {
            func = SetLoadedToProfile,
            type = 'execute',
            name = 'Save Loaded',
            desc = 'Save currently loaded AddOns as a profile.',
            order = 400,
          },
          save_selected = {
            func = SetSelectedToProfile,
            type = 'execute',
            name = 'Save',
            desc = 'Save the selected AddOns as a profile.',
            order = 450,
          }
        }
      },
      channels = {
        type = 'group',
        name = 'Console',
        order = 30,
        args = {
          primary_channel = {
            type = 'select',
            name = 'Primary Channel',
            desc = 'Set the default output channel for untagged messages.',
            values = {},
          }
        }
      },
      tags = {
        type = 'group',
        name = 'Tags',
        order = 40,
        args = {
          enable_tag = {
            type = 'toggle',
            name ='Message prefix handling',
            desc = 'Enables direction of print() results to different channels based on the first whole word in the output.',
          }
        }
      },
    }
  }


  for i = 1, GetNumAddOns() do
    local name = GetAddOnInfo(i)
    local enableState, globalState = GetAddOnEnableState(playername, i), GetAddOnEnableState(nil, i)
    self.opts.args.addon.args['addon_'..i..'_desc'] = {
      type = 'description',
      name = name,
      width = 'single',
      order= (500+i*3)
    }
    self.opts.args.addon.args['addon_'..i..'_global'] = {
      type = 'toggle',
      name = '',
      get  = function() return (GetAddOnEnableState(nil, i) == 2) and true or false end,
      set  = function(info, value) EnableAddOn(i, value) end,
      width= 'half',
      order= (500+i*3+1)
    }

    self.opts.args.addon.args['addon_'..i..'_char'] = {
      type = 'toggle',
      name = '',
      get  = function() return (GetAddOnEnableState(GetUnitName('player'), i) == 1) and true or false end,
      set  = function(info, value) EnableAddOn(PLAYER_REALM, value) end,
      width= 'half',
      order= (500+i*3+2)
    }
  end

  LibStub("AceConfig-3.0"):RegisterOptionsTable("Devian", self.opts)
  self.diag = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("Devian", "Devian")
end

function Cf:ChatCommand(input)
  InterfaceOptionsFrame_OpenToCategory(self.diag)
  InterfaceOptionsFrame_OpenToCategory(self.diag)
end