Quantcast

Add macro creation and bind deletion

James Whitehead II [10-05-10 - 20:34]
Add macro creation and bind deletion
Filename
BindConfig.lua
Clique.lua
Clique.toc
Clique.xml
diff --git a/BindConfig.lua b/BindConfig.lua
index 60fcd42..285bf75 100755
--- a/BindConfig.lua
+++ b/BindConfig.lua
@@ -139,7 +139,9 @@ function CliqueConfig:Spellbook_OnBinding(button, key)
     local texture = GetSpellBookItemTexture(slot, SpellBookFrame.bookType)

     local key = addon:GetCapturedKey(key)
-    assert(key, "Unable to get binding information: " .. tostring(key))
+    if not key then
+        return
+    end

     local succ, err = addon:AddBinding{
         key = key,
@@ -168,27 +170,34 @@ function CliqueConfig:Button_OnClick(button)
         local menu = {
             {
                 text = L["Select a binding type"],
-                isTitle = true
+                isTitle = true,
+                notCheckable = true,
             },
             {
                 text = L["Target clicked unit"],
                 func = function()
                     self:SetupCaptureDialog("target")
                 end,
+                notCheckable = true,
             },
             {
                 text = L["Open unit menu"],
                 func = function()
                     self:SetupCaptureDialog("menu")
                 end,
+                notCheckable = true,
             },
             {
                 text = L["Run custom macro"],
                 func = function()
                     config.page1:Hide()
                     config.page2.bindType = "macro"
+                    -- Clear out the entries
+                    config.page2.bindText:SetText("")
+                    config.page2.editbox:SetText("")
                     config.page2:Show()
                 end,
+                notCheckable = true,
             },
         }
         UIDropDownMenu_SetAnchor(self.dropdown, 0, 0, "BOTTOMLEFT", self.page1.button_other, "TOP")
@@ -252,7 +261,8 @@ compareFunctions = {
     end,
 }

-CliqueConfig.binds = {}
+-- Mapping between binding entry and index in profile
+local bindMap = {}
 function CliqueConfig:UpdateList()
     local page = self.page1
     local binds = Clique.profile.binds
@@ -264,7 +274,8 @@ function CliqueConfig:UpdateList()

     -- Sort the bindings
     local sort = {}
-    for uid, entry in pairs(binds) do
+    for idx, entry in pairs(binds) do
+        bindMap[entry] = idx
         sort[#sort + 1] = entry
     end

@@ -306,6 +317,7 @@ function CliqueConfig:UpdateList()
             row.name:SetText(addon:GetBindingActionText(bind))
             --row.type:SetText(bind.type)
             row.bind:SetText(addon:GetBindingKeyComboText(bind))
+            row.bindIndex = bindMap[bind]
             row:Show()
         else
             row:Hide()
@@ -368,3 +380,27 @@ function CliqueConfig:AcceptSetBinding()
     end
     dialog:Hide()
 end
+
+function CliqueConfig:Row_OnClick(frame, button)
+    local menu = {
+        {
+            text = L["Change binding"],
+            func = function()
+                -- Do nothing right now
+                -- self:SetupCaptureDialog("target")
+            end,
+            notCheckable = true,
+        },
+        {
+            text = L["Delete binding"],
+            func = function()
+                local bindIndex = frame.bindIndex
+                table.remove(Clique.profile.binds, bindIndex)
+                self:UpdateList()
+            end,
+            notCheckable = true,
+        },
+    }
+    EasyMenu(menu, self.dropdown, "cursor", 0, 0, nil, nil)
+end
+
diff --git a/Clique.lua b/Clique.lua
index e36a5c1..a9bf0d9 100755
--- a/Clique.lua
+++ b/Clique.lua
@@ -121,16 +121,26 @@ end

 function addon:InitializeDatabase()
     -- TODO: This is all testing boilerplate, try to fix it up
-    self.profile = {
-        binds = {
-            [1] = {key = "BUTTON1", type = "target", unit = "mouseover"},
-            [2] = {key = "BUTTON2", type = "menu"},
-            [3] = {key = "F", type = "spell", spell = "Lifebloom"},
-            [4] = {key = "SHIFT-F", type = "spell", spell = "Regrowth"},
-            [5] = {key = "CTRL-BUTTON1", type = "spell", spell = "Rejuvenation"},
-            [6] = {key = "SHIFT-BUTTON1", type = "spell", spell = "Regrowth"},
-        },
-    }
+    local reset = false
+    if not CliqueDB then
+        reset = true
+    elseif type(CliqueDB) == "table" and not CliqueDB.dbversion then
+        reset = true
+    elseif type(CliqueDB) == "table" and CliqueDB.dbversion == 2 then
+        reset = false
+    end
+
+    if reset then
+        CliqueDB = {
+            binds = {
+                [1] = {key = "BUTTON1", type = "target", unit = "mouseover"},
+                [2] = {key = "BUTTON2", type = "menu"},
+            },
+            dbversion = 2,
+        }
+    end
+
+    self.profile = CliqueDB
 end

 function ATTR(prefix, attr, suffix, value)
diff --git a/Clique.toc b/Clique.toc
index 0942c8c..c78b7db 100755
--- a/Clique.toc
+++ b/Clique.toc
@@ -4,7 +4,6 @@
 ## Version: @project-version@
 ## Notes: Simply powerful click-casting interface
 ## SavedVariables: CliqueDB
-## OptionalDeps: Dongle

 AddonCore.lua
 Localization.enUS.lua
diff --git a/Clique.xml b/Clique.xml
index 7988e6c..fb256ae 100755
--- a/Clique.xml
+++ b/Clique.xml
@@ -53,6 +53,12 @@
             </Layer>
         </Layers>
         <Scripts>
+            <OnLoad>
+                self:RegisterForClicks("RightButtonDown")
+            </OnLoad>
+            <OnClick>
+                CliqueConfig:Row_OnClick(self, button)
+            </OnClick>
             <OnMouseWheel>
                 local slider = CliqueConfig.page1.slider
                 slider:SetValue(slider:GetValue() - delta)
@@ -152,9 +158,11 @@
                     </OnMouseDown>
                     <OnMouseUp>
                         self:GetParent():StopMovingOrSizing()
+                        self:SetUserPlaced(false)
                     </OnMouseUp>
                     <OnHide>
                         self:GetParent():StopMovingOrSizing()
+                        self:SetUserPlaced(false)
                     </OnHide>
                 </Scripts>
             </Button>