changeset 87:e80723841888

- /dvn rc resets the current workspace channels and tags - slash command arguments handled by string.find - toggle command argument handling
author Nenue
date Tue, 26 Jul 2016 09:21:37 -0400
parents 6e27274da4d9
children 7ff0579e5a6e
files Config.lua Devian.lua UI.lua
diffstat 3 files changed, 32 insertions(+), 196 deletions(-) [+]
line wrap: on
line diff
--- a/Config.lua	Tue Jul 26 01:45:30 2016 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,175 +0,0 @@
---- 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
\ No newline at end of file
--- a/Devian.lua	Tue Jul 26 01:45:30 2016 -0400
+++ b/Devian.lua	Tue Jul 26 09:21:37 2016 -0400
@@ -594,13 +594,6 @@
   db.tagcolor = {}
   D:Print('Tag color cache cleared.')
 end
-D.ConfigCommand = function(self, input)
-  if not self.config then
-    self.config = DevCon
-    self:EnableModule("Config")
-  end
-  self.modules.Config:ChatCommand(input)
-end
 
 function D:OnEnable()
 
@@ -609,15 +602,20 @@
     ['dfs'] = 'FrameHelper_Update',
     ['dvn'] = "Command",
     ['devian'] = "Command",
-    ['dvc'] = "Console_Toggle",
+    ['dvc'] = function() D:Console_Toggle() end,
     ['dvncolors'] = "UnsetColors",
     ['cleandvn'] = "SetDefaultsAll",
     ['resetdvn'] = "SetDefaults",
-    ['dvg'] = "ConfigCommand"
   }
   for cmd, func in pairs(cmdlist) do
-    _G['SLASH_' .. cmd:upper() .. '1'] = "/"..cmd
-    SlashCmdList[cmd:upper()] = D[func]
+    local CMD = cmd:upper()
+    _G['SLASH_' .. CMD:upper() .. '1'] = "/"..cmd
+    if type(func == 'string') then
+      SlashCmdList[CMD] = D[func]
+    else
+      SlashCmdList[CMD] = func
+    end
+
   end
 end
 
--- a/UI.lua	Tue Jul 26 01:45:30 2016 -0400
+++ b/UI.lua	Tue Jul 26 09:21:37 2016 -0400
@@ -378,24 +378,33 @@
 --- Console frame toggler
 -- @paramsig [...]
 -- @param ... one or more space-seperated channel keys
-function D:Console_Toggle(input, force)
+function D:Console_Toggle(cmd, force)
+
+
+  local args = {}
+  if cmd then
+    cmd = tostring(cmd)
+    local i, j = 0, 0
+    repeat
+      i, j = cmd:find("%S+", j+1)
+      if i and j then
+        local key = cmd:sub(i, j)
+        if self.sig[key] then
+          --print(key, self.sigID[key])
+          insert(search, self.sigID[key])
+        elseif self.console[tonumber(key)] then
+          --print(key, tonumber(key))
+          insert(search, tonumber(key))
+        end
+      end
+    until not(i or j)
+  end
+
   local profile = D.currentProfile
   local setAll
   local search = {}
-  local key
-  local n = 0
-
   -- resolve key/sig values from args
-  while self:GetArgs(input,1,n) and n < 255 do
-    key, n = self:GetArgs(input,1,n)
-
-    if self.sig[key] then
-      --print(key, self.sigID[key])
-      insert(search, self.sigID[key])
-    elseif self.console[tonumber(key)] then
-      --print(key, tonumber(key))
-      insert(search, tonumber(key))
-    end
+  for i, key in ipairs(args) do
 
   --oldprint(#search, key, n)
   end