diff gui.lua @ 79:0235a1695b83

Tweak the manual entry hyperlink handling to use unique tags instead.
author Farmbuyer of US-Kilrogg <farmbuyer@gmail.com>
date Tue, 12 Jun 2012 17:33:38 +0000
parents f8118aa5fbb8
children 0f6355bcfe68
line wrap: on
line diff
--- a/gui.lua	Tue Jun 12 03:46:00 2012 +0000
+++ b/gui.lua	Tue Jun 12 17:33:38 2012 +0000
@@ -54,6 +54,7 @@
 local flib = LibStub("LibFarmbuyer")
 
 local g_loot			= nil
+local g_uniques			= nil
 local g_generated		= nil
 local window_title		= "Ouro Loot"
 local dirty_tabs		= nil
@@ -606,18 +607,28 @@
 	local rebroadcast_map  -- XXX weaken this somehow?
 
 	local function onclick (self, ident)
-		local data = assert(rebroadcast_map[ident])
-		eoi_dropdownfuncs["Rebroadcast this loot entry"](data.rowindex)
-		-- XXX delete the entry maybe?
+		-- Since an arbitrary number of insert/delete ops can happen between
+		-- now and (potentially) clicking on the hyperlink, we can't depend on
+		-- the row index.  Force the uniques cache to re-search (research?) it.
+		local u = assert(rebroadcast_map[ident])
+		local cache = g_uniques:SEARCH(u)
+		-- A missing history entry isn't necessarily an error here, but we
+		-- need a loot entry to go further.
+		if cache.loot then
+			eoi_dropdownfuncs["Rebroadcast this loot entry"](cache.loot)
+		else
+			addon:Print("...guh?  Entry was recorded with tag <%s> but cannot now be found!", u)
+		end
+		-- delete the entry maybe?
 	end
 
-	function _new_rebroadcast_hyperlink (data)
+	function _new_rebroadcast_hyperlink (u)
 		rebroadcast_map = rebroadcast_map or flib.new()
 		local clicky, ident = addon.format_hypertext(
 			-- same color sequence as what DBM uses to announce pizza timers,
 			-- which looks reasonably pleasing
 			[[Broadcast this entry]], "|cff3588ff", onclick)
-		rebroadcast_map[ident] = data
+		rebroadcast_map[ident] = u
 		return clicky
 	end
 end
@@ -683,8 +694,9 @@
 end
 
 -- Done at startup, and whenever we've changed the population of tabs.
-function addon:gui_init (loot_pointer)
+function addon:gui_init (loot_pointer, uniques_pointer)
 	g_loot = assert(loot_pointer, "something went wrong at startup")
+	g_uniques = assert(uniques_pointer, "something went wrong at startup")
 	g_generated = nil
 	tabgroup_tabs = {}
 	window_title = "Ouro Loot " .. self.revision
@@ -2336,13 +2348,13 @@
 	UIDROPDOWNMENU_SHOW_TIME = 4
 
 	if dirty_tabs then
-		self:gui_init(g_loot)  -- pointer known to be good by now
+		self:gui_init (g_loot, g_uniques)  -- pointers known to be good by now
 		self:zero_printed_fenceposts()
 	end
 
 	local display = GUI:Create("Frame")
 	if _d then
-		display:SetUserData("eoiST",_d)   -- warning! warning! kludge detected!
+		display:SetUserData("eoiST",_d)    -- warning! warning! kludge detected!
 	end
 	_d = display
 	self.display = display
@@ -2791,7 +2803,7 @@
 		tinsert(g_loot,data.rowindex,entry)
 		addon:_fill_out_eoi_data(data.rowindex)
 		addon:BuildMainDisplay()
-		local clicky = _new_rebroadcast_hyperlink (data)
+		local clicky = _new_rebroadcast_hyperlink (entry.unique)
 		dialog.data = nil
 		addon:Print ("Inserted %s %s at entry %d.  %s",
 			data.kind, data.name, data.rowindex, tostring(clicky))