changeset 1:018fc9f0c471

continuing the development.
author tercio
date Sat, 09 Aug 2014 17:28:04 -0300
parents fc346da3afd9
children a6fb0ff113b1
files HotCorners.lua
diffstat 1 files changed, 125 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/HotCorners.lua	Fri Aug 08 12:35:17 2014 -0300
+++ b/HotCorners.lua	Sat Aug 09 17:28:04 2014 -0300
@@ -1,5 +1,6 @@
 
 LibHotCorners = LibStub ("AceAddon-3.0"):NewAddon ("HotCorners", "AceConsole-3.0", "AceEvent-3.0", "AceTimer-3.0")
+_G.HotCorners = LibHotCorners
 local LibHotCorners = LibHotCorners
 
 local LBD = LibStub ("LibDataBroker-1.1")
@@ -11,12 +12,15 @@
 	profile = {
 		is_enabled = true,
 		topleft_enabled = true,
-		quickfunc = false,
+		topleft_quickfunc = false,
 		clicks = {}, 
 		disabled = {}
 	},
 }
 
+LibHotCorners.RegistredQuickFunctions = {}
+LibHotCorners.QuickFunctions = {topleft = false}
+
 function LibHotCorners:OnEnable()
 	
 end
@@ -49,6 +53,29 @@
 			get = function() return LibHotCorners.db.profile.topleft_enabled end,
 			set = function (self, val) LibHotCorners.db.profile.topleft_enabled = not LibHotCorners.db.profile.topleft_enabled; refresh_topleft() end,
 		},
+		QuickClickFunc = {
+			type = "select",
+			name = "Quick Click",
+			desc = "Select the behavior when clicking over the absolute topleft corner.",
+			values = function()
+					local options = {}
+					for index, quickfunc in ipairs (LibHotCorners.RegistredQuickFunctions) do
+						options [quickfunc.name] = quickfunc.name
+					end
+					return options
+				end,
+			get = function() return LibHotCorners.db.profile.topleft_quickfunc or "" end,
+			set = function (self, funcname) 
+						LibHotCorners.db.profile.topleft_quickfunc = funcname;
+						for index, quickfunc in ipairs (LibHotCorners.RegistredQuickFunctions) do
+							if (quickfunc.name == funcname) then
+								LibHotCorners.QuickFunctions.topleft = quickfunc.func
+								break
+							end
+						end
+				end,
+			order = 4,
+		}
 	}
 }
 
@@ -92,7 +119,6 @@
 	local embed_functions = {
 		"RegisterHotCornerButton",
 		"HideHotCornerButton",
-		"QuickHotCornerEnable"
 	}
 	
 	function LibHotCorners:Embed (target)
@@ -115,55 +141,108 @@
 		assert (corner == "topleft" or corner == "bottomleft" or corner == "topright" or corner == "bottomright", "LibHotCorners:RegisterAddon expects a corner on #1 argument.")
 	end
 	
-	function LibHotCorners:RegisterHotCornerButton (name, corner, savedtable, fname, icon, tooltip, clickfunc, menus, quickfunc, onenter, onleave, is_install)
+	function LibHotCorners:AddQuickFunction (quickfunc, corner)
+
+		local current_quickfunc = LibHotCorners.db.profile [corner .. "_quickfunc"] or ""
+	
+		--> passed only one table
+		if (quickfunc.name) then
+			--> check if already exists
+			local already_exists = false
+			for _, registred in ipairs (LibHotCorners.RegistredQuickFunctions) do
+				if (registred.name == quickfunc.name) then
+					registred.func = quickfunc.func
+					if (current_quickfunc == quickfunc.name) then
+						LibHotCorners.QuickFunctions [corner] = quickfunc.func
+					end
+					already_exists = true
+					break
+				end
+			end
+			--> add table
+			if (not already_exists) then
+				table.insert (LibHotCorners.RegistredQuickFunctions, quickfunc)
+				if (current_quickfunc == quickfunc.name) then
+					LibHotCorners.QuickFunctions [corner] = quickfunc.func
+				end
+			end
+			--> check if there is a quickfunc to be use
+			if (current_quickfunc == "") then
+				LibHotCorners.db.profile [corner .. "_quickfunc"] = quickfunc.name
+				LibHotCorners.QuickFunctions [corner] = quickfunc.func
+			end
+		else
+			--> passed a table of tables
+			for _, this_quickfunc in ipairs (quickfunc) do
+				--> check if already exists
+				local already_exists = false
+				for _, registred in ipairs (LibHotCorners.RegistredQuickFunctions) do
+					if (registred.name == this_quickfunc.name) then
+						registred.func = this_quickfunc.func
+						if (current_quickfunc == this_quickfunc.name) then
+							LibHotCorners.QuickFunctions [corner] = this_quickfunc.func
+						end
+						already_exists = true
+						break
+					end
+				end
+				--> add table
+				if (not already_exists) then
+					table.insert (LibHotCorners.RegistredQuickFunctions, this_quickfunc)
+					if (current_quickfunc == this_quickfunc.name) then
+						LibHotCorners.QuickFunctions [corner] = this_quickfunc.func
+					end
+				end
+				--> check if there is a quickfunc to be use
+				if (current_quickfunc == "") then
+					LibHotCorners.db.profile [corner .. "_quickfunc"] = this_quickfunc.name
+					LibHotCorners.QuickFunctions [corner] = this_quickfunc.func
+					current_quickfunc = this_quickfunc.name
+				end
+			end
+		end
+
+	end
+	
+	function LibHotCorners:RegisterHotCornerButton (name, corner, optionstable, fname, icon, tooltip, clickfunc, menus, quickfunc, onenter, onleave, is_install)
 		corner = string.lower (corner)
 		test (corner)
 
+		optionstable = optionstable or {hide = false}
+		
 		if (is_install) then
 			--> overwrite if already exists a widget
 			for i, widget in ipairs (LibHotCorners [corner]) do
 				if (widget.name == name) then
 					table.remove (LibHotCorners [corner], i)
-					table.insert (LibHotCorners [corner], i, {name = name, fname = fname, savedtable = savedtable, icon = icon, tooltip = tooltip, click = clickfunc, menus = menus, quickfunc = quickfunc, onenter = onenter, onleave = onleave, is_install = true})
+					table.insert (LibHotCorners [corner], i, {name = name, fname = fname, optionstable = optionstable, icon = icon, tooltip = tooltip, click = clickfunc, menus = menus, quickfunc = quickfunc, onenter = onenter, onleave = onleave, is_install = true})
+					if (quickfunc) then
+						LibHotCorners:AddQuickFunction (quickfunc, corner)
+					end
 					return LibHotCorners [corner].map [name]
 				end
 			end
-			
-			table.insert (LibHotCorners [corner], {name = name, fname = fname, savedtable = savedtable, icon = icon, tooltip = tooltip, click = clickfunc, menus = menus, quickfunc = quickfunc, onenter = onenter, onleave = onleave, is_install = true})
+			--> add
+			table.insert (LibHotCorners [corner], {name = name, fname = fname, optionstable = optionstable, icon = icon, tooltip = tooltip, click = clickfunc, menus = menus, quickfunc = quickfunc, onenter = onenter, onleave = onleave, is_install = true})
 			LibHotCorners [corner].map [name] = #LibHotCorners [corner]
+			if (quickfunc) then
+				LibHotCorners:AddQuickFunction (quickfunc, corner)
+			end
 			return LibHotCorners [corner].map [name]
 		else
-			tinsert (LibHotCorners [corner], {name = name, fname = fname, savedtable = savedtable, icon = icon, tooltip = tooltip, click = clickfunc, menus = menus, quickfunc = quickfunc, onenter = onenter, onleave = onleave})
-			LibHotCorners [corner].map [name] = #LibHotCorners [corner]
-			return LibHotCorners [corner].map [name]
-		end
-	end
-	
-	function LibHotCorners:QuickHotCornerEnable (name, corner, value)
-		
-		corner = string.lower (corner)
-		test (corner)
-		
-		local corner_table = LibHotCorners [corner]
-		local addon_table = corner_table [corner_table.map [name]]
-		
-		addon_table.savedtable [corner .. "_quickclick"] = value
-
-		if (value and addon_table.quickfunc) then
-			corner_table.quickfunc = addon_table.quickfunc
-		else
-			local got = false
-			for index, button_table in ipairs (corner_table) do 
-				if (button_table.savedtable.quickclick) then
-					corner_table.quickfunc = button_table.quickfunc
-					got = true
-					break
+			--> check if already exists
+			for i, widget in ipairs (LibHotCorners [corner]) do
+				if (widget.name == name) then
+					return
 				end
 			end
-			
-			if (not got) then
-				corner_table.quickfunc = nil
+			--> add
+			table.insert (LibHotCorners [corner], {name = name, fname = fname, optionstable = optionstable, icon = icon, tooltip = tooltip, click = clickfunc, menus = menus, quickfunc = quickfunc, onenter = onenter, onleave = onleave})
+			LibHotCorners [corner].map [name] = #LibHotCorners [corner]
+			if (quickfunc) then
+				LibHotCorners:AddQuickFunction (quickfunc, corner)
 			end
+			return LibHotCorners [corner].map [name]
 		end
 	end
 	
@@ -175,13 +254,14 @@
 		local corner_table = LibHotCorners [corner]
 		local addon_table = corner_table [corner_table.map [name]]
 		
-		addon_table.savedtable.hide = value
+		if (addon_table) then
+			addon_table.optionstable.hide = value
+		end
 
-		--print (LibHotCorners, corner)
 		LibHotCorners [corner].is_enabled = false
 		
-		for index, button_table in ipairs (corner_table) do 
-			if (not button_table.savedtable.hide) then
+		for index, button_table in ipairs (corner_table) do
+			if (not button_table.optionstable.hide) then
 				LibHotCorners [corner].is_enabled = true
 				break
 			end
@@ -281,7 +361,7 @@
 				
 				button_table.widget:ClearAllPoints()
 				
-				if (not disabled [button_table.name]) then
+				if (not disabled [button_table.name] and not button_table.optionstable.hide) then
 					if (self.position == "topleft" or self.position == "topright") then
 						local y = i * 35 * -1
 						button_table.widget:SetPoint ("topleft", self, "topleft", 4, y)
@@ -312,7 +392,9 @@
 		function HotCornersOnLeave (self)
 			self:SetSize (1, 1)
 			for index, button_table in ipairs (LibHotCorners [self.position]) do 
-				button_table.widget:Hide()
+				if (button_table.widget) then
+					button_table.widget:Hide()
+				end
 			end
 			local OptionsButton = LibHotCorners [self.position].optionsbutton
 			OptionsButton:Hide()
@@ -321,8 +403,9 @@
 	--> quick corner on click
 		function HotCornersOnQuickClick (self, button)
 			local parent_position = self:GetParent().position
-			if (LibHotCorners [parent_position].quickfunc) then
-				LibHotCorners [parent_position].quickfunc (self, button)
+			local func = LibHotCorners.QuickFunctions [parent_position]
+			if (func) then
+				func (self, button)
 			end
 		end