diff Devian.lua @ 66:516ceb31703d

New profile system that stores channel and tag settings for each saved AddOn list. A boatload of structural revisions, making better use of the built-in table, and hopefully making console command issues easier to pick up.
author Nenue
date Sat, 05 Mar 2016 13:35:51 -0500
parents 59e047d6c5de
children 137b8c55a593
line wrap: on
line diff
--- a/Devian.lua	Fri Mar 04 08:01:16 2016 -0500
+++ b/Devian.lua	Sat Mar 05 13:35:51 2016 -0500
@@ -2,46 +2,83 @@
 -- @file-author@
 -- @project-revision@ @project-hash@
 -- @file-revision@ @file-hash@
-if not LibStub then
-  print('Something has happened...')
+
+--GLOBALS: Devian, DevCon, DevianLoadMessage
+local ADDON, D = ...
+
+local currentProfile
+local playerName = UnitName("player")
+local playerRealm = playerName .. '-' .. GetRealmName()
+local num_dock_tabs = 0
+local in_workspace = false
+--@debug@
+D.debugmode = true
+--@end-debug@
+D.print = function(...)
+  if currentProfile and not currentProfile.workspace then
+    return
+  end
+
+  if D.debugmode then
+    return print('Dvn', ...)
+  else
+    return function() end
+  end
 end
+local print = D.print
+
+setmetatable(D, {
+  __call = function(t,k)
+    if not k then
+      return t.in_workspace
+    end
+
+    return function(value)
+      if value then
+        D[k] = value
+      end
+      return D[k]
+    end
+  end
+})
+D.L = setmetatable({}, {
+  __index= function(t,k)
+    return k
+  end,
+  __call = function(t,k,...)
+    return string.format((t[k] or k) , ...)
+  end
+})
+
 local MAJOR, MINOR = 'Devian-2.0', 'r@project-revision@'
-Devian = LibStub("AceAddon-3.0"):NewAddon("Devian", "AceConsole-3.0", "AceEvent-3.0")
-local D = _G.Devian
+local D =  LibStub("AceAddon-3.0"):NewAddon(D, "Devian", "AceConsole-3.0", "AceEvent-3.0")
+local L = D.L
+_G.Devian = D
 D:SetDefaultModuleState(false)
-D.L = {}
-setmetatable(D.L, {__index= function(t,k) return k end, __call = function(t,k,...) return string.format((t[k] or k) , ...) end})
-local L = D.L
+D.oldprint = getprinthandler()
+if not _G.oldprint then _G.oldprint = D.oldprint end
+
 local pairs, tostring, tonumber, ipairs, type = pairs, tostring, tonumber, ipairs, type
-local max, rand, format = math.max, math.random, string.format
+local max, rand, format, print = max, math.random, string.format, print
 local insert, wipe, concat = table.insert, table.wipe, table.concat
 local select, unpack = select, unpack
 local GetNumAddOns, GetAddOnInfo, GetAddOnEnableState, EnableAddOn = GetNumAddOns, GetAddOnInfo, GetAddOnEnableState, EnableAddOn
 local UnitName, DisableAddOn = UnitName, DisableAddOn
-local WORKSPACE_ON, WORKSPACE_OFF = 1, 2
-local PLAYER_REALM = UnitName("player") .. '-' .. GetRealmName()
-local print = _G.print
+
 local db
 local defaults = {
-  ['global'] = {{}, {}},
-  ['tags'] = {},
-  ['channels'] = {[1] = {
+  global = {{}, {}},
+  default_channel = {
     signature = 'Main',
-    index = 1,
     x = 100, y = 800,
     height = 500, width = 600,
-    enabled = true}},
-  ['profiles'] = {
-    {'Main', false},
-    {'Devian', true},
-    {'Turok', true},
-    {'Bam', true}
+    enabled = true},
+  current_profile = 1,
+  main_profile = 1,
+  last_profile = 1,
+  profilesName = {},
+  profiles = {
   },
-  primary_channel = 1, -- the channel to which default output is sent
-  current_channel = 1, -- the front channel
-  max_channel = 1, -- the highest created channel id
-  enabled = true, -- allow enabled consoles to appear
-  load_message = "Defaults loaded.", -- messages to be displayed after reload
   font = [[Interface\Addons\Devian\font\SourceCodePro-Regular.ttf]], -- font info
   fontsize = 13,
   fontoutline = 'NONE',
@@ -91,9 +128,91 @@
   movement_translation_y = 25,
 }
 
-local function ScanAddOnList(cmd, ...)
-  local list_state
+D.console = {}
+D.max_channel = 0
 
+D.Profile = function (id, name)
+
+  if name and not id and db.profilesName[name] then
+    id = db.profilesName[name]
+    print('ID located by name, |cFF00FF00'..name..'|r is |cFFFFFF00'.. id..'|r')
+  end
+
+  if not id or not db.profiles[id] then
+    if not id then
+      id = #db.profiles+1
+      print('Generated profile ID: |cFFFFFF00'.. id .. '|r')
+    end
+
+    if not name or db.profilesName[name] then
+      local newName = name or (id == 1 and 'Main' or 'Profile')
+      local prefix = newName
+      local i = 2
+      while db.profilesName[newName] do
+        i = i + 1
+        newName = prefix .. i
+      end
+      name = newName
+      print('Generated profile name: |cFF00FF00'..newName..'|r')
+    end
+    print('Creating profile')
+    db.profilesName[name] = id
+    db.profiles[id] = {
+      name = name,
+      workspace = (id ~= 1),
+      current_channel = 1,
+      default_channel = 1,
+      num_channels = 1,
+      max_channel = 1, -- the highest created channel id
+      enabled = true, -- allow enabled consoles to appear
+      channels = {
+        {
+          index = 1,
+          signature = 'Main',
+          x = 100, y = 800,
+          height = 500, width = 600,
+          enabled = true
+        }
+      },
+      loadouts = {},
+      global = {},
+      tags = {},
+      char = {
+        [playerRealm] = {}
+      },
+      unlisted = {}
+    }
+  end
+
+  D.currentProfile = db.profiles[id]
+  currentProfile = D.currentProfile
+  currentProfile.char[playerRealm] = currentProfile.char[playerRealm] or {}
+  if currentProfile.workspace then
+    setprinthandler(D.Message)
+  else
+    print = function() end
+  end
+
+  D.unlisted = currentProfile.unlisted
+  D.channels = currentProfile.channels
+  D.tags = currentProfile.tags
+  D.channelinfo = currentProfile.channels
+  D.char = currentProfile.char[playerRealm]
+  D.global = currentProfile.global
+  D.num_channels = currentProfile.num_channels
+  D.enabled = currentProfile.enabled
+  D.sig = {}
+  D.sigID = {}
+  D.IDsig = {}
+  D.dock = DevianDock
+  D.dock.buttons = D.dock.buttons or {}
+
+  return id, name
+end
+
+local targetGlobal, targetChar
+D.Command = function (self, cmd, ...)
+  local list_id, scan_func, reload
   local args = {}
   local arg, n = D:GetArgs(cmd, 1)
   while arg do
@@ -102,151 +221,137 @@
   end
   local mode, tag, dest = unpack(args)
 
-
   -- no args, toggle ui
   if  mode == 'stack' then
-    if db.workspace == 1 then
-      return D:Print(L['Need devmode'])
-    end
     return D:StackFrames()
   elseif mode == 'grid' then
-    if db.workspace == 1 then
-      return D:Print(L['Need devmode'])
-    end
     return D:DistributeFrames()
   elseif mode == 'tag' then -- tagging
-    if db.workspace == 1 then
-      return D:Print(L['Need devmode'])
-    end
+    return D.Tag(self, tag, dest)
+  elseif tonumber(mode) ~= nil or mode == 'save' then
+    -- either a number of the save command
+    if mode == 'save' then
+      list_id = tonumber(tag)
+      if list_id == nil then
+        D:Print(L('Invalid ID from arg', tag))
+      end
+      D.Profile(list_id, dest)
+      scan_func = D.Save
+      D:Print("Profile |cFFFFFF00".. list_id .."|r saved.")
+    else
 
-    local sig
-    if tag ~= nil and dest ~= nil then
-      --@debug@
-      --print(tag, dest)
-      --@end-debug@
+      DevianLoadMessage = "Switched profiles."
 
-      -- convert to ID
-      if tonumber(dest) == nil then
-        if D.sigID[dest] then
-          dest = db.channels[D.sigID[dest]].index
-        else
-          sig = dest
-        end
-      else
-        dest = tonumber(dest)
+      list_id = tonumber(mode)
+      if list_id ~= db.main_profile then
+        db.last_profile = list_id
       end
-      --@debug@
-      --print('2 tag,dest,sig', tag, dest, sig)--@end-debug@
-
-      -- make a new channel?
-      local channel
-      if not D.db.channels[dest] then
-        dest = D.max_channel + 1
-        D:Print(L('New channel created', sig and (dest..':'..sig) or dest ))
-        channel = D:SetChannel(sig or tag,dest)
-      else
-
-        channel = D.db.channels[dest]
-      end
-      --@debug@
-      --print('3 tag,dest,channel.sig=',tag, dest, channel.signature)--@end-debug@
-
-      if not db.tags[tag] then -- no tag table?
-        db.tags[tag] = {}
-      end
-
-      if db.tags[tag][dest] then -- is tag set?
-        db.tags[tag][dest] = nil
-        D:Print(L('Tag removed from channel', tag, db.channels[dest].index, db.channels[dest].signature))
-      else
-        db.tags[tag][dest] = dest
-        D:Print(L('Tag added to channel', tag, db.channels[dest].index, db.channels[dest].signature))
-      end
-      D:UpdateDock()
-    else
-      D:Print(L['Command tag help'])
-    end
-    return
-  elseif tonumber(mode) ~= nil or mode == 'save' then
-    -- iterating for something
-    if mode == 'save' then
-      if tonumber(tag) == nil then
-        T:Print(L('Invalid ID from arg', tag))
-      end
-      list_state = tonumber(tag)
-    else
-      list_state = tonumber(mode)
-      db.workspace = list_state
-      if list_state ~= 1 then
-        db.last_workspace = list_state
-      end
-
+      db.current_profile = list_id
+      scan_func = D.Load
     end
   elseif mode == nil then
-    list_state = (db.workspace == 1) and db.last_workspace or 1
-    db.workspace = list_state
+    list_id = (db.current_profile ~= db.main_profile) and db.main_profile or db.last_profile
+    DevianLoadMessage = "Switched between main and recent profile ("..db.current_profile..' and '..list_id..')'
+    db.current_profile = list_id
+    scan_func = D.Load
   else
     return D:PrintHelp()
   end
+  targetGlobal = db.profiles[list_id].global
+  targetChar = db.profiles[list_id].char[playerRealm]
 
-  -- start the iterating
-  if not db[PLAYER_REALM][list_state] then
-    db[PLAYER_REALM][list_state] = {}
-  end
-  if not db.global[list_state] then
-    db.global[list_state] = {}
-    end
-
-  local char_list, global_list = db[PLAYER_REALM][list_state], db.global[list_state]
-  local playername = UnitName("player")
-
-  for i = 1, GetNumAddOns() do
-    local name = GetAddOnInfo(i)
-    local enableState, globalState = GetAddOnEnableState(playername, i), GetAddOnEnableState(nil, i)
-
-    if mode == 'save' then
-      char_list[name] = enableState
-      global_list[name] = globalState
-    else
-      if char_list[name] or global_list[name] then
-        if char_list[name] ~= 0 and global_list[name] ~= 0 then
-          local value = false
-          if char_list[name] == 2 and global_list[name] == 1 then
-            value = UnitName("player")
-          elseif global_list[name] == 2 then
-            value = true
-          end
-          --print('EnableAddOn(', i, ',', value,')')
-          EnableAddOn(i, value)
-        else
-          local value = true
-          if char_list[name] == 2 and global_list[name] == 1 then
-            value = UnitName("player")
-          end
-          --print('DisableAddOn(', i, ',', value,')')
-          DisableAddOn(i,value)
-        end
-      elseif mode ~= 'save' then
-        if type(db.unlisted) ~= 'table' then
-          db.unlisted = {}
-        end
-        insert(db.unlisted, name)
-      end
-
+  if scan_func then
+    for id, name, enableState, globalState in D.Addons() do
+      scan_func(id, name, enableState, globalState)
     end
   end
 
-  if mode ~= 'save' then
-    db.load_message = (mode == nil) and L("Toggled to profile", list_state) or L('Switched to profile number', list_state)
+  if scan_func == D.Load then
     ReloadUI()
+  end
+  D.Profile(db.current_profile)
+end
+
+D.Addons = function()
+  local playername = UnitName("player")
+  return function(n, i)
+    if i >= n then
+      return nil
+    end
+
+    i = i + 1
+    local name = GetAddOnInfo(i)
+    local enableState, globalState = GetAddOnEnableState(playername, i), GetAddOnEnableState(nil, i)
+    return i, name, enableState, globalState
+  end, GetNumAddOns(), 0
+end
+
+D.Load = function(id, name, charState, globalState)
+  if targetChar[name] or targetGlobal[name] then
+    if targetGlobal[name] == 2 then
+      EnableAddOn(id, true)
+    elseif targetChar[name] == 2 then
+      EnableAddOn(id, playerName)
+    else
+      DisableAddOn(id, playerName)
+    end
+    print('load', name, 'global =', targetGlobal[name], 'char =', targetChar[name])
   else
+    tinsert(D.unlisted, name)
+  end
+end
+D.Save = function(id, name, charState, globalState)
+  print('save', id, name, charState, globalState)
+  targetGlobal[name] = globalState
+  targetChar[name] = charState
+end
 
-    if list_state == 1 then
-      D:Print(L['Profile main saved'])
+D.Tag = function(self, tag, dest)
+  local sig
+  if tag ~= nil and dest ~= nil then
+    --@debug@
+    --print(tag, dest)
+    --@end-debug@
+
+    -- convert to ID
+    if tonumber(dest) == nil then
+      if D.sigID[dest] then
+        dest = currentProfile.channels[D.sigID[dest]].index
+      else
+        sig = dest
+      end
     else
-      db.last_workspace = list_state
-      D:Print(L('Profile number saved', list_state, list_state))
+      dest = tonumber(dest)
     end
+    --@debug@
+    --print('2 tag,dest,sig', tag, dest, sig)--@end-debug@
+
+    -- make a new channel?
+    local channel
+    if not currentProfile.channels[dest] then
+      dest = D.max_channel + 1
+      D:Print(L('New channel created', sig and (dest..':'..sig) or dest ))
+      channel = D:SetChannel(sig or tag,dest)
+    else
+      channel = D.channels[dest]
+    end
+    --@debug@
+    --print('3 tag,dest,channel.sig=',tag, dest, channel.signature)--@end-debug@
+
+    if not currentProfile.tags[tag] then -- no tag table?
+    currentProfile.tags[tag] = {}
+    end
+
+    if currentProfile.tags[tag][dest] then -- is tag set?
+    currentProfile.tags[tag][dest] = nil
+    D:Print(L('Tag removed from channel', tag, currentProfile.channels[dest].index, currentProfile.channels[dest].signature))
+    else
+      currentProfile.tags[tag][dest] = dest
+      D:Print(L('Tag added to channel', tag, currentProfile.channels[dest].index, currentProfile.channels[dest].signature))
+    end
+    D:UpdateDock()
+  else
+    D:Print(L['Command tag help'])
   end
 end
 
@@ -257,8 +362,8 @@
 -- This becomes the print handler when development mode is active. The original print() function is assigned to oldprint().
 -- @param Tag, signature, or numeric index of the channel to output on. Defaults to primary channel.
 -- @param ... Output contents.
-local function Message(prefix, ...)
-  if db.workspace == 1 then
+function D.Message(prefix, ...)
+  if currentProfile.workspace then
     return D.oldprint(prefix, ...)
   end
   prefix =  tostring(prefix)
@@ -349,110 +454,51 @@
   D:Print("|cFFFFFF00/cleandvn|r", "- Fully resets SavedVariables, profiles and all.")
 end
 
-local dot1, dot2 = CreateFrame('Frame', nil, UIParent), CreateFrame('Frame', nil, UIParent)
-dot1:SetSize(5,5)
-dot1:SetFrameStrata('TOOLTIP')
-local a = dot1:CreateTexture('fill', nil)
-a:SetAllPoints(dot1)
-a:SetTexture(1,0,0,1)
-dot2:SetSize(5,5)
-dot2:SetFrameStrata('TOOLTIP')
-a = dot2:CreateTexture('fill', nil)
-a:SetAllPoints(dot2)
-a:SetTexture(0,1,0,1)
-
-local OnStartedMoving = function()
-  for k, v in pairs(D.console) do
-    if v.enabled then
-      v.moveFade:Stop()
-      local F1 = v.moveFade.alphaOut
-      F1:SetFromAlpha(db.movement_fade_from)
-      F1:SetToAlpha(db.movement_fade_to)
-      F1:SetDuration(db.movement_fade_time)
-      v.moveFade:Play()
-      v:EnableMouse(false)
+local blocked = {profiles = true, debugmode = true}
+D.SetDefaults = function()
+  for k,v in pairs(DevianDB) do
+    if not blocked[k] then
+      DevianDB[k] = nil
     end
   end
-end
-
-local OnStoppedMoving = function()
-  for k, v in pairs(D.console) do
-    if v.enabled then
-      v.moveFade:Stop()
-      local F1 = v.moveFade.alphaOut
-      F1:SetToAlpha(db.movement_fade_from)
-      F1:SetFromAlpha(db.movement_fade_to)
-      F1:SetDuration(db.movement_fade_time)
-      v.moveFade:Play()
-      v:EnableMouse(true)
+  for k,v in pairs(defaults) do
+    if not blocked[k] then
+      DevianDB[k] = v
     end
   end
+  DevianLoadMessage = "Non-user SavedVars have been reset."
+  ReloadUI()
 end
-
+D.SetDefaultsAll = function ()
+  DevianDB = nil
+  DevianLoadMessage = "All SavedVars wiped."
+  ReloadUI()
+end
+D.ConfigCommand = function(input)
+  if not self.config then
+    self.config = DevCon
+    self:EnableModule("Config")
+  end
+  self.modules.Config:ChatCommand(input)
+end
 
 function D:OnEnable()
 
-  if db.unlisted and #db.unlisted > 0 then
-    D:Print('New AddOns have been found since the last profile update: '.. concat(db.unlisted, ', '))
-    wipe(db.unlisted)
-  end
-
-  if db.workspace == 1 then
-    D:Print(L('Devian loaded on standby',MAJOR, MINOR))
-  else
-    D:Print(L('Devian loaded in workspace', MAJOR, MINOR, db.workspace))
-    -- movement fading
-    if db.movement_fade then
-
-      self:RegisterEvent('PLAYER_STARTED_MOVING', OnStartedMoving)
-      self:RegisterEvent('PLAYER_STOPPED_MOVING', OnStoppedMoving)
-    end
-  end
-
-  --@debug@
-  self:RegisterChatCommand("dvg", function(input)
-    if not self.config then
-      self.config = DevCon
-      self:EnableModule("Config")
-    end
-    self.modules.Config:ChatCommand(input)
-  end)
-  --@end-debug@
-
-end
-
-function D:OnInitialize()
   -- commands
-  self:RegisterChatCommand("cleandvn", function(args)
-    DevianDB = nil
-    DevianDB = {
-      load_message = "All SavedVars wiped."
-    }
-    ReloadUI()
-    end)
-  local blocked = {global = true, channels = true, tags = true, [PLAYER_REALM] = true}
-  self:RegisterChatCommand("resetdvn", function(args)
-    for k,v in pairs(DevianDB) do
-      if not blocked[k] then
-        DevianDB[k] = nil
-      end
-    end
-    for k,v in pairs(defaults) do
-      if not blocked[k] then
-        DevianDB[k] = v
-      end
-    end
-    DevianDB.load_message = "Non-user SavedVars have been reset."
-    ReloadUI()
-  end)
   local cmdlist = {
-    ['dvn'] = ScanAddOnList,
-    ['devian'] = ScanAddOnList,
+    ['dvn'] = "Command",
+    ['devian'] = "Command",
     ['dvc'] = "Console_Toggle",
+    ['cleandvn'] = "SetDefaultsAll",
+    ['resetdvn'] = "SetDefaults",
+    ['dvg'] = "ConfigCommand"
   }
   for cmd, func in pairs(cmdlist) do
     self:RegisterChatCommand(cmd, func, true)
   end
+end
+
+function D:OnInitialize()
 
   -- pull defaults
   if not _G.DevianDB then
@@ -460,135 +506,45 @@
   end
   db = _G.DevianDB
   self.db = db
-  self.tags = db.tags
-  self.channelinfo = db.channels
 
-  if not db[PLAYER_REALM] then
-    db[PLAYER_REALM] = {[WORKSPACE_ON] = {}, [WORKSPACE_OFF] = {}}
+  ---
+  if DevianLoadMessage then
+    D:Print(DevianLoadMessage)
+    DevianLoadMessage = nil
   end
 
-  if db.load_message then
-    D:Print(db.load_message)
-    db.load_message = nil
-  end
-  D.oldprint = getprinthandler()
-  if not _G.oldprint then
-    _G.oldprint = D.oldprint
+
+  --- 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')
+  if  currentProfile.workspace then
+    D:Print('Workspace: '.. (#currentProfile.channels) .. ' channels, ' .. #currentProfile.tags .. ' tags.')
+    D:Print('Default channel: |cFFFFFF00'..currentProfile.default_channel..'|r: |cFF00FFFF'.. D.channels[currentProfile.default_channel].signature..'|r')
   end
 
-  -- Stop here in game mode
-  if db.workspace == 1 then
-    return
-  end
-  -----------------------------------------------------------------------
-  self.db = db
-  self.channels = db.channels
-  self.max_channel = 0
-  self.num_channels = 0
-  self.console = {}
-  self.sig = {}
-  self.sigID = {}
-  self.IDsig = {}
-  self.dock = DevianDock
-  self.dock.buttons = {}
-  for i, cinfo in pairs(db.channels) do
+  for i, cinfo in pairs(D.channels) do
     i = tonumber(i)
-    if not self.primary_channel then
-      self.primary_channel = i
+    if not D.primary_channel then
+      D.primary_channel = i
     end
-    self:SetChannel(cinfo, i)
-    self.max_channel = max(i, self.max_channel)
-    self.num_channels = self.num_channels + 1
+    D:SetChannel(cinfo, i)
+    D.num_channels = D.num_channels + 1
   end
 
-  if self.console[db.current_channel] then
-    print('bringing', self.console[db.current_channel].signature, 'to the front')
-    self.console[db.current_channel]:ToFront()
-    -- bring the current channel to the front
-  end
-  DevianDock:Show()
-  self:UpdateDock()
-  setprinthandler(Message)
-  print = function(...)
-    _G.print('Dvn', ...)
-  end
-end
-
---- Console frame toggler
--- @paramsig [...]
--- @param ... one or more space-seperated channel keys
-function D:Console_Toggle(input, force)
-  --oldprint(input)
-  local setAll
-  if db.workspace == 1 then
-    return self:Print(MSG_NEED_DEV_MODE)
-  end
-  local search = {}
-  local key
-  local n = 0
-  while self:GetArgs(input,1,n) and n < 255 do --should end itself when it gets nil, but
-      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
-
-      --oldprint(#search, key, n)
-  end
-  if #search < 1 then
-    search = self.sigID
-    setAll = true
-  end
-  if setAll then
-    --oldprint('setall', setAll)
-    db.enabled = (not db.enabled) and true or nil
-    if force == 0 then
-      db.enabled = nil
+  D.max_channel = max(D.max_channel, currentProfile.max_channel)
+  if currentProfile.max_channel < D.max_channel then
+    for i = currentProfile.max_channel, D.max_channel do
+      D.console[i]:Hide()
     end
   end
 
-  for i, id in pairs(search) do
-    --oldprint(i, id)
-    local c = self.console[id]
-    if setAll then
-      c.enabled = db.enabled and db.enabled or nil
-    else
-
-      db.enabled = true
-      c.enabled = (not c.enabled) and true or nil
-      if force == 0 then
-        c.enabled = nil
-      end
-      --oldprint(id, '  ', force, c.enabled, db.enabled)
+  if currentProfile.workspace then
+    if D.console[currentProfile.current_channel] then
+      print('bringing', D.console[currentProfile.current_channel].signature, 'to the front')
+      D.console[currentProfile.current_channel]:ToFront()
+      -- bring the current channel to the front
     end
-
-    if c.enabled or (setAll and db.enabled) then
-      c:Show()
-    elseif not (c.enabled and db.enabled) then
-      c:Hide()
-    end
-    c:Save()
+    DevianDock:Show()
+    D:UpdateDock()
   end
-
-  if setAll then
-    if db.enabled then
-      self:Print('toggled all consoles ON')
-      if D.console[db.current_channel] then
-        oldprint('push', D.console[db.current_channel].signature, 'to the front')
-        D.console[db.current_channel]:ToFront()
-      end
-    else
-      self:Print('toggled all consoles OFF')
-    end
-  else
-    local result = {}
-    for i, id in pairs(search) do
-      result[i] = tostring(id) .. ' = ' .. (self.console[id].enabled and 'ON' or 'OFF')
-    end
-    self:Print('toggled: '..concat(result, ', '))
-  end
-end
\ No newline at end of file
+end