From 58fd8805e3a3fca98fe9cf5d055f22a3cce6c016 Mon Sep 17 00:00:00 2001 From: James Whitehead II Date: Sat, 2 Oct 2010 14:14:23 +0100 Subject: [PATCH] Make columns clickable to sort by action text or binding --- Clique.xml | 1 + CliqueOptions.lua | 30 ++++++++++++++++++++++++++++-- CliqueUtils.lua | 5 +++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/Clique.xml b/Clique.xml index 1e83fd3..ad3ee54 100755 --- a/Clique.xml +++ b/Clique.xml @@ -79,6 +79,7 @@ PlaySound("igMainMenuOptionCheckBoxOn"); + CliqueConfig:Column_OnClick(self, button) diff --git a/CliqueOptions.lua b/CliqueOptions.lua index 332752f..143278e 100755 --- a/CliqueOptions.lua +++ b/CliqueOptions.lua @@ -36,12 +36,22 @@ function CliqueConfig:SetupGUI() self.page1.column1:SetText(L["Action"]) self.page1.column2:SetText(L["Binding"]) + -- Set columns up to handle sorting + self.page1.column1.sortType = "name" + self.page1.column2.sortType = "key" + self.page1.sortType = self.page1.column2.sortType + self.button_add:SetText(L["Add binding"]) self.button_edit:SetText(L["Edit"]) self.page1:Show() end +function CliqueConfig:Column_OnClick(frame, button) + self.page1.sortType = frame.sortType + self:UpdateList() +end + function CliqueConfig:HijackSpellbook() self.spellbookButtons = {} @@ -172,7 +182,18 @@ end}) local compareFunctions = { name = function(a, b) - return a.binding < b.binding + local texta = addon:GetBindingActionText(a) + local textb = addon:GetBindingActionText(b) + return texta < textb + end, + key = function(a, b) + local keya = addon:GetBindingKey(a) + local keyb = addon:GetBindingKey(b) + if keya == keyb then + return memoizeBindings[a] < memoizeBindings[b] + else + return keya < keyb + end end, binding = function(a, b) local mem = memoizeBindings @@ -195,7 +216,12 @@ function CliqueConfig:UpdateList() for uid, entry in pairs(binds) do sort[#sort + 1] = entry end - table.sort(sort, compareFunctions.binding) + + if page.sortType then + table.sort(sort, compareFunctions[page.sortType]) + else + table.sort(sort, compareFunctions.key) + end -- Enable or disable the scroll bar if #sort > MAX_ROWS - 1 then diff --git a/CliqueUtils.lua b/CliqueUtils.lua index cd43a6b..775dc3c 100644 --- a/CliqueUtils.lua +++ b/CliqueUtils.lua @@ -110,6 +110,11 @@ function addon:GetBindingActionText(binding) end end +function addon:GetBindingKey(binding) + local key = binding.key:match("[^%-]+$") + return key +end + local binMap = { ALT = 1, LALT = 2, -- 1.7.9.5