diff Devian.lua @ 89:b3ed963f482d v.2.1.92

- /dvc command needed a pre-defined enclosure to properly work through SlashCmdList - /dvn <profile name> and /dvn save <profile name> should resolve to and update the correct profile. - set some globals indicating the name and index of the workspace in use - DEVIAN_WORKSPACE (bool) - DEVIAN_PNAME (string) - DEVIAN_PID (number)
author Nenue
date Wed, 10 Aug 2016 06:58:27 -0400
parents e80723841888
children bb403e03d82d
line wrap: on
line diff
--- a/Devian.lua	Tue Jul 26 09:50:45 2016 -0400
+++ b/Devian.lua	Wed Aug 10 06:58:27 2016 -0400
@@ -18,6 +18,8 @@
 local playerRealm = playerName .. '-' .. GetRealmName()
 local num_dock_tabs = 0
 DEVIAN_WORKSPACE = false
+DEVIAN_PNAME = 'Dvn'
+DEVIAN_PID = 0
 
 
 DevianLoadMessage = setmetatable({}, {
@@ -224,11 +226,15 @@
   currentProfile.char[playerRealm] = currentProfile.char[playerRealm] or {}
   if currentProfile.workspace then
     DEVIAN_WORKSPACE = true
+    DEVIAN_PNAME = name
+    DEVIAN_PID = id
     setprinthandler(D.Message)
   else
     DEVIAN_WORKSPACE = false
+    DEVIAN_PNAME = ''
     print = function() end
   end
+  DEVIAN_PID =id
 
   D.unlisted = currentProfile.unlisted
   D.channels = currentProfile.channels
@@ -278,26 +284,57 @@
     return D.New(self, tag)
   elseif mode == 'remove' then
     return D.Remove(self, tag)
-  elseif tonumber(mode) ~= nil or mode == 'save' then
-    -- either a number of the save command
+  elseif mode ~= nil then
+    -- profile selector or save command
     if mode == 'save' then
       list_id = tonumber(tag)
-      if list_id == nil then
-        D:Print(L('Invalid ID from arg', tag))
+    else
+      list_id = tonumber(mode)
+    end
+
+    if not list_id then
+      if db.profilesName[tostring(list_id)] then
+        list_id = db.profilesName[tostring(list_id)]
+      else
+
+        D:Print(L('Unable to resolve profile ID/name', list_id, dest))
+        return
       end
+    end
+
+
+    if mode == 'save' then
       D.Profile(list_id, dest)
       scan_func = D.Save
-      D:Print("Profile |cFFFFFF00".. list_id .."|r saved.")
+
+
+      local name = currentProfile.name
+      if dest then
+        dest = dest:gsub("$%s+", ''):gsub("%s+^", '')
+        if dest then
+          if name then
+            db.profilesName[name] = nil
+          end
+          db.profiles[list_id].name = dest
+          db.profilesName[dest] = list_id
+        end
+      end
+
+
+      D:Print("Profile |cFFFFFF00".. list_id .."|r:|cFF00FFFF".. name .."|r saved.")
     else
 
-      D.LoadMessage "Switched profiles."
+      if db.profiles[list_id] then
+        D.LoadMessage ("Switched profiles.")
+        if list_id ~= db.main_profile then
+          db.last_profile = list_id
+        end
+        db.current_profile = list_id
+        scan_func = D.Load
+      else
+        return D:PrintHelp()
+      end
 
-      list_id = tonumber(mode)
-      if list_id ~= db.main_profile then
-        db.last_profile = list_id
-      end
-      db.current_profile = list_id
-      scan_func = D.Load
     end
   elseif mode == nil then
     list_id = (db.current_profile ~= db.main_profile) and db.main_profile or db.last_profile
@@ -305,6 +342,8 @@
     db.current_profile = list_id
     scan_func = D.Load
   else
+
+
     return D:PrintHelp()
   end
 
@@ -595,29 +634,11 @@
   D:Print('Tag color cache cleared.')
 end
 
-function D:OnEnable()
 
-  -- commands
-  local cmdlist = {
-    ['dfs'] = 'FrameHelper_Update',
-    ['dvn'] = "Command",
-    ['devian'] = "Command",
-    ['dvc'] = function() D:Console_Toggle() end,
-    ['dvncolors'] = "UnsetColors",
-    ['cleandvn'] = "SetDefaultsAll",
-    ['resetdvn'] = "SetDefaults",
-  }
-  for cmd, func in pairs(cmdlist) do
-    local CMD = cmd:upper()
-    _G['SLASH_' .. CMD:upper() .. '1'] = "/"..cmd
-    if type(func == 'string') then
-      SlashCmdList[CMD] = D[func]
-    else
-      SlashCmdList[CMD] = func
-    end
+function D.ConsoleCommand (cmd)
+  D:Console_Toggle(cmd)
+end
 
-  end
-end
 
 function D:OnInitialize()
   L = D.L
@@ -639,6 +660,28 @@
   end
 
 
+  -- commands
+  local cmdlist = {
+    ['dvn'] = "Command",
+    ['devian'] = "Command",
+    ['dvc'] = "ConsoleCommand",
+    ['dvncolors'] = "UnsetColors",
+    ['cleandvn'] = "SetDefaultsAll",
+    ['resetdvn'] = "SetDefaults",
+  }
+  for cmd, func in pairs(cmdlist) do
+    local CMD = cmd:upper()
+    _G['SLASH_' .. CMD .. '1'] = "/"..cmd
+
+    if type(func == 'string') then
+      print('SLASH_' .. CMD .. '1','/'.. cmd, func)
+      SlashCmdList[CMD] = D[func]
+    else
+      print('SLASH_' .. CMD .. '1','/'.. cmd, func)
+      SlashCmdList[CMD] = func
+    end
+  end
+
   --- initialize the current profile
   local id, name = D.Profile(db.current_profile or 1)
   D:Print('Using profile |cFFFFFF00'.. id ..'|r: |cFF00FF00'..currentProfile.name..'|r')
@@ -677,3 +720,4 @@
     D:UpdateDock()
   end
 end
+