Introduction

Predictors

The first step to use this widget is to register a "Predictor", a predictor is a callback function (or a list of callback functions for more advanced uses). The widget calls this function requesting values to display in the results dropdown list.

This is the more simple way to register a predictor. This predictor iterates over the player spell book, looking for spells matching the text typed in the editbox.

LibStub("AceGUI-3.0-Search-EditBox"):Register( "MyAddonSpellPredictor", function( self, text, results, max )
	local query = "^" .. string.lower(text)
	for index = 1, 1000 do
		local skillType, spellID = GetSpellBookItemInfo(index, "player")
		if not spellID then return end
		local name,_,icon = GetSpellInfo(spellID)
		if string.match(string.lower(name), query) then
			results[spellID] = string.format("|T%s:0|t%s (%d)",icon, name, spellID)
			max = max - 1; if max==0 then return end
		end
	end
end )

A more complex predictor, GetValue function is used to validate or change the result the user has typed or selected.

LibStub("AceGUI-3.0-Search-EditBox"):Register( "MyAddonSpellPredictor", {
	GetValues = function( self, text, results, max )
		local query = "^" .. string.lower(text)
		for index = 1, 1000 do
			local skillType, spellID = GetSpellBookItemInfo(index, "player")
			if not spellID then return end
			local name,_,icon = GetSpellInfo(spellID)
			if string.match(string.lower(name), query) then
				results[spellID] = string.format("|T%s:0|t%s (%d)",icon, name, spellID)
				max = max - 1; if max==0 then return end
			end
		end
	end,
	GetValue = function( self, text, spellID )
		return spellID
	end,
	GetHyperlink = function( self, spellID )
		return "spell:"..spellID
	end,
} )
AceConfig option code

The second step is to create an AceConfig option, using dialogControl: The dialogControl name must be:

"EditBox" .. predictor_name_used_in_register_process

An unique name for predictors must be used, adding your addon name to the predictor name is a good way to avoid conflicts with predictors registered by other addons.

options.editbox1 = {
	type = "input", 
	dialogControl = "EditBoxMyAddonSpellPredictor",
	name = "Type a spell name", 
	get = function ()   end,
	set = function (_, v)  print(v) end,
}

Comments

Posts Quoted:
Reply
Clear All Quotes