view SkeletonKey/BindingsFrame.lua @ 65:556e075983a6

check for valid spell name when updating talent data
author Nenue
date Sat, 10 Sep 2016 19:08:19 -0400
parents 2409fe9b81e1
children
line wrap: on
line source
-- KrakTool
-- BindingsFrame.lua
-- Created: 7/28/2016 3:39 PM
-- %file-revision%
-- Handles the arrangement of and interaction with the SkeletonKey frame
--[=[
  -- some useful texture paths
  [[Interface\PaperDollInfoFrame\UI-GearManager-Undo]]
  [[Interface\PetPaperDollFrame\UI-PetHappiness]]
  [[Interface\RAIDFRAME\ReadyCheck-Waiting]]
  [[Interface\RAIDFRAME\ReadyCheck-Read]]
  [[Interface\RAIDFRAME\ReadyCheck-NotReady]]
  [[Interface\TradeSkillFrame\UI-TradeSkill-LinkButton]]
  [[Interface\TUTORIALFRAME\UI-TUTORIAL-FRAME]]
  [[Interface\UI-TutorialFrame-QuestGiver\UI-TutorialFrame-QuestGray]]
--]=]

local kb, print = LibStub("LibKraken").register(KeyBinder, 'BindingsUI')
local L = kb.L
local BINDS_PER_ROW = 2
local BINDING_TYPE_SPECIALIZATION = 3
local BINDING_TYPE_CHARACTER = 2
local BINDING_TYPE_GLOBAL = 1
local BUTTON_HSPACING = 128
local BUTTON_SPACING = 4
local BUTTON_PADDING = 12
local KEY_BUTTON_SIZE = 48
local NUM_KEY_SLOTS = BINDS_PER_ROW * 8
local TAB_HEIGHT = 40

local BINDING_SCHEME_COLOR = {
  [BINDING_TYPE_GLOBAL] = {0,.125,.5,.5},
  [BINDING_TYPE_CHARACTER] = {0,0.25,0,0.5},
  [BINDING_TYPE_SPECIALIZATION] = {.25,0,0,0.5},
}
local BINDING_SCHEME_VERTEX = {
  [BINDING_TYPE_GLOBAL] = {0,.5,1,1},
  [BINDING_TYPE_CHARACTER] = {0,1,0,1},
  [BINDING_TYPE_SPECIALIZATION] = {1,1,1,1},
}
local BINDING_SCHEME_TEXT = {
  [BINDING_TYPE_SPECIALIZATION] = {0, 1, 1},
  [BINDING_TYPE_CHARACTER] = {0, 1, 0},
  [BINDING_TYPE_GLOBAL] = {0, 1, 1}
}

local match, strupper = string.match, string.upper
local tremove, tinsert, ipairs, pairs, unpack = table.remove, table.insert, ipairs, pairs, unpack
local tonumber, tostring = tonumber, tostring
local GetCursorInfo, ClearCursor, ResetCursor = GetCursorInfo, ClearCursor, ResetCursor
local IsShiftKeyDown, IsControlKeyDown, IsAltKeyDown = IsShiftKeyDown, IsControlKeyDown, IsAltKeyDown
local GetBindingAction, GetBindingKey, GetCurrentBindingSet = GetBindingAction, GetBindingKey, GetCurrentBindingSet
local SetBinding, SaveBindings = SetBinding, SaveBindings
local GetSpellInfo, InCombatLockdown = GetSpellInfo, InCombatLockdown

kb.ProcessInput = function(key)
  if key == 'ESCAPE' then
    kb.DeactivateSlot(kb.saveTarget)
    kb.ui()
    return
  end

  if (match(key, '[RL]SHIFT') or match(key, '[RL]ALT') or match(key, '[RL]CTRL')) then
    return
  end

  if kb.saveTarget then
    if kb.SaveSlot(kb.saveTarget, key) then
      if not (kb.db.stickyMode or kb.db.hoverInput) then
        kb.DeactivateSlot(kb.saveTarget)
      end
    end
    kb.ui()
  end
end

local lastFolder
local restingAlpha = 0.7
local fadeTime, fadeDelay = .30, 0.15
local saveButton

local KeyButton_OnKeyDown = function(self, key)
  local st = kb.saveTarget
  kb.ProcessInput(key)
end
local KeyButton_OnKeyUp = function(self, key)
  local st = kb.saveTarget
end

local KeyButton_OnClick = function(self, click)
  print(self:GetName(), 'OnMouseDown', click)
  local cursorType = GetCursorInfo()
  if click == 'LeftButton' then
    if cursorType then
      kb.DropToSlot(self)
    else
      if self.command and self.isAvailable then
        if IsShiftKeyDown() then
          kb.db.stickyMode = true
          KeyBinderStickyMode:SetChecked(true)
        end
        kb.ActivateSlot(self)
        kb.ui()
      end
    end
  elseif click == 'RightButton' then
    kb.ReleaseSlot(self)
    kb.ui()
  else
    kb.ProcessInput(strupper(click))
  end
end

local KeyButton_OnDragStart = function(self)
  kb.PickupSlot(self)
end

local KeyButton_OnReceiveDrag = function(self, ...)
  kb.DropToSlot(self)
end


local KeyBinder_OnUpdate = function(self, elapsed)
  self.elapsed = self.elapsed + elapsed
  self.throttle = self.throttle + elapsed

  if (self.throttle >= 0.032) then
    self.throttle = 0
  else
    return
  end

  local progress = 1
  if self.elapsed > fadeTime then
    self.elapsed = 0
    self.fadeStep = 0
    --self.statustext:SetText(nil)
    --self.bindingstext:SetText(nil)
    self:SetScript('OnUpdate', nil)
  else
    if self.elapsed < fadeDelay then
      progress = 0
    else
      self.fadeStep = self.fadeStep + 1
      progress = (self.elapsed - fadeDelay) /(fadeTime - fadeDelay)
    end
    --print(self.fadeStep, format('%.02f/%.02f', (self.elapsed - fadeDelay) ,(fadeTime - fadeDelay)) , progress)
  end

  local alpha = 1 - progress * (1- restingAlpha)
  self.statustext:SetAlpha(alpha)
  self.bindingstext:SetAlpha(alpha)
end

local KeyButton_OnUpdate = function(self)
  if not self.command then
    return
  end

  if self:IsMouseOver() then
    kb.elapsed = 0
    if not self.active then
      -- only set this handler when the button is activated/mouseOver
      self.active = true
      kb.statustext:SetText(self.statusText .. ': '..self.actionName)
      kb.bindingstext:SetText(self.bindingText)
      kb.fadeStep = 0
      kb.throttle = 0
      kb:SetScript('OnUpdate', KeyBinder_OnUpdate)

      if kb.db.hoverInput and kb.saveTarget ~= self then
        kb.ActivateSlot(self)
        kb.ui()
      end

    end
  else
    if self.active and kb.db.hoverInput then
      self.active = nil
      --kb.DeactivateSlot(self)
      --kb.ui()
    end
  end
end

local KeyBinder_OnMouseWheel = function(self, delta)
  print(self, delta, self.scrollOffset, (self.scrollOffset <= 0))


  if IsControlKeyDown() then
    KEY_BUTTON_SIZE = KEY_BUTTON_SIZE - delta
  else


    if (delta > 0) and (self.scrollOffset <= 0) then
      return
    elseif delta < 0 and kb.scrollOffset >= 42 then
      return
    end
    kb.scrollOffset = ceil(kb.scrollOffset - (delta * BINDS_PER_ROW))
  end

  for i = 1, #kb.buttons do
      kb.buttons[i]:SetSize(KEY_BUTTON_SIZE,KEY_BUTTON_SIZE)
  end

  kb.ui(true)
end

local frameCount = 0
local lastCheckFrame
local KeyBinder_CheckButton = function(frame ,enableText, disableText, dbKey, tooltipText, callback, header)
  if kb.db[dbKey] then
    frame:SetChecked(true)
  end

  frame.header:SetText(header)

  frame:SetScript('OnClick', function(self)
    kb.db[dbKey] = self:GetChecked()
    if callback then
      callback(self)
    end
    kb.ui()
  end)

  frame:SetScript('OnEnter', function(self)
    if tooltipText then
      GameTooltip:SetOwner(self)
      GameTooltip:SetText(tooltipText)
      GameTooltip:Show()
    end
  end)

  frame:SetScript('OnLeave', function(self)
    if tooltipText and GameTooltip:GetOwner() == self then
      GameTooltip:Hide()
    end
  end)

  if frame:GetID() == 0 then
    frameCount = frameCount + 1
    frame:SetID(frameCount)
    print('checkbutton #', frameCount)
    if frameCount == 1 then
      frame:ClearAllPoints()
      frame:SetPoint('TOP', KeyBinderInventoryButton, 'BOTTOM', 0, -22)
      frame:SetPoint('LEFT', kb.sourcesbg, 'LEFT', 2, 0)
    else
      frame:ClearAllPoints()
      frame:SetPoint('TOPLEFT', lastCheckFrame, 'BOTTOMLEFT', 0, -2)
    end

    frame.header:ClearAllPoints()
    frame.header:SetPoint('LEFT', frame, 'RIGHT', 2, 0)

    lastCheckFrame = frame
  end
end

local KeyBinder_OnHide = function()
  KeyBinderImportLog:Hide()
end

local CloseButton_OnClick = function()
  kb.db.showUI = false
  kb:Hide()
end
local CancelButton_OnClick = function()
  kb.RevertBindings()
end
local SaveButton_OnClick = function()
  kb.ConfirmBindings()
end


local KeyBinder_Initialize = function()
  do
    local leftSlot, upSlot
    for index = 1, NUM_KEY_SLOTS do

      local button = CreateFrame('CheckButton', 'KeyBinderSlot'..index, kb, 'KeyButton')
      button:SetScript('OnClick', KeyButton_OnClick)
      button:SetScript('OnUpdate', KeyButton_OnUpdate)
      button:SetScript('OnDragStart', KeyButton_OnDragStart)
      button:SetScript('OnReceiveDrag', KeyButton_OnReceiveDrag)
      button:RegisterForClicks('AnyUp')


      local newRow = (mod(index, BINDS_PER_ROW) == 1)

      if index == 1 then
        button:SetPoint('TOPLEFT', kb.bg, 'TOPLEFT', BUTTON_PADDING, - BUTTON_PADDING)
        upSlot = button
      elseif newRow then
        button:SetPoint('TOPLEFT', upSlot, 'BOTTOMLEFT', 0, -BUTTON_SPACING)
        upSlot = button
      else
        button:SetPoint('TOPLEFT', leftSlot, 'TOPRIGHT', BUTTON_HSPACING, 0)
      end

      button:SetSize(KEY_BUTTON_SIZE, KEY_BUTTON_SIZE)
      button:Show()
      kb.buttons[index] = button
      leftSlot = button
    end
  end


  kb.scrollOffset = 0
  kb.tabAnchor = {'TOPLEFT', kb.profilebg, 'TOPLEFT', BUTTON_PADDING, -BUTTON_SPACING}
  kb.tabGrowth = {'TOPLEFT', nil,'TOPRIGHT', BUTTON_SPACING, 0}
  kb.tabSize = {TAB_HEIGHT, TAB_HEIGHT }
  kb.UIPanelAnchor = {'TOPLEFT', kb.sourcesbg, 'TOPLEFT', BUTTON_PADDING, -BUTTON_SPACING}
  kb.UIPanelGrowth = {'TOPLEFT', nil, 'BOTTOMLEFT', 0, -2 }
  kb.UIPanelSize = {84, 32 }
  kb.UIPanelIcon = {24, 32, 'LEFT', -12, 0}
  kb.controlsAnchor = {'BOTTOMRIGHT', kb.footer, -BUTTON_PADDING, BUTTON_PADDING }
  kb.controlsGrowth = {'BOTTOMRIGHT', nil, 'BOTTOMLEFT', -BUTTON_SPACING, 0}

  -- order of these is important
  kb:tab('KeyBinderGlobalTab',
    kb.configTitle[BINDING_TYPE_GLOBAL] .. '\n' .. kb.configDescription[BINDING_TYPE_GLOBAL], "Interface\\ICONS\\item_azereansphere", {0.15,.85,.15,.85})
  kb:tab('KeyBinderCharacterTab',
    kb.configHeaders[BINDING_TYPE_CHARACTER] .. '\n' .. kb.configDescription[BINDING_TYPE_CHARACTER], nil)
  kb:tab('KeyBinderSpecTab',
    kb.configHeaders[BINDING_TYPE_SPECIALIZATION] .. '\n' .. kb.configDescription[BINDING_TYPE_SPECIALIZATION], kb.specInfo.texture)
  KeyBinderCharacterTab.icon:SetTexCoord(0.15,.85,.15,.85)



  --portraitLayers[1] = KeyBinderCharacterTab.icon
  -- todo: find some generic icons for refresh/key input,etc

  saveButton = kb:button('KeyBinderSaveButton', 'Update', 'Reload current bindings and refresh panel.', SaveButton_OnClick)
  --restoreButton = kb:button('KeyBinderRestoreButton', 'Discard', 'Revert all changes.', CancelButton_OnClick)
  --clearButton = kb:button('KeyBinderClearButton', 'Clear Page', 'Release all buttons.', ResetButton_OnClick)

  kb:uibutton(
    'KeyBinderSpellBookButton', 'SpellBook', nil,
    function() ToggleSpellBook(BOOKTYPE_SPELL) end,
    "Interface\\BUTTONS\\UI-MicroButton-Spellbook-Up", {0, 1, .4, 1})
  kb:uibutton(
    'KeyBinderTalentFrameButton', TALENTS, SPECIALIZATION,
    function() ToggleTalentFrame() end,
    "Interface\\BUTTONS\\UI-MicroButton-Talents-Up", {0, 1, .4, 1})

  kb:uibutton(
    'KeyBinderMacroFrameButton', 'Macros', nil,
    function() if MacroFrame and MacroFrame:IsVisible() then
      HideUIPanel(MacroFrame)
    else
      ShowMacroFrame() end
    end,
    "Interface\\BUTTONS\\UI-MicroButton-Help-Up", {0, 1, .4, 1})

  kb:uibutton(
    'KeyBinderInventoryButton', 'Bags', nil,
    function() OpenAllBags() end,
    "Interface\\BUTTONS\\UI-MicroButtonCharacter-Up", {0, 1, .4, 1})

  KeyBinder_CheckButton(KeyBinderStickyMode, 'Enabled', 'Disabled', 'stickyMode', 'Keep input active after receiving a key.', function()
    if kb.saveTarget and (not kb.db.stickyMode) then
      kb.DeactivateSlot(kb.saveTarget)
    end
  end, 'Sticky:')
  KeyBinder_CheckButton(KeyBinderHoverInput, 'MouseOver', 'Click', 'hoverInput', 'Enable key input when the cursor is over a binding slot.', nil, 'Bind by:')
  KeyBinder_CheckButton(KeyBinderProtectBindings, 'Block', 'Allow', 'protectBlizKeys', 'Allow overwriting Blizzard UI bindings.', nil, 'Safety:')


  KeyBinderUnbindButton:SetScript('OnClick', function()
    if kb.saveTarget then
      kb.UnbindSlot(kb.saveTarget)
    end
    kb.ui()
  end)


  kb.info:SetPoint('TOPLEFT', kb.UIPanels[1], 'BOTTOMLEFT', 0, -BUTTON_SPACING)
  HEADER_OFFSET = kb.UIPanels[1]:GetHeight() + BUTTON_PADDING
      + kb.info:GetHeight()
  FOOTER_OFFSET = saveButton:GetHeight() + BUTTON_PADDING

  kb:SetScript('OnHide', KeyBinder_OnHide)
  kb:SetScript('OnMouseWheel', KeyBinder_OnMouseWheel)
  kb.CloseButton:SetScript('OnClick', CloseButton_OnClick)

end


--- Retrieves button at index; creates said button and instates any stored parameters


kb.ActivateSlot = function(button)
  kb.saveTarget = button
  kb:SetScript('OnKeyUp', function(self, key) KeyButton_OnKeyUp(button, key) end)
  kb:SetScript('OnKeyDown', function(self, key) KeyButton_OnKeyDown(button, key) end)
  kb:SetScript('OnMouseUp', function(self, key) KeyButton_OnKeyUp(button, key) end)
  kb.savingText:ClearAllPoints()
  kb.savingText:SetParent(button)
  kb.savingText:SetPoint('BOTTOMLEFT', button, 'TOPLEFT', 0, 0)
end

kb.DeactivateSlot = function(button)
  kb.saveTarget = nil
  kb:SetScript('OnKeyUp', nil)
  kb:SetScript('OnKeyDown', nil)
  kb:SetScript('OnMouseUp', nil)
end


--- push current information into living UI
kb.ui = function(force)
  for i, module in ipairs(kb.modules) do
    if module.ui then
      module.ui(force)
    end
  end

  if InCombatLockdown() or not kb.db.showUI then
    print('---end of refresh')
    return
  end
  if not kb.loaded then
    KeyBinder_Initialize()
    kb.loaded = true
  end
  for i, button in ipairs(kb.buttons) do
    button:SetID(i+kb.scrollOffset)
    kb.UpdateSlot(button, force)
  end


  --- Frame Sizing
  kb.profilebg:SetHeight(kb.tabSize[2] + BUTTON_PADDING * 2 + kb.profiletext:GetStringHeight())

  kb.bg:SetWidth((KEY_BUTTON_SIZE + BUTTON_HSPACING + BUTTON_SPACING) * BINDS_PER_ROW + BUTTON_PADDING*2 - BUTTON_SPACING)
  local numRows = NUM_KEY_SLOTS/BINDS_PER_ROW

  kb.bg:SetHeight((KEY_BUTTON_SIZE + BUTTON_SPACING) * numRows + BUTTON_PADDING*2 - BUTTON_SPACING)

  kb:SetHeight(kb.headerbg:GetHeight() + kb.profilebg:GetHeight() + kb.bg:GetHeight() + kb.footer:GetHeight())
  kb:SetWidth((kb.sourcesbg:GetWidth() +(BINDS_PER_ROW * (KEY_BUTTON_SIZE + BUTTON_HSPACING) + (BINDS_PER_ROW - 1) * BUTTON_SPACING + BUTTON_PADDING * 2) ))

  if kb.saveTarget then
    kb.bg:SetColorTexture(.2,.5, .2, .5)
    kb.savingText:Show()

  else
    kb.bg:SetColorTexture(unpack(BINDING_SCHEME_COLOR[kb.db.bindMode]))
    kb.savingText:Hide()
  end

  for i, tab in ipairs(kb.tabButtons) do
    local border = tab:GetNormalTexture()
    local tabTexture = "Interface\\Buttons\\UI-Quickslot2"
    local left, top, right, bottom = -12, 12, 13, -13
    if i == kb.db.bindMode then
      tabTexture = "Interface\\Buttons\\CheckButtonGlow"
      left, top, right, bottom = -14, 14, 15, -15
      tab.icon:SetDesaturated(false)
      if tab.icon2 then tab.icon2:SetDesaturated(false) end
      border:SetDesaturated(true)
      border:SetVertexColor(1,1,1, 1)
    else
      tab.icon:SetDesaturated(true)
      if tab.icon2 then tab.icon2:SetDesaturated(true) end
      border:SetDesaturated(false)
      border:SetVertexColor(1,1,1)
    end
    border:SetTexture(tabTexture)
    border:SetPoint('TOPLEFT', tab, 'TOPLEFT', left, top)
    border:SetPoint('BOTTOMRIGHT', tab, 'BOTTOMRIGHT', right, bottom)
  end

  KeyBinderSpecTab.icon:SetTexture(kb.specInfo.texture)
  SetPortraitTexture(KeyBinderCharacterTab.icon, 'player')

  kb.profiletext:SetText(kb.configHeaders[kb.db.bindMode])
  print(kb.db.bindMode, kb.configHeaders[kb.db.bindMode], kb:GetSize())
  print(kb:GetPoint(1))

  kb:Show()

  if kb.saveTarget then
    KeyBinderUnbindButton:SetParent(kb.saveTarget)
    KeyBinderUnbindButton:SetPoint('TOPLEFT', kb.saveTarget, 'BOTTOMLEFT', 0, -1)
    KeyBinderUnbindButton:Show()
  else
    KeyBinderUnbindButton:Hide()
  end

  -- Reset this so talent cache can be rebuilt
  kb.talentsPushed = nil
end

--- Associate processed input with the given slot's metadata
kb.SaveSlot = function(self, key)

  if not self.command then
    return
  end
  if InCombatLockdown() then
    kb:print(L('Bindings cannot be changed during combat.'))
    return
  end


  print('|cFFFFFF00received|cFFFFFF00', self:GetID(), '|cFF00FFFF', key)

  local modifier = ''
  if IsAltKeyDown() then
    modifier = 'ALT-'
  end
  if IsControlKeyDown() then
    modifier = modifier.. 'CTRL-'
  end
  if IsShiftKeyDown() then
    modifier = modifier..'SHIFT-'
  end
  local binding = modifier..key

  -- check for system bindings
  --bprint('|cFFFFFF00SaveBind|r', 'protectKeys', kb.db.protectBlizKeys)
  if kb.db.protectBlizKeys and kb.SystemBindings[binding] then
    kb.statustext:SetText(L('BINDING_FAILED_PROTECTED', binding, kb.SystemBindings[binding]))
    kb.bindingstext:SetText(nil)
    return false
  end

  -- check for other keys
  local previousCommand = GetBindingAction(binding)
  if previousCommand ~= "" and previousCommand ~= self.command then
    local actionType, actionID, name = kb.GetCommandAction(previousCommand)
    if actionType then
      local keys = {GetBindingKey(previousCommand) }
      local  i = 1
      while keys[i] do
        if keys[i] == binding then
          tremove(keys, i)
          kb.UpdateBindingsCache(actionType, actionID, keys)
          break
        end
        i = i + 1
      end
    end
  end

  local currentHotKeys = {GetBindingKey(self.command)}
  local found
  for i, key in ipairs(currentHotKeys) do
    if key == binding then
      found = true
      print('|cFFFF4400key already bound to this')
      return true
    end
  end
  if not found then
    tinsert(currentHotKeys, 1, binding)
    kb.UpdateBindingsCache(self.actionType, self.actionID, currentHotKeys)
  end

  -- scour profile data for any conflicting binds
  local currentAction = GetBindingAction(binding)
  if match(currentAction, 'KeyBinder') then
    if currentAction ~= self.command then
      print('|cFFFF4400removing bindings for:', currentAction)
      for profileID, profileData in ipairs(kb.loadedProfiles) do
        local buttonID = profileData.commands[currentAction]
        if buttonID then
          local buttonAction = profileData.buttons[buttonID][2]
          if buttonAction then
            local talentInfo = profileData.talents[buttonAction]
            if talentInfo and GetSpellInfo(buttonAction) then
              for i = #talentInfo, 5, -1  do
                if binding == talentInfo[i] then
                  tremove(talentInfo, i)
                end
              end
              kb:print(L('Overwrote talent |cFF88FF00%s|r in |cFF00FFFF%s|r', buttonAction, kb.configHeaders[profileID]))
            else

              kb:print(L('Overwrote |cFFFFFF00%s|r in |cFF00FFFF%s|r', buttonAction, kb.configHeaders[profileID]))
            end
            profileData.bindings[binding] = nil
          end
        end
      end
    end
  end


  print('SetBinding', binding, self.command)
  SetBinding(binding, self.command)
  SaveBindings(GetCurrentBindingSet())
  self.binding = binding

  local talentName = self.actionName
  if self.actionType == 'macro' then
    talentName = GetMacroSpell(self.actionID)
  end

  local talentInfo
  if talentName and kb.TalentCache[talentName] then
    print('store dynamicType talent')
    talentInfo = {self.macroName, self.actionName, self.actionType, self.actionID}
    local bindings = {GetBindingKey(self.command) }
    for i, key in ipairs(bindings) do
      tinsert(talentInfo, key)
    end
  end

  for level, profile in ipairs(kb.orderedProfiles) do
    if (level == kb.db.bindMode) then
      profile.bound[self.command] = true
      if talentInfo then
        profile.bindings[self.binding] = nil
      else
        profile.bindings[self.binding] = self.command
      end
      if talentName then
        profile.talents[talentName] = talentInfo
      end
    else
      profile.bindings[self.binding] = nil
      profile.bound[self.command] = nil
      if talentName then
        profile.talents[talentName] = nil
      end
    end
  end


  kb:print(L('BINDING_ASSIGNED', self.binding, self.actionName, kb.currentHeader))
  kb.ui()
  return true
end


kb.UnbindSlot = function(self)

  local keys = {GetBindingKey(self.command) }
  if #keys >= 1 then
    kb.UpdateBindingsCache(self.actionType, self.actionID, {})
  end

  local talentName = self.actionName
  if self.actionType == 'macro' then
    local spellName, _, spellID = GetMacroSpell(self.actionID)
    talentName = spellName
  end


  --print('detected', #keys, 'bindings')
  for i, key in pairs(keys) do
    --print('clearing', key)
    SetBinding(key, nil)
    SaveBindings(GetCurrentBindingSet())
    if kb.currentProfile.bindings[key] then
      --kb:print(L('BINDING_REMOVED', self.actionName, kb.currentHeader))
      kb.currentProfile.bindings[key] = nil
    end
    if kb.currentProfile.talents[talentName] then
      kb.currentProfile.talents[talentName] = nil
    end

    kb.bindings[tostring(self.actionType)..'_'..tostring(self.actionID)] = nil
  end
  if kb.currentProfile.bound[self.command] then
    kb.currentProfile.bound[self.command] = nil
    --kb:print(BINDING_REMOVED:format(self.actionName, configHeaders[db.bindMode]))
  end


  self.active = false
  kb.UpdateSlot(self, true)
end

kb.AcceptAssignment = function(self, ...)
  local popup = StaticPopupDialogs["SKELETONKEY_CONFIRM_ASSIGN_SLOT"]
  local source = kb.  loadedProfiles[popup.oldProfile]
  kb.SetSlot(popup.slot, unpack(popup.args))
  kb.UpdateSlot(popup.slot)
  kb:SetScript('OnMouseWheel', KeyBinder_OnMouseWheel) -- re-enable scrolling
  ClearCursor()
  ResetCursor()
end

--- Add to blizzard interfaces
StaticPopupDialogs["SKELETONKEY_CONFIRM_ASSIGN_SLOT"] = {
  text = "Confirm moving an assigned command.",
  button1 = OKAY,
  button2 = CANCEL,
  timeout = 0,
  whileDead = 1,
  showAlert = 1,
  OnAccept = kb.AcceptAssignment,
  OnCancel = function() kb:SetScript('OnMouseWheel', KeyBinder_OnMouseWheel) end
}