diff options.lua @ 125:a9cf9b2fbf9b

- Fix interactions with AddonLoader. - Plugins get a :Print with a clickable prefix, with overrideable behaviors. - 'Deactivate' event gets a [wrapper around] current raiders table. - Fix sorting bug in player history data. - Smarter status line text when viewing unfiltered history. - Do not disable history regeneration button when current history is empty. - :BuildMainDisplay can handle the CLI args now.
author Farmbuyer of US-Kilrogg <farmbuyer@gmail.com>
date Sun, 19 Aug 2012 21:08:59 -0400
parents ccca3d8d2b22
children 47b149f9a5d7
line wrap: on
line diff
--- a/options.lua	Fri Aug 17 02:48:13 2012 -0400
+++ b/options.lua	Sun Aug 19 21:08:59 2012 -0400
@@ -750,6 +750,7 @@
 
 -- widget container status tables (will have things magically appear
 -- inside them that we wish to preserve)
+local options_treegroup -- careful, this is deliberately not preserved
 local status_for_scroll = {}
 local status_for_select = { treewidth = 160 }
 
@@ -800,6 +801,7 @@
 local tabs_OGS = function (container, specials)
 	container:SetLayout("Fill")
 	local left = AceGUI:Create("TreeGroup")
+	options_treegroup = left
 	left:SetStatusTable(status_for_select)
 	left:SetLayout("Fill")
 	left:SetFullWidth(true)
@@ -846,12 +848,18 @@
 	if preload then preload() end
 end
 
+local tabs_cli = function (unique)
+	if not controls[unique] then return end
+	options_treegroup:SetSelected(unique)
+	options_treegroup:SetUserData("options restore scroll", false)
+end
+
 addon:register_tab_control_AT_END ("opt", [[Options]],
 	[[Options for fine-tuning behavior]], tabs_OGS, [[
 The "be chatty" options can be noisy, but they make the
 |cffff8000[Ouro Loot]|r link much more useful.  See
 <Help -- Handy Tips> for details!
-]])
+]], tabs_cli)
 
 
 ---------------
@@ -873,14 +881,18 @@
 --[[
 PLUGIN is the module table itself.  (This does not actually have to be
   a plugin created with :[Constrained]NewModule, as long as it has a
-  GetName method and
+  'name' field and
   - TEXT is passed
   - if OPTIONS is a table, then OPTIONS.args.name exists
-PARENT is nil to register in the tree list directly.
-TEXT is either the text to display in the tree list, or nil to use the
-  moduleName field out of PLUGIN (not :GetName()).
+UNIQUE and PARENT control placement in the tree list.  UNIQUE is a unique
+  string, or nil to use the module's unique name (this can only be used once
+  obviously, or it's not "unique").  PARENT is nil to display at the main
+  level of options, or a previously-registered return value to display as a
+  child of that option.
+TEXT is either the text to display in the tree list, or nil to use
+  PLUGIN:GetName().
 OPTIONS is either
-  I)  an aceconfig-style options table
+  I)  an aceconfig-style options table (uses PLUGIN:GetName())
   II) a function to call directly
 
 (I) Will augment options.args.name with coloring/sizing, if it exists.
@@ -893,13 +905,16 @@
 	  the "button" clicked in the lefthand tree list.
 
 Will append a reset button IFF an options database has been registered already.
+
+XXX - the PARENT functionality hasn't been implmented yet cuz I'm lazy
 ]]
-function addon:register_options_entry (plugin, parent, text, options)
-	-- if this changes at all, fix up plugin_reset_button accordingly
-	local code = plugin:GetName()
+function addon:register_options_entry (plugin, unique, parent, text, options)
+	unique = (unique and tostring(unique))
+		or assert(plugin.name, "plugin has no 'name' field")
+
 	--if parent 
 
-	text = text or plugin.moduleName
+	text = text or plugin:GetName()
 
 	local handler
 	local pdb = plugin.moduleName and
@@ -907,10 +922,10 @@
 
 	if type(options) == 'table' then
 		-- AceConfig-style options table
-		aceconfig_list[code] = true
+		aceconfig_list[unique] = true
 		if not options.args.name then
 			options.args.name = {
-				name = plugin.moduleName,
+				name = plugin:GetName(),
 				type = 'description',
 			}
 		end
@@ -948,7 +963,7 @@
 		if pdb then
 			handler = function (sf)
 				sf:AddChildren(mktitle(text))
-				local ret = options (sf, plugin, code)
+				local ret = options (sf, plugin, unique)
 				local w = mkbutton("Reset",
 					([[Reset settings for <%s> plugin back to defaults.  Shift-click to also trigger a UI reload.]]):format(text))
 				w:SetRelativeWidth(0.3)
@@ -962,7 +977,7 @@
 		else
 			handler = function (sf)
 				sf:AddChildren(mktitle(text))
-				return options (sf, plugin, code)
+				return options (sf, plugin, unique)
 			end
 		end
 
@@ -970,19 +985,19 @@
 		error(("Error: 'options' parameter for plugin '%s' is neither table nor function"):format(plugin:GetName()))
 	end
 
-	if not controls[code] then
-		controls[code] = {}
+	if not controls[unique] then
+		controls[unique] = {}
 	end
-	table.insert (controls[code], handler)
+	table.insert (controls[unique], handler)
 
 	table.insert (options_tree, insertion_index, {
-		value = code,
-		text = text,  -- maybe call markup on this?
+		value = unique,
+		text = '++ '..text,  -- maybe call markup on this?
 	})
 	insertion_index = insertion_index + 1
 	-- The treegroup will rescan options_tree (via RefreshTree) several times
 	-- before the player actually sees anything; no more work needs doing.
-	return -- something that can be used as 'parent'
+	return unique -- something that can be used as 'parent'?
 end