diff options.lua @ 104:04198c8d0717

Don't set a default keybinding, but rather change the associated option to not be clunky and gross.
author Farmbuyer of US-Kilrogg <farmbuyer@gmail.com>
date Sun, 05 Aug 2012 16:53:07 +0000
parents dc8a23a47b03
children 646c9b41aaed
line wrap: on
line diff
--- a/options.lua	Sun Aug 05 07:26:06 2012 +0000
+++ b/options.lua	Sun Aug 05 16:53:07 2012 +0000
@@ -183,8 +183,9 @@
 		local pair = AceGUI:Create("InlineGroup")
 		pair:SetLayout("List")
 		pair:SetRelativeWidth(0.49)
-		pair:SetTitle("Keybinding for '/ouroloot'")
-		local editbox, checkbox
+		pair:SetTitle('Keybinding for "/ouroloot toggle"')
+		local checkbox, button
+		--[=[
 		editbox = mkbutton("EditBox", nil, opts.keybinding_text,
 			[[Keybinding text format is fragile!  (All caps, ALT then CTRL then SHIFT.)  Relog to take effect.]])
 		editbox:SetFullWidth(true)
@@ -193,15 +194,42 @@
 			opts.keybinding_text = value
 		end)
 		editbox:SetDisabled(not opts.keybinding)
+		]=]
 		checkbox = mktoggle('keybinding', "Register keybinding", 1,
-			[[Register a keybinding to toggle the loot display.  Relog to take effect.]],
+			[[Whether to register a keybinding to toggle the loot display.  Relog to take effect.]],
 			function (_w,_,value)
 				opts.keybinding = value
-				editbox:SetDisabled(not opts.keybinding)
+				--editbox:SetDisabled(not opts.keybinding)
+				button:SetDisabled(not opts.keybinding)
 			end)
 		checkbox:SetFullWidth(true)
-		pair:AddChild(checkbox)
-		pair:AddChild(editbox)
+		button = mkbutton("Keybinding", nil, "",
+			-- This wording is not quite accurate, but auto-l10n is nice.
+			_G.BIND_KEY_TO_COMMAND:format([['/ouroloot toggle']]))
+		button:SetFullWidth(true)
+		--button:SetLabel("this is label text")
+		button:SetKey(opts.keybinding_text)
+		button.msgframe:SetToplevel(true) -- XXX ace3 ticket #305
+		button:SetCallback("OnKeyChanged", function(_b,event,value)
+			local possible_prev = opts.keybinding_text
+			opts.keybinding_text = value
+			-- If they were already binding something at login, try updating.
+			if not _G.OuroLootBindingOpen then return end
+			if possible_prev and #possible_prev > 0 then
+				addon:Print("Trying to unbind previous %s key.", possible_prev)
+				SetBinding (possible_prev, nil)
+			end
+			if value and #value > 0 then
+				addon:Print("Trying to bind new %s key.", value)
+				if SetBindingClick (value, "OuroLootBindingOpen") then
+					local c = GetCurrentBindingSet()
+					if c == ACCOUNT_BINDINGS or c == CHARACTER_BINDINGS then
+						SaveBindings(c)
+					end
+				end
+			end
+		end)
+		pair:AddChildren (checkbox, button)--, editbox)
 		container:AddChild(pair)
 	end