diff gui.lua @ 57:81d5449621f8

Fix some sloppy indentation. Correct handling of delayed-load plugins registering multiple tabs in arbitrary order. Add option to not display tabs for disabled plugins (would normally allow enabling of them).
author Farmbuyer of US-Kilrogg <farmbuyer@gmail.com>
date Tue, 17 Apr 2012 04:57:06 +0000
parents fcc0d0ff5832
children 59718ec80610
line wrap: on
line diff
--- a/gui.lua	Fri Apr 13 04:28:46 2012 +0000
+++ b/gui.lua	Tue Apr 17 04:57:06 2012 +0000
@@ -95,7 +95,6 @@
 ------ Behind the scenes routines
 -- Text generation
 do
-	local next_insertion_position = 2   -- position in _taborder
 	local text_gen_funcs, specials_gen_funcs = {}, {}
 	local accumulator = {}
 
@@ -116,8 +115,7 @@
 			error(("Generator for text type '%s' must be a function!"):format(text_type))
 		end
 		_tabtexts[text_type] = { title=title, desc=description }
-		tinsert (_taborder, next_insertion_position, text_type)
-		next_insertion_position = next_insertion_position + 1
+		self:tabposition_insert (text_type)
 		text_gen_funcs[text_type] = generator
 		specials_gen_funcs[text_type] = opt_specgen
 		dirty_tabs = true
@@ -159,24 +157,19 @@
 		-- "tabtitle" here is the name in _taborder, not the colorized string
 		local what = _tabtexts[tabtitle]
 		local addon_index = what.LOD
-		local loaded_at = what.loaded_at
-		local real_nip = next_insertion_position
 		local function LOAD()
 			_tabtexts[tabtitle] = nil
-			tremove (_taborder, loaded_at)
-			next_insertion_position = loaded_at
-			local saved_next_insertion_position = loaded_at
+			addon:tabposition_remove_and_remember (tabtitle)
 			local loaded, whynot = LoadAddOn(addon_index)
+			local tabdelta = addon:tabposition_restore()
 			if loaded then
-				addon:Print("%s loaded.  %d |4tab:tabs; added.", tabtitle,
-					next_insertion_position - saved_next_insertion_position)
+				addon:Print("%s loaded, %d |4tab:tabs; added.", tabtitle, tabdelta)
 			else
 				what.disabled = true
 				_tabtexts[tabtitle] = what -- restore this for mouseovers
 				addon:Print("%s could not load (game client reason was '%s').", tabtitle, whynot)
 				DisableAddOn(addon_index)
 			end
-			next_insertion_position = real_nip
 			dirty_tabs = true
 			return addon:OpenMainDisplayToTab(tabtitle) or addon:BuildMainDisplay()
 		end
@@ -187,7 +180,7 @@
 		else
 			-- was disabled at addons menu
 			StaticPopupDialogs["OUROL_LOD_DISABLED"] = flib.StaticPopup{
-				text = tabtitle.." was disabled at the character loading screen.  Do you want to enable it?",
+				text = tabtitle.." was disabled at the character selection screen.  Do you want to enable it?",
 				button1 = YES,
 				button2 = NO,
 				OnAccept = function()
@@ -211,15 +204,13 @@
 	function addon:_gui_add_LOD_tab (tabtitle, folder, addon_index, enabled_p, why_not)
 		_tabtexts[tabtitle] = {
 			title = ("|cffff0000(%s)|r"):format(tabtitle),
-			desc = ("'|cffff0000%s|r' is not loaded yet.  Click the tab to load it now."):format(folder),
+			desc = ("Plugin '|cffff0000%s|r' is not loaded yet.  Click the tab to load it now."):format(folder),
 			LOD = addon_index,
 			LOD_enabled = enabled_p,
 			LOD_why_not = why_not,
-			loaded_at = next_insertion_position,
 		}
 		tabs_OnGroupSelected[tabtitle] = _handle_LOD
-		tinsert (_taborder, next_insertion_position, tabtitle)
-		next_insertion_position = next_insertion_position + 1
+		self:tabposition_insert (tabtitle)
 		dirty_tabs = true
 	end
 end
@@ -417,6 +408,11 @@
 --[[
 Controls for the tabs on the left side of the main display.
 ]]
+
+-- The _tabtexts and _taborder tables have distressingly wide visibility.
+-- They are used to build the tabgroup_tabs array fed to TabGroup, and for the
+-- official source of mouseover tab titles, etc.  Not completely encapsulated
+-- because we need to reach in and fiddle too often to be worth it.
 _tabtexts = {
 	["eoi"] = {title=[[Loot]], desc=[[Observed loot, plus boss kills and other events of interest]]},
 	["hist"] = {title=[[History]], desc=[[A short semi-permanent record]]},
@@ -428,6 +424,42 @@
 _taborder = { "eoi", "hist", "help", "opt" }
 --else _taborder = { "eoi", "help", "opt" } end
 
+do
+	local next_insertion_position = 2   -- position in _taborder
+	local removed, saved_offset
+
+	function addon:tabposition_insert (tabcode)
+		tinsert (_taborder, next_insertion_position, tabcode)
+		next_insertion_position = next_insertion_position + 1
+	end
+
+	-- These two functions are push/pop pairs, sort of.  The first removes
+	-- a tab and prepares to insert more tab(s) in its place.  The second
+	-- returns the "next tab goes here" marker back to the proper end.  (And
+	-- doing all 3 adjustments below at once is amazingly hard to read.)
+	function addon:tabposition_remove_and_remember (tabcode)
+		assert(not removed)   -- enforce stack-ish discipline
+		for i = 2, #_taborder do
+			if _taborder[i] == tabcode then
+				tremove (_taborder, i)
+				saved_offset = next_insertion_position - i - 1
+				removed, next_insertion_position = i, i
+				return
+			end
+		end
+		error(("'%s' not used as a tab-text code"):format(tabcode))
+	end
+	function addon:tabposition_restore()
+		assert(removed)
+		local count = next_insertion_position - removed
+		next_insertion_position = next_insertion_position + saved_offset
+		removed, saved_offset = nil, nil
+		return count
+	end
+end
+
+
+-- Done at startup, and whenever we've changed the population of tabs.
 function addon:gui_init (loot_pointer)
 	g_loot = loot_pointer
 	g_generated = nil
@@ -1690,6 +1722,11 @@
 			[[Irreverent replacement names for boss events.]])
 		grp:AddChild(w)
 
+		-- LOD plugins in all cases
+		w = mkoption('display_disabled_LODs', "Include disabled plugins", 0.49,
+			[[Show loadable plugins even if they've been disabled (and offer to enable them).  Relog to take effect.]])
+		grp:AddChild(w)
+
 		-- possible keybindings
 		do
 			local pair = GUI:Create("SimpleGroup")