Quantcast

-Updated the tooltip search library

Xruptor [03-23-13 - 18:55]
-Updated the tooltip search library
-Fixed an issue where the tooltip library search wouldn't always pick up on items.
-Added the ability to search by class c:warlock or class:warlock
-Fixed a stupid taint issue with bindings
Filename
BagSync.toc
BagSync_Search.lua
Bindings.xml
libs/LibItemSearch-1.0.lua
diff --git a/BagSync.toc b/BagSync.toc
index cb5b89c..7567f92 100644
--- a/BagSync.toc
+++ b/BagSync.toc
@@ -2,7 +2,7 @@
 ## Title: BagSync
 ## Notes: BagSync tracks your characters items and displays it within tooltips.
 ## Author: Xruptor
-## Version: 7.3
+## Version: 7.4
 ## OptionalDeps: tekDebug
 ## SavedVariables: BagSyncDB, BagSyncOpt, BagSyncGUILD_DB, BagSyncTOKEN_DB, BagSyncCRAFT_DB, BagSyncBLACKLIST_DB

diff --git a/BagSync_Search.lua b/BagSync_Search.lua
index 02777e2..2e016ee 100644
--- a/BagSync_Search.lua
+++ b/BagSync_Search.lua
@@ -8,6 +8,52 @@ local currentPlayer = UnitName('player')
 local ItemSearch = LibStub('LibItemSearch-1.0')
 local bgSearch = CreateFrame("Frame","BagSync_SearchFrame", UIParent)

+--add class search
+local tooltipScanner = _G['LibItemSearchTooltipScanner'] or CreateFrame('GameTooltip', 'LibItemSearchTooltipScanner', UIParent, 'GameTooltipTemplate')
+local tooltipCache = setmetatable({}, {__index = function(t, k) local v = {} t[k] = v return v end})
+
+ItemSearch:RegisterTypedSearch{
+	id = 'classRestriction',
+	tags = {'c', 'class'},
+
+	canSearch = function(self, _, search)
+		return search
+	end,
+
+	findItem = function(self, link, _, search)
+		if link:find("battlepet") then return false end
+
+		local itemID = link:match('item:(%d+)')
+		if not itemID then
+			return
+		end
+
+		local cachedResult = tooltipCache[search][itemID]
+		if cachedResult ~= nil then
+			return cachedResult
+		end
+
+		tooltipScanner:SetOwner(UIParent, 'ANCHOR_NONE')
+		tooltipScanner:SetHyperlink(link)
+
+		local result = false
+
+		local pattern = string.gsub(ITEM_CLASSES_ALLOWED:lower(), "%%s", "(.+)")
+
+		for i = 1, tooltipScanner:NumLines() do
+			local text =  _G[tooltipScanner:GetName() .. 'TextLeft' .. i]:GetText():lower()
+			textChk = string.find(text, pattern)
+
+			if textChk and tostring(text):find(search) then
+				result = true
+			end
+		end
+
+		tooltipCache[search][itemID] = result
+		return result
+	end,
+}
+
 local function LoadSlider()

 	local function OnEnter(self)
diff --git a/Bindings.xml b/Bindings.xml
index d9837cc..bf01d65 100644
--- a/Bindings.xml
+++ b/Bindings.xml
@@ -6,28 +6,28 @@
 		BagSync_SearchFrame:Show()
 	end
   </Binding>
-   <Binding name="BAGSYNCTOGGLETOKENS" header="BAGSYNC">
+   <Binding name="BAGSYNCTOGGLETOKENS">
 	if BagSync_TokensFrame:IsVisible() then
 		BagSync_TokensFrame:Hide()
 	else
 		BagSync_TokensFrame:Show()
 	end
   </Binding>
-   <Binding name="BAGSYNCTOGGLEPROFILES" header="BAGSYNC">
+   <Binding name="BAGSYNCTOGGLEPROFILES">
 	if BagSync_ProfilesFrame:IsVisible() then
 		BagSync_ProfilesFrame:Hide()
 	else
 		BagSync_ProfilesFrame:Show()
 	end
   </Binding>
-   <Binding name="BAGSYNCTOGGLECRAFTS" header="BAGSYNC">
+   <Binding name="BAGSYNCTOGGLECRAFTS">
 	if BagSync_CraftsFrame:IsVisible() then
 		BagSync_CraftsFrame:Hide()
 	else
 		BagSync_CraftsFrame:Show()
 	end
   </Binding>
-   <Binding name="BAGSYNCTOGGLEBLACKLIST" header="BAGSYNC">
+   <Binding name="BAGSYNCTOGGLEBLACKLIST">
 	if BagSync_BlackListFrame:IsVisible() then
 		BagSync_BlackListFrame:Hide()
 	else
diff --git a/libs/LibItemSearch-1.0.lua b/libs/LibItemSearch-1.0.lua
index 4bfdcff..ab83398 100644
--- a/libs/LibItemSearch-1.0.lua
+++ b/libs/LibItemSearch-1.0.lua
@@ -17,7 +17,7 @@
 		<op>				:=  : | = | == | != | ~= | < | > | <= | >=
 --]]

-local Lib = LibStub:NewLibrary('LibItemSearch-1.0', 7)
+local Lib = LibStub:NewLibrary('LibItemSearch-1.0', 9)
 if not Lib then
   return
 else
@@ -176,7 +176,7 @@ function Lib:FindTypedSearch(item, search, default)
     end
   else
     for id, searchType in self:GetTypedSearches() do
-      if self:UseTypedSearch(searchType, item, operator, search) then
+      if not searchType.onlyTags and self:UseTypedSearch(searchType, item, operator, search) then
         return true
       end
     end
@@ -200,14 +200,14 @@ end

 Lib:RegisterTypedSearch{
   id = 'itemName',
-  tags = {'name'},
+  tags = {'n', 'name'},

 	canSearch = function(self, operator, search)
 		return not operator and search
 	end,

 	findItem = function(self, item, _, search)
-		local name = GetItemInfo(item)
+		local name = item:match('%[(.-)%]')
 		return match(search, name)
 	end
 }
@@ -217,7 +217,7 @@ Lib:RegisterTypedSearch{

 Lib:RegisterTypedSearch{
 	id = 'itemType',
-	tags = {'type', 'slot'},
+	tags = {'t', 'type', 'slot'},

 	canSearch = function(self, operator, search)
 		return not operator and search
@@ -239,7 +239,7 @@ end

 Lib:RegisterTypedSearch{
 	id = 'itemQuality',
-	tags = {'quality'},
+	tags = {'q', 'quality'},

 	canSearch = function(self, _, search)
 		for i, name in pairs(qualities) do
@@ -260,7 +260,7 @@ Lib:RegisterTypedSearch{

 Lib:RegisterTypedSearch{
 	id = 'itemLevel',
-	tags = {'level', 'lvl'},
+	tags = {'l', 'level', 'lvl'},

 	canSearch = function(self, _, search)
 		return tonumber(search)
@@ -279,17 +279,19 @@ Lib:RegisterTypedSearch{

 local tooltipCache = setmetatable({}, {__index = function(t, k) local v = {} t[k] = v return v end})
 local tooltipScanner = _G['LibItemSearchTooltipScanner'] or CreateFrame('GameTooltip', 'LibItemSearchTooltipScanner', UIParent, 'GameTooltipTemplate')
-tooltipScanner:SetOwner(UIParent, 'ANCHOR_NONE')

 local function link_FindSearchInTooltip(itemLink, search)
-	--look in the cache for the result
 	local itemID = itemLink:match('item:(%d+)')
+	if not itemID then
+		return
+	end
+
 	local cachedResult = tooltipCache[search][itemID]
 	if cachedResult ~= nil then
 		return cachedResult
 	end

-	--no match?, pull in the resut from tooltip parsing
+	tooltipScanner:SetOwner(UIParent, 'ANCHOR_NONE')
 	tooltipScanner:SetHyperlink(itemLink)

 	local result = false
@@ -316,8 +318,8 @@ Lib:RegisterTypedSearch{
 	end,

 	keywords = {
-    	['soulbound'] = ITEM_BIND_ON_PICKUP,
-    	['bound'] = ITEM_BIND_ON_PICKUP,
+    		['soulbound'] = ITEM_BIND_ON_PICKUP,
+    		['bound'] = ITEM_BIND_ON_PICKUP,
 		['boe'] = ITEM_BIND_ON_EQUIP,
 		['bop'] = ITEM_BIND_ON_PICKUP,
 		['bou'] = ITEM_BIND_ON_USE,
@@ -328,21 +330,23 @@ Lib:RegisterTypedSearch{

 Lib:RegisterTypedSearch{
 	id = 'tooltip',
+	tags = {'tt', 'tip', 'tooltip'},
+	onlyTags = true,

 	canSearch = function(self, _, search)
-		return search and search:match('^tt:(.+)$')
+		return search
 	end,

-	findItem = function(self, itemLink, _, search)
-		tooltipScanner:SetHyperlink(itemLink)
+	findItem = function(self, link, _, search)
+		tooltipScanner:SetOwner(UIParent, 'ANCHOR_NONE')
+		tooltipScanner:SetHyperlink(link)

-		local i = 1
-		while i <= tooltipScanner:NumLines() do
+		for i = 1, tooltipScanner:NumLines() do
 			local text =  _G[tooltipScanner:GetName() .. 'TextLeft' .. i]:GetText():lower()
+
 			if text:find(search) then
 				return true
 			end
-			i = i + 1
 		end

 		return false
@@ -454,7 +458,7 @@ end

 Lib:RegisterTypedSearch{
 	id = 'equipmentSet',
-	tags = {'set'},
+	tags = {'s', 'set'},

 	canSearch = function(self, operator, search)
 		return not operator and search