Quantcast

Add key bindings option. (off by default.)

Eyal Shilony [10-20-14 - 10:38]
Add key bindings option. (off by default.)

Wrapped all of the function calls in EasyDisplay lib
so when 3rd-party addons hook Blizzard's API
it will call to the latest version that is
the modified (hooked) function rather than the original function.
Filename
Core.lua
Menu.lua
libs/EasyDisplay.lua
loc/enUS.lua
options/Accessibility.lua
options/General.lua
options/Menu.lua
diff --git a/Core.lua b/Core.lua
index 1537b45..0806536 100644
--- a/Core.lua
+++ b/Core.lua
@@ -36,6 +36,7 @@ local defaults = {
 		hideLogoutButtons = true,
 		hideReloadUIButton = false,
 		hideOptionsButton = false,
+		hideKeyBindings = true,
 		menu = {
 			character = 1,
 			spellbook = 2,
@@ -82,20 +83,6 @@ addon.modifiers = {
 	ALT_KEY
 }

-addon.secureItems = {
-	["spellbook"] = true,
-	["talents"] = true,
-	--["achievements"] = true,
-	--["questlog"] = true,
-	["lfd"] = true,
-	["collections"] = true,
-	["journal"] = true,
-	["guild"] = true,
-	--["help"] = true,
-	["interface"] = true,
-	["options"] = true
-}
-
 core:SetOnUpdate(function(self, elapsed)
 	if addon:IsMenuVisible() or not addon.tooltip then
 		return
@@ -115,6 +102,7 @@ end)
 function core:OnInitialize()
 	self:RegisterEvent("PLAYER_REGEN_ENABLED")
 	self:RegisterEvent("PLAYER_REGEN_DISABLED")
+	self:RegisterEvent("UPDATE_BINDINGS")

 	addon.db = LibStub("AceDB-3.0"):New("Broker_StartMenuDb", defaults, true)

@@ -169,3 +157,7 @@ function core:PLAYER_REGEN_DISABLED()
 	addon.dataobj.text = "|cffff0000In combat|r"
 	addon:UpdateMenu()
 end
+
+function core:UPDATE_BINDINGS()
+	addon:UpdateMenu()
+end
diff --git a/Menu.lua b/Menu.lua
index 8a39465..6040dc7 100644
--- a/Menu.lua
+++ b/Menu.lua
@@ -37,6 +37,17 @@ dropdown.initialize = function(self, level)
 	end
 end

+local function getMenuText(text, command)
+	if not addon.db.profile.hideKeyBindings and command and GetBindingKey(command) then
+		-- We cannot inline this because GetBindingKey may return more than one binding for a single command,
+		--	and so when it returns more than one it messes up GetBindingText and we only need the first one.
+		local binding = GetBindingKey(command)
+		return text .. " (|cff82c5ff" .. GetBindingText(binding) .. FONT_COLOR_CODE_CLOSE .. ")";
+	else
+		return text;
+	end
+end
+
 local function insertItem(name, order)
 	local interface = addon.display:GetInterface(name)
 	if interface and order > 0 then
@@ -45,13 +56,13 @@ local function insertItem(name, order)
 		local entry = {
 			order = order,
 			name = name,
-			text = interface.title,
+			text = getMenuText(interface.title, interface.command),
 			icon = interface.icon,
 			notCheckable = 1,
-			disabled = inCombat and addon.secureItems[interface.name]
+			disabled = inCombat and interface.secure
 		}

-		if not inCombat and interface.button and addon.secureItems[interface.name] then
+		if not inCombat and interface.button and interface.secure then
 			entry.attributes = {
 				["type"] = "click",
 				["clickbutton"] = interface.button,
diff --git a/libs/EasyDisplay.lua b/libs/EasyDisplay.lua
index 3e2b1dc..0d92667 100644
--- a/libs/EasyDisplay.lua
+++ b/libs/EasyDisplay.lua
@@ -25,7 +25,7 @@

 assert(LibStub, "EasyDisplay-1.0 requires LibStub")

-local lib, minor = LibStub:NewLibrary("EasyDisplay-1.0", 10)
+local lib, minor = LibStub:NewLibrary("EasyDisplay-1.0", 11)
 if not lib then return end
 minor = minor or 0

@@ -75,78 +75,66 @@ LoD_AddonFrames = {
 	level - (number) The minimum level of the player required to display the interface.
 	func - (function) The function (handler) to display the interface.
 	special - (boolean) Requires special handling before it can be displayed so it's recommended to use the DisplayInterface api to show the interface.
+	secure - (boolean) Determines whether it needs to be opened from a secure context.
+	command - (string) The name of the command for key bindings.
 ]]
 local interfaces = {
 	{
-		name = "character",
-		title = CHARACTER_BUTTON,
-		alias = "char",
-		frameName = "CharacterFrame",
-		--button = CharacterMicroButton,
-		func = function() ToggleCharacter("PaperDollFrame") end,
-	},
-	{
-		name = "spellbook",
-		title = SPELLBOOK_ABILITIES_BUTTON,
-		alias = "sb",
-		frameName = "SpellBookFrame",
-		button = SpellbookMicroButton,
-		func = function() ToggleFrame(SpellBookFrame) end,
-	},
-	{
-		name = "talents",
-		title = TALENTS_BUTTON,
-		alias = "tal",
-		frameName = "PlayerTalentFrame",
-		level = SHOW_TALENT_LEVEL,
-		button = TalentMicroButton,
-		func = ToggleTalentFrame,
-	},
-	{
 		name = "achievements",
 		title = ACHIEVEMENT_BUTTON,
 		alias = "achi",
 		frameName = "AchievementFrame",
 		button = AchievementMicroButton,
-		func = ToggleAchievementFrame,
+		command = "TOGGLEACHIEVEMENT",
+		func = function() ToggleAchievementFrame() end,
 	},
 	{
-		name = "calendar",
-		title = CALENDAR,
-		alias = "cal",
-		frameName = "CalendarFrame",
-		func = ToggleCalendar,
+		name = "addons",
+		title = ADDONS,
+		frameName = "AddonList",
+		special = true,
+		func = function()
+			if not AddonList:IsVisible() then
+				ShowUIPanel(AddonList)
+				AddonList.hideMenu = true
+			else
+				HideUIPanel(AddonList)
+			end
+		end,
 	},
 	{
-		name = "questlog",
-		title = QUESTLOG_BUTTON,
-		alias = "ql",
-		frameName = "QuestLogFrame",
-		button = QuestLogMicroButton,
-		func = ToggleQuestLog,
+		name = "backpack",
+		title = BACKPACK_TOOLTIP,
+		command = "TOGGLEBACKPACK",
+		func = function()
+			if IsModifierKeyDown() then
+				ToggleAllBags()
+			else
+				ToggleBackpack()
+			end
+		end,
 	},
 	{
-		name = "pvp",
-		title = PLAYER_V_PLAYER,
-		frameName = "PVPFrame",
-		level = SHOW_PVP_LEVEL,
-		--button = PVPMicroButton,
-		func = TogglePVPUI,
+		name = "bags",
+		title = BAGS,
+		command = "OPENALLBAGS",
+		func = function() ToggleAllBags() end,
 	},
 	{
-		name = "lfd",
-		title = DUNGEONS_BUTTON,
-		frameName = "LFDParentFrame",
-		level = SHOW_LFD_LEVEL,
-		button = LFDMicroButton,
-		func = ToggleLFDParentFrame,
+		name = "calendar",
+		title = CALENDAR,
+		alias = "cal",
+		frameName = "CalendarFrame",
+		func = function() ToggleCalendar() end,
 	},
 	{
-		name = "lfr",
-		title = RAID_FINDER,
-		frameName = "LFRParentFrame",
-		level = SHOW_LFD_LEVEL,
-		func = ToggleRaidFrame,
+		name = "character",
+		title = CHARACTER_BUTTON,
+		alias = "char",
+		frameName = "CharacterFrame",
+		--button = CharacterMicroButton,
+		command = "TOGGLECHARACTER0",
+		func = function() ToggleCharacter("PaperDollFrame") end,
 	},
 	{
 		name = "collections",
@@ -154,91 +142,31 @@ local interfaces = {
 		alias = "pets",
 		frameName = "PetJournalParent",
 		button = CompanionsMicroButton,
-		func = TogglePetJournal,
-	},
-	{
-		name = "journal",
-		title = ENCOUNTER_JOURNAL,
-		frameName = "EncounterJournal",
-		level = SHOW_LFD_LEVEL,
-		button = EJMicroButton,
-		func = ToggleEncounterJournal,
+		secure = true,
+		command = "TOGGLECOLLECTIONS",
+		func = function() TogglePetJournal() end,
 	},
 	{
 		name = "guild",
-		title = GUILD,
+		title = LOOKINGFORGUILD,
 		frameName = "GuildFrame",
 		button = GuildMicroButton,
-		func = ToggleGuildFrame,
-	},
-	{
-		name = "backpack",
-		title = BACKPACK_TOOLTIP,
-		func = function()
-			if IsModifierKeyDown() then
-				ToggleAllBags()
-			else
-				ToggleBackpack()
-			end
-		end,
-	},
-	{
-		name = "bags",
-		title = BAGS,
-		func = ToggleAllBags,
-	},
-	{
-		name = "time",
-		title = TIMEMANAGER_TITLE,
-		frameName = "TimeManagerFrame",
-		func = ToggleTimeManager,
+		secure = true,
+		command = "TOGGLEGUILDTAB",
+		func = function() ToggleGuildFrame() end,
 	},
 	{
 		name = "help",
 		title = HELP_BUTTON,
 		frameName = "HelpFrame",
 		button = HelpMicroButton,
-		func = ToggleHelpFrame,
-	},
-	{
-		name = "shops",
-		title = BLIZZARD_STORE,
-		func = ToggleStoreUI,
-	},
-	{
-		name = "whatsnew",
-		title = GAMEMENU_NEW_BUTTON,
-		special = true,
-		func = SplashFrame_Open,
-	},
-	{
-		name = "social",
-		title = SOCIAL_BUTTON,
-		alias = "soc",
-		frameName = "FriendsFrame",
-		special = true,
-		func = ToggleFriendsFrame,
-	},
-	{
-		name = "options",
-		title = SYSTEMOPTIONS_MENU,
-		alias = "system",
-		frameName = "VideoOptionsFrame",
-		special = true,
-		func = function()
-			if not VideoOptionsFrame:IsVisible() then
-				ShowUIPanel(VideoOptionsFrame)
-				VideoOptionsFrame.lastFrame = GameMenuFrame
-				VideoOptionsFrame.hideMenu = true
-			else
-				HideUIPanel(VideoOptionsFrame)
-			end
-		end,
+		func = function() ToggleHelpFrame() end,
 	},
 	{
 		name = "interface",
 		title = UIOPTIONS_MENU,
 		frameName = "InterfaceOptionsFrame",
+		secure = true,
 		special = true,
 		func = function()
 			if not InterfaceOptionsFrame:IsVisible() then
@@ -251,18 +179,14 @@ local interfaces = {
 		end,
 	},
 	{
-		name = "mac",
-		title = MAC_OPTIONS,
-		frameName = "MacOptionsFrame",
-		special = true,
-		func = function()
-			if not MacOptionsFrame:IsVisible() then
-				ShowUIPanel(MacOptionsFrame)
-				MacOptionsFrame.hideMenu = true
-			else
-				HideUIPanel(MacOptionsFrame)
-			end
-		end,
+		name = "journal",
+		title = ENCOUNTER_JOURNAL,
+		frameName = "EncounterJournal",
+		level = SHOW_LFD_LEVEL,
+		button = EJMicroButton,
+		secure = true,
+		command = "TOGGLEENCOUNTERJOURNAL",
+		func = function() ToggleEncounterJournal() end,
 	},
 	{
 		name = "keybindings",
@@ -280,29 +204,46 @@ local interfaces = {
 		end,
 	},
 	{
-		name = "macro",
-		title = MACROS,
-		frameName = "MacroFrame",
+		name = "lfd",
+		title = DUNGEONS_BUTTON,
+		frameName = "LFDParentFrame",
+		level = SHOW_LFD_LEVEL,
+		button = LFDMicroButton,
+		secure = true,
+		command = "TOGGLEGROUPFINDER",
+		func = function() ToggleLFDParentFrame() end,
+	},
+	{
+		name = "lfr",
+		title = RAID_FINDER,
+		frameName = "LFRParentFrame",
+		level = SHOW_LFD_LEVEL,
+		func = function() ToggleRaidFrame() end,
+	},
+	{
+		name = "mac",
+		title = MAC_OPTIONS,
+		frameName = "MacOptionsFrame",
 		special = true,
 		func = function()
-			if not MacroFrame:IsVisible() then
-				ShowUIPanel(MacroFrame)
+			if not MacOptionsFrame:IsVisible() then
+				ShowUIPanel(MacOptionsFrame)
+				MacOptionsFrame.hideMenu = true
 			else
-				HideUIPanel(MacroFrame)
+				HideUIPanel(MacOptionsFrame)
 			end
 		end,
 	},
 	{
-		name = "addons",
-		title = ADDONS,
-		frameName = "AddonList",
+		name = "macro",
+		title = MACROS,
+		frameName = "MacroFrame",
 		special = true,
-		func = function()
-			if not AddonList:IsVisible() then
-				ShowUIPanel(AddonList)
-				AddonList.hideMenu = true
+		func = function()
+			if not MacroFrame:IsVisible() then
+				ShowUIPanel(MacroFrame)
 			else
-				HideUIPanel(AddonList)
+				HideUIPanel(MacroFrame)
 			end
 		end,
 	},
@@ -312,6 +253,7 @@ local interfaces = {
 		alias = "menu",
 		frameName = "GameMenuFrame",
 		--button = MainMenuMicroButton,
+		command = "TOGGLEGAMEMENU",
 		func = function()
             -- Calling ToggleGameMenu() causes the UI to taint.
 			if not GameMenuFrame:IsShown() then
@@ -330,6 +272,86 @@ local interfaces = {
 			end
 		end,
 	},
+	{
+		name = "options",
+		title = SYSTEMOPTIONS_MENU,
+		alias = "system",
+		frameName = "VideoOptionsFrame",
+		secure = true,
+		special = true,
+		func = function()
+			if not VideoOptionsFrame:IsVisible() then
+				ShowUIPanel(VideoOptionsFrame)
+				VideoOptionsFrame.lastFrame = GameMenuFrame
+				VideoOptionsFrame.hideMenu = true
+			else
+				HideUIPanel(VideoOptionsFrame)
+			end
+		end,
+	},
+	{
+		name = "pvp",
+		title = PLAYER_V_PLAYER,
+		frameName = "PVPFrame",
+		level = SHOW_PVP_LEVEL,
+		--button = PVPMicroButton,
+		func = function() TogglePVPUI() end,
+	},
+	{
+		name = "questlog",
+		title = QUESTLOG_BUTTON,
+		alias = "ql",
+		frameName = "QuestLogFrame",
+		button = QuestLogMicroButton,
+		command = "TOGGLEQUESTLOG",
+		func = function() ToggleQuestLog() end,
+	},
+	{
+		name = "shops",
+		title = BLIZZARD_STORE,
+		func = function() ToggleStoreUI() end,
+	},
+	{
+		name = "social",
+		title = SOCIAL_BUTTON,
+		alias = "soc",
+		frameName = "FriendsFrame",
+		special = true,
+		func = function() ToggleFriendsFrame() end,
+	},
+	{
+		name = "spellbook",
+		title = SPELLBOOK_ABILITIES_BUTTON,
+		alias = "sb",
+		frameName = "SpellBookFrame",
+		button = SpellbookMicroButton,
+		secure = true,
+		command = "TOGGLESPELLBOOK",
+		func = function() ToggleFrame(SpellBookFrame) end,
+	},
+	{
+		name = "talents",
+		title = TALENTS_BUTTON,
+		alias = "tal",
+		frameName = "PlayerTalentFrame",
+		level = SHOW_TALENT_LEVEL,
+		button = TalentMicroButton,
+		secure = true,
+		command = "TOGGLETALENTS",
+		func = function() ToggleTalentFrame() end,
+	},
+	{
+		name = "time",
+		title = TIMEMANAGER_TITLE,
+		frameName = "TimeManagerFrame",
+		func = function() ToggleTimeManager() end,
+	},
+	{
+		name = "whatsnew",
+		title = GAMEMENU_NEW_BUTTON,
+		special = true,
+		func = function() SplashFrame_Open() end,
+	}
 }

 -- if we're not using a mac client, remove the interface from the table.
@@ -342,7 +364,7 @@ if IsMacClient() ~= 1 then
 	end
 end

--- We need to show addons only when we have more than one addon available.
+-- We need to show addons only when we have at least one addon available.
 if GetNumAddOns() <= 0 then
 	for i, v in ipairs(interfaces) do
 		if v.name == "addons" then
diff --git a/loc/enUS.lua b/loc/enUS.lua
index f3dda79..a19198f 100644
--- a/loc/enUS.lua
+++ b/loc/enUS.lua
@@ -31,6 +31,7 @@ L["Block the menu in combat"] = true
 L["Hide the logout and exit items from the menu"] = true
 L["Hide the reload item from the menu"] = true
 L["Hide the options item from the menu"] = true
+L["Hide key bindings from the menu"] = true

 L["Tooltip"] = true
 L["Hide tooltip"] = true
diff --git a/options/Accessibility.lua b/options/Accessibility.lua
index f9d3aed..8efc76e 100644
--- a/options/Accessibility.lua
+++ b/options/Accessibility.lua
@@ -32,7 +32,7 @@ function options:OnInitialize()

 	local titles = {}
 	for _, interface in addon.display:Interfaces() do
-		if not addon.secureItems[interface.name] then
+		if not interface.secure then
 			table.insert(titles, interface.title)
 		end
 	end
diff --git a/options/General.lua b/options/General.lua
index f4dad55..e452fc0 100644
--- a/options/General.lua
+++ b/options/General.lua
@@ -49,7 +49,7 @@ function options:OnInitialize()
 			end,
 			set = function()
 				addon.db.profile.hideLogoutButtons = not addon.db.profile.hideLogoutButtons
-				addon.updateMenu = true
+				addon:UpdateMenu()
 			end
 		},
 		{
@@ -60,7 +60,7 @@ function options:OnInitialize()
 			end,
 			set = function()
 				addon.db.profile.hideLogoutButtons = not addon.db.profile.hideLogoutButtons
-				addon.updateMenu = true
+				addon:UpdateMenu()
 			end
 		},
 		{
@@ -71,7 +71,18 @@ function options:OnInitialize()
 			end,
 			set = function()
 				addon.db.profile.hideOptionsButton = not addon.db.profile.hideOptionsButton
-				addon.updateMenu = true
+				addon:UpdateMenu()
+			end
+		},
+		{
+			type = "CheckButton",
+			text = L["Hide key bindings from the menu"],
+			get = function()
+				return addon.db.profile.hideKeyBindings
+			end,
+			set = function()
+				addon.db.profile.hideKeyBindings = not addon.db.profile.hideKeyBindings
+				addon:UpdateMenu()
 			end
 		},
 		{
diff --git a/options/Menu.lua b/options/Menu.lua
index 639cbd5..c25c0de 100644
--- a/options/Menu.lua
+++ b/options/Menu.lua
@@ -91,7 +91,7 @@ end

 function options:OnInitialize()
 	local order = addon.options:AddSubCategory(L["Menu"])
-
+
 	local availableItems = ui:CreateList(order)
 	availableItems:SetTitle("Available Interfaces")
 	availableItems:SetPoint("TOPLEFT", 10, -80)