Quantcast

Upgrade Ace3 libs to the latest version.

Eyal Shilony [10-16-14 - 09:03]
Upgrade Ace3 libs to the latest version.

Add a secure buttons overlay so we can execute secure actions.

Altering profiles will reload the UI immediately once executed.
Filename
.gitignore
Broker_StartMenu.toc
Core.lua
Menu.lua
SecureButtonsOverlay.lua
libs/AceDB-3.0/AceDB-3.0.lua
libs/EasyDisplay.lua
loc/enUS.lua
options/Accessibility.lua
options/Menu.lua
options/Profiles.lua
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..47a521d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+.buildpath
+.project
\ No newline at end of file
diff --git a/Broker_StartMenu.toc b/Broker_StartMenu.toc
index 36b5940..77aa8dd 100644
--- a/Broker_StartMenu.toc
+++ b/Broker_StartMenu.toc
@@ -22,6 +22,7 @@ libs\EasyDisplay.lua

 loc\enUS.lua

+SecureButtonsOverlay.lua
 Tooltip.lua
 Menu.lua
 Core.lua
diff --git a/Core.lua b/Core.lua
index a61bc4d..724515b 100644
--- a/Core.lua
+++ b/Core.lua
@@ -99,10 +99,20 @@ core:SetOnUpdate(function(self, elapsed)
 end)

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

+	addon.db.RegisterCallback(addon, "OnProfileChanged", function()
+		ReloadUI()
+	end)
+
+	addon.db.RegisterCallback(addon, "OnProfileCopied", function()
+		ReloadUI()
+	end)
+
+	addon.db.RegisterCallback(addon, "OnProfileReset", function()
+		ReloadUI()
+	end)
+
 	addon.dataobj = LibStub("LibDataBroker-1.1"):NewDataObject(addon.name, {
 		type = "data source",
 		icon = "Interface\\GroupFrame\\UI-Group-LeaderIcon",
diff --git a/Menu.lua b/Menu.lua
index 17ed3b1..5dbdf7f 100644
--- a/Menu.lua
+++ b/Menu.lua
@@ -39,7 +39,6 @@ local function insertItem(name, order)
 			text = interface.title,
 			icon = interface.icon,
 			notCheckable = 1,
-			func = function() display:DisplayInterface(name) end,
 			attributes = {
 				["type"] = "click",
 				["clickbutton"] = interface.button,
@@ -48,6 +47,9 @@ local function insertItem(name, order)

 		if interface.button then
 			entry.button = interface.button
+			entry.func = interface.func
+		else
+			entry.func = function() display:DisplayInterface(name) end
 		end

 		table.insert(menu, entry)
@@ -76,6 +78,20 @@ local function comp(a, b)
 	return a.order < b.order
 end

+DropDownList1:HookScript("OnShow", function(self)
+	if InCombatLockdown() then
+		return
+	end
+	addon:RemoveSecureButtonsOverlay()
+	if addon:IsMenuVisible() then
+		addon:AddSecureButtonsOverlay(menu)
+	end
+end)
+
+DropDownList1:HookScript("OnHide", function(self)
+	addon:RemoveSecureButtonsOverlay()
+end)
+
 function addon:BuildMenu()
 	if not self.updateMenu then
 		return
diff --git a/SecureButtonsOverlay.lua b/SecureButtonsOverlay.lua
new file mode 100644
index 0000000..37fc8cd
--- /dev/null
+++ b/SecureButtonsOverlay.lua
@@ -0,0 +1,111 @@
+--[[
+	Copyright (c) 2012 Eyal Shilony
+
+	Permission is hereby granted, free of charge, to any person obtaining
+	a copy of this software and associated documentation files (the
+	"Software"), to deal in the Software without restriction, including
+	without limitation the rights to use, copy, modify, merge, publish,
+	distribute, sublicense, and/or sell copies of the Software, and to
+	permit persons to whom the Software is furnished to do so, subject to
+	the following conditions:
+
+	The above copyright notice and this permission notice shall be
+	included in all copies or substantial portions of the Software.
+
+	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+	EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+	MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+	NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+	LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+	OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+	WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+]]
+
+local _, addon = ...
+
+local secureButtons = { }
+
+-- script handlers to mimic regular dropdown button behaviour
+-- close menu when clicked
+local function onClick(self)
+	self.parent:GetParent():Hide()
+end
+
+local function onMouseDown(self)
+	self.parent:SetButtonState("PUSHED")
+end
+
+local function onMouseUp(self)
+	self.parent:SetButtonState("NORMAL")
+end
+
+-- prevent menu from hiding
+local function onEnter(self)
+	local grandParent = self.parent:GetParent()
+	CloseDropDownMenus(grandParent:GetID() + 1)
+	_G[self.parent:GetName().."Highlight"]:Show()
+	UIDropDownMenu_StopCounting(grandParent)
+end
+
+-- hide menu after timeout
+local function onLeave(self)
+	_G[self.parent:GetName().."Highlight"]:Hide()
+	UIDropDownMenu_StartCounting(self.parent:GetParent())
+	GameTooltip:Hide()
+end
+
+local function createSecureButtonOverlay(button)
+	local secureButton = CreateFrame("Button", nil, nil, "SecureActionButtonTemplate")
+	secureButton:SetSize(200, 16)
+	secureButton:HookScript("OnClick", onClick)
+	secureButton:SetScript("OnEnter", onEnter)
+	secureButton:SetScript("OnLeave", onLeave)
+	secureButton:SetScript("OnMouseDown", onMouseDown)
+	secureButton:SetScript("OnMouseUp", onMouseUp)
+	secureButton:SetAttribute("type", "click")
+	secureButton:SetAttribute("clickbutton", button)
+	return secureButton
+end
+
+-- TODO: We can remove the dependency on the menu by using the dropdown itself, for now it works!
+function addon:AddSecureButtonsOverlay(menu)
+	local index = 0
+	for _, item in pairs(menu) do
+		if item.order and item.order > 0 then
+			index = index + 1
+			local parent = _G["DropDownList1Button" .. index]
+			if not parent then
+				UIDropDownMenu_CreateFrames(1, index)
+				parent = _G["DropDownList1Button" .. index]
+			end
+			if parent and item.button then
+				local button = createSecureButtonOverlay(item.button)
+				table.insert(secureButtons, button)
+				button.parent = parent
+				button:SetParent(parent)
+				button:SetAllPoints()
+				--[[button:SetBackdrop({
+					  bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
+					  tile = true,
+					  tileSize = 16,
+					  --edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
+					  edgeSize = 16,
+					  insets = {left = 5, right = 3, top = 3, bottom = 5}
+				})
+				button:SetBackdropColor(0, 1, 0, 0.5)]]
+				button:Show()
+			end
+		end
+	end
+end
+
+function addon:RemoveSecureButtonsOverlay()
+	if #secureButtons > 0 then
+		for index, button in ipairs(secureButtons) do
+			button:SetParent(UIParent)
+			button:ClearAllPoints()
+			button:Hide()
+		end
+		wipe(secureButtons)
+	end
+end
\ No newline at end of file
diff --git a/libs/AceDB-3.0/AceDB-3.0.lua b/libs/AceDB-3.0/AceDB-3.0.lua
index c2bb775..79f4b39 100644
--- a/libs/AceDB-3.0/AceDB-3.0.lua
+++ b/libs/AceDB-3.0/AceDB-3.0.lua
@@ -39,8 +39,8 @@
 -- end
 -- @class file
 -- @name AceDB-3.0.lua
--- @release $Id: AceDB-3.0.lua 1035 2011-07-09 03:20:13Z kaelten $
-local ACEDB_MAJOR, ACEDB_MINOR = "AceDB-3.0", 22
+-- @release $Id: AceDB-3.0.lua 1115 2014-09-21 11:52:35Z kaelten $
+local ACEDB_MAJOR, ACEDB_MINOR = "AceDB-3.0", 25
 local AceDB, oldminor = LibStub:NewLibrary(ACEDB_MAJOR, ACEDB_MINOR)

 if not AceDB then return end -- No upgrade needed
@@ -260,9 +260,12 @@ local _, classKey = UnitClass("player")
 local _, raceKey = UnitRace("player")
 local factionKey = UnitFactionGroup("player")
 local factionrealmKey = factionKey .. " - " .. realmKey
-local factionrealmregionKey = factionrealmKey .. " - " .. string.sub(GetCVar("realmList"), 1, 2):upper()
 local localeKey = GetLocale():lower()

+local regionTable = { "US", "KR", "EU", "TW", "CN" }
+local regionKey = _G["GetCurrentRegion"] and regionTable[GetCurrentRegion()] or string.sub(GetCVar("realmList"), 1, 2):upper()
+local factionrealmregionKey = factionrealmKey .. " - " .. regionKey
+
 -- Actual database initialization function
 local function initdb(sv, defaults, defaultProfile, olddb, parent)
 	-- Generate the database keys for each section
@@ -525,6 +528,15 @@ function DBObjectLib:DeleteProfile(name, silent)
 		end
 	end

+	-- switch all characters that use this profile back to the default
+	if self.sv.profileKeys then
+		for key, profile in pairs(self.sv.profileKeys) do
+			if profile == name then
+				self.sv.profileKeys[key] = nil
+			end
+		end
+	end
+
 	-- Callback: OnProfileDeleted, database, profileKey
 	self.callbacks:Fire("OnProfileDeleted", self, name)
 end
diff --git a/libs/EasyDisplay.lua b/libs/EasyDisplay.lua
index 3d2f1d4..8a6609c 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", 6)
+local lib, minor = LibStub:NewLibrary("EasyDisplay-1.0", 7)
 if not lib then return end
 minor = minor or 0

@@ -69,7 +69,7 @@ LoD_AddonFrames = {
 	name - (string) The name to access the interface.
 	title - (string) The title that represents the interface.
 	alias - (string) An optional name to access the interface.
-	frameName - (string) The name of the frame as it appears in the UIPanelWindows table to manage the display or the name of the frame as it appears in the ProtectedFrames table to determine whether the frame is protected.
+	frameName - (string) The name of the frame as it appears in the UIPanelWindows table to manage the display or the name of the frame as it appears in the ProtectedFrames table.
 	button (frame) - The button to click to open the interface.
 	level - (number) The minimum level of the player required to display the interface.
 	func - (function) The function (handler) to display the interface.
@@ -102,6 +102,7 @@ local interfaces = {
 		frameName = "SpellBookFrame",
 		button = SpellbookMicroButton,
 		func = function() ToggleFrame(SpellBookFrame) end,
+		secure = true,
 	},
 	{
 		name = "talents",
@@ -110,7 +111,8 @@ local interfaces = {
 		frameName = "PlayerTalentFrame",
 		level = SHOW_TALENT_LEVEL,
 		button = TalentMicroButton,
-		func = function() ToggleTalentFrame() end,
+		func = ToggleTalentFrame,
+		secure = true,
 	},
 	{
 		name = "achievements",
@@ -118,7 +120,7 @@ local interfaces = {
 		alias = "achi",
 		frameName = "AchievementFrame",
 		button = AchievementMicroButton,
-		func = function() ToggleAchievementFrame() end,
+		func = ToggleAchievementFrame,
 	},
 	{
 		name = "calendar",
@@ -133,7 +135,7 @@ local interfaces = {
 		alias = "ql",
 		frameName = "QuestLogFrame",
 		button = QuestLogMicroButton,
-		func = function() ToggleQuestLog() end,
+		func = ToggleQuestLog,
 	},
 	{
 		name = "social",
@@ -156,7 +158,7 @@ local interfaces = {
 		frameName = "LFDParentFrame",
 		level = SHOW_LFD_LEVEL,
 		button = LFDMicroButton,
-		func = function() ToggleLFDParentFrame() end,
+		func = ToggleLFDParentFrame,
 	},
 	{
 		name = "lfr",
@@ -171,7 +173,7 @@ local interfaces = {
 		alias = "pets",
 		frameName = "PetJournalParent",
 		button = CompanionsMicroButton,
-		func = function() TogglePetJournal() end,
+		func = TogglePetJournal,
 	},
 	{
 		name = "journal",
@@ -179,14 +181,14 @@ local interfaces = {
 		frameName = "EncounterJournal",
 		level = SHOW_LFD_LEVEL,
 		button = EJMicroButton,
-		func = function() ToggleEncounterJournal() end,
+		func = ToggleEncounterJournal,
 	},
 	{
 		name = "guild",
 		title = GUILD,
 		frameName = "GuildFrame",
 		button = GuildMicroButton,
-		func = function() ToggleGuildFrame() end,
+		func = ToggleGuildFrame,
 	},
 	{
 		name = "backpack",
@@ -217,7 +219,7 @@ local interfaces = {
 		title = HELP_BUTTON,
 		frameName = "HelpFrame",
 		button = HelpMicroButton,
-		func = function() ToggleHelpFrame() end,
+		func = ToggleHelpFrame,
 	},
 	{
 		name = "options",
diff --git a/loc/enUS.lua b/loc/enUS.lua
index cfca477..f3dda79 100644
--- a/loc/enUS.lua
+++ b/loc/enUS.lua
@@ -45,4 +45,4 @@ L["Menu"] = true
 L["Sort the order of the menu items.\n\nNote, having no sorting order (zero) hides the item from the menu."] = true

 L["Profiles"] = true
-L["You can change the active database profile, so you can have different settings for every character."] = true
\ No newline at end of file
+L["You can change the active database profile, so you can have different settings for every character.\n\nAltering profiles reloads the UI immediately."] = true
\ No newline at end of file
diff --git a/options/Accessibility.lua b/options/Accessibility.lua
index c23f36d..af5f10b 100644
--- a/options/Accessibility.lua
+++ b/options/Accessibility.lua
@@ -30,9 +30,11 @@ function options:OnInitialize()
     local accessibility = addon.options:AddSubCategory(L["Accessibility"])
 	accessibility:SetDescription(L["Bind up to four menu items to the mouse which you can use to open them quickly by clicking on the broker display."])

-	local titles = { }
+	local titles = {}
 	for _, v in addon.display:Interfaces() do
-		table.insert(titles, v.title)
+		if not v.secure then
+			table.insert(titles, v.title)
+		end
 	end

 	local buttons = {
diff --git a/options/Menu.lua b/options/Menu.lua
index d2c11c0..7b3e863 100644
--- a/options/Menu.lua
+++ b/options/Menu.lua
@@ -143,16 +143,4 @@ function options:OnInitialize()
 		visibleItems:MoveSelectedDown()
 		updateMenuDb(visibleItems)
 	end)
-
-	addon.db.RegisterCallback(addon, "OnProfileChanged", function()
-		reset(availableItems, visibleItems)
-	end)
-
-	addon.db.RegisterCallback(addon, "OnProfileCopied", function()
-		reset(availableItems, visibleItems)
-	end)
-
-	addon.db.RegisterCallback(addon, "OnProfileReset", function()
-		reset(availableItems, visibleItems)
-	end)
 end
diff --git a/options/Profiles.lua b/options/Profiles.lua
index e1f20b2..cfe6b2f 100644
--- a/options/Profiles.lua
+++ b/options/Profiles.lua
@@ -27,7 +27,7 @@ local L = LibStub("AceLocale-3.0"):GetLocale(addonName)

 function options:OnInitialize()
     local profiles = addon.options:AddSubCategory(L["Profiles"])
-    profiles:SetDescription(L["You can change the active database profile, so you can have different settings for every character."])
+    profiles:SetDescription(L["You can change the active database profile, so you can have different settings for every character.\n\nAltering profiles reloads the UI immediately."])

     local frame = LibStub("Libra"):CreateAceDBControls(addon.db, profiles)