Updates for API version 100007, plus remove ghost checkmark when the last character unmarks a recipe

katkat42 [06-27-14 - 20:58]
Updates for API version 100007, plus remove ghost checkmark when the last character unmarks a recipe
Filename
Provisioning.lua
README
SousChef.txt
Utility.lua
libs/LibSort/LibSort-1.0.lua
diff --git a/Provisioning.lua b/Provisioning.lua
index c0a8ce4..1d24859 100644
--- a/Provisioning.lua
+++ b/Provisioning.lua
@@ -2,25 +2,26 @@ local SousChef = SousChef
 local u = SousChef.Utility
 local m = SousChef.Media

+-- SousChef:UpdateProvisioningTable() adds the Quality checkbox to the provisioner window and overrides the filtering function to incorporate it
 function SousChef:UpdateProvisioningTable()
-    self.qualityCheckBox = SousChef_ControllerOnlyQuality
-
     local function OnFilterChanged()
         self.settings.qualityChecked = ZO_CheckButton_IsChecked(self.qualityCheckBox)
         PROVISIONER:DirtyRecipeTree()
     end
+	-- set up the quality checkbox
+    self.qualityCheckBox = SousChef_ControllerOnlyQuality
     self.qualityCheckBox:SetParent(ZO_ProvisionerTopLevel)
     ZO_CheckButton_SetLabelText(self.qualityCheckBox, "Quality")
     ZO_CheckButton_SetToggleFunction(self.qualityCheckBox, OnFilterChanged)
     ZO_CraftingUtils_ConnectCheckBoxToCraftingProcess(self.qualityCheckBox)
     ZO_CheckButton_SetCheckState(self.qualityCheckBox, self.settings.qualityChecked)

-    -- Nudge to the left
+    -- make room for the checkbox
     ZO_ProvisionerTopLevelHaveSkills:ClearAnchors()
     ZO_ProvisionerTopLevelHaveSkills:SetAnchor( LEFT, ZO_ProvisionerTopLevelHaveIngredients, RIGHT, 180 )

+	-- incorporate new checkbox into the filter
     SousChef.filter = PROVISIONER.DoesRecipePassFilter
-
     PROVISIONER.DoesRecipePassFilter =
         function(control, specialIngredientType, numCreatable, provisionerLevelReq, qualityReq)
             if ZO_CheckButton_IsChecked(self.qualityCheckBox) and qualityReq < 2 then return false end
@@ -28,7 +29,7 @@ function SousChef:UpdateProvisioningTable()
         end
 end

-
+-- this is our "Mark Recipe" button definition
 SousChef.ProvisioningButton=
 {{
     name = "Mark Recipe", -- or function that returns a name
@@ -38,9 +39,9 @@ SousChef.ProvisioningButton=
     visible = function(descriptor) return PROVISIONER:GetSelectedRecipeIndex() ~= nil end,
     alignment = KEYBIND_STRIP_ALIGN_RIGHT,
 }}
-
 local bGroup = SousChef.ProvisioningButton

+-- SousChef:HookRecipeTreeFunction() adds the "Mark Recipe" button to the keybind bar, and set the provisioning window to display checkmarks by marked recipes
 function SousChef:HookRecipeTreeFunction()
     if not KEYBIND_STRIP:HasKeybindButtonGroup(bGroup) then
         KEYBIND_STRIP:AddKeybindButtonGroup(bGroup)
@@ -67,8 +68,10 @@ function SousChef:HookRecipeTreeFunction()
     PROVISIONER:DirtyRecipeTree()
 end

+-- SousChef:getMarkedIcon(row, marked) adds the checkmark next to each marked line in the provisioning window
 function SousChef:getMarkedIcon(row, marked)
     local rankIcon = SousChef.slotLines[row:GetName()]
+	-- first, if the control for the checkmark doesn't exist, create it
     if(not rankIcon) then
         rankIcon =  WINDOW_MANAGER:CreateControl(row:GetName() .. "SousChef", row, CT_TEXTURE)
         SousChef.slotLines[row:GetName()] = rankIcon
@@ -80,7 +83,7 @@ function SousChef:getMarkedIcon(row, marked)
                                                 ClearTooltip(InformationTooltip)
                                             end)
     end
-
+	-- then, if the recipe is marked by someone, show who, and set the checkmark's alpha accordingly
     if marked then
         rankIcon:SetHandler("OnMouseEnter", function()
                                         InitializeTooltip(InformationTooltip, rankIcon, RIGHT, -15, 0)
@@ -95,6 +98,7 @@ function SousChef:getMarkedIcon(row, marked)
     return rankIcon
 end

+-- SousChef:AddNotifier(control, marked) shows or hides the checkmark next to each recipe according to whether it's marked by anyone
 function SousChef:AddNotifier(control, marked)
     local icon = self:getMarkedIcon(control, marked)
     if marked then
@@ -120,6 +124,10 @@ function SousChef:MarkRecipe()
         SousChef.settings.shoppingList[link][GetUnitName("player")] = true -- we're now marked
     else
         SousChef.settings.shoppingList[link][GetUnitName("player")] = nil -- we're now unmarked
+		-- if that was the last mark we just got rid of, then nil out the entire recipe entry
+		if u.TableLength(SousChef.settings.shoppingList[link]) == 0 then
+			SousChef.settings.shoppingList[link] = nil
+		end
     end

     PROVISIONER:DirtyRecipeTree()
@@ -206,7 +214,6 @@ function SousChef:RefreshRecipeTree()
                     local data = {
                         recipeListIndex = recipeListIndex,
                         recipeIndex = recipeIndex,
-
                         name = recipeName,
                         provisionerLevelReq = provisionerLevelReq,
                         qualityReq = qualityReq,
diff --git a/README b/README
new file mode 100644
index 0000000..37685a4
--- /dev/null
+++ b/README
@@ -0,0 +1 @@
+This Add-on is not created by, affiliated with or sponsored by ZeniMax Media Inc. or its affiliates. The Elder Scrolls® and related logos are registered trademarks or trademarks of ZeniMax Media Inc. in the United States and/or other countries. All rights reserved.
\ No newline at end of file
diff --git a/SousChef.txt b/SousChef.txt
index 0dfc35c..59c89e1 100644
--- a/SousChef.txt
+++ b/SousChef.txt
@@ -1,7 +1,7 @@
 ## Title: Sous Chef
 ## Author: Wobin
 ## Version: @project-version@
-## APIVersion: 100004
+## APIVersion: 100007
 ## SavedVariables: SousChef_Settings

 libs\LibStub\LibStub.lua
diff --git a/Utility.lua b/Utility.lua
index c5bbf50..51e253b 100644
--- a/Utility.lua
+++ b/Utility.lua
@@ -1,11 +1,11 @@
-
 local SousChef = SousChef

 local u =  SousChef.Utility

 function u.GetItemID(link)
     if link == "" or not link then return -1 end
-	return tonumber(string.match(string.match(link, "%d+:"), "%d+"))
+    local itemid = select(4,ZO_LinkHandler_ParseLink(link))
+	return tonumber(itemid)
 end

 function u.EndsWith(String,End)
@@ -85,4 +85,13 @@ function u.MatchInIgnoreList(name)
         if u.CleanString(recipe) == name then return true end
     end
     return false
+end
+
+function u.TableLength(t)
+	if type(t) ~= "table" then return #t end
+	local n = 0
+	for k, v in pairs(t) do
+		n = n + 1
+	end
+	return n
 end
\ No newline at end of file
diff --git a/libs/LibSort/LibSort-1.0.lua b/libs/LibSort/LibSort-1.0.lua
index 098b3c4..c984a8a 100644
--- a/libs/LibSort/LibSort-1.0.lua
+++ b/libs/LibSort/LibSort-1.0.lua
@@ -36,40 +36,17 @@ function LibSort:SetupArrows()
 	LibSort.ItemSortBank = wm:CreateControlFromVirtual("ItemSortBank", ZO_PlayerBankSortBy, "ZO_SortHeaderIcon")
 	LibSort.ItemSortBank:SetDimensions(16, 32)
 	LibSort.ItemSortBank:SetAnchor(RIGHT, ZO_PlayerBankSortByName, LEFT, -15)
-	ZO_SortHeader_SetMouseCallback(ItemSortBank,    function(header, eventType)
-                                                            if(eventType == "OnMouseEnter") then
-                                                                InitializeTooltip(InformationTooltip, ItemSortBank, BOTTOMRIGHT, 0, 32)
-                                                                SetTooltipText(InformationTooltip, "Sort")
-                                                            else
-                                                                ClearTooltip(InformationTooltip)
-                                                            end
-                                                        end)
-    ZO_PlayerInventory_InitSortHeaderIcon(LibSort.ItemSortBank,
-                                    "EsoUI/Art/Miscellaneous/list_sortHeader_icon_neutral.dds",
-                                    "EsoUI/Art/Miscellaneous/list_sortHeader_icon_sortUp.dds",
-                                    "EsoUI/Art/Miscellaneous/list_sortHeader_icon_sortDown.dds",
-                                    "EsoUI/Art/Miscellaneous/list_sortHeader_icon_over.dds",
-                                    "age")
-
+	ZO_SortHeader_SetTooltip(LibSort.ItemSortBank, "Sort", BOTTOMRIGHT, 0, 32)
+    ZO_SortHeader_InitializeArrowHeader(LibSort.ItemSortBank, "age", ZO_SORT_ORDER_DOWN)
+
     PLAYER_INVENTORY.inventories[INVENTORY_BANK].sortHeaders:AddHeader(ItemSortBank)

     LibSort.ItemSortGuild = wm:CreateControlFromVirtual("ItemSortGuild", ZO_GuildBankSortBy, "ZO_SortHeaderIcon")
 	LibSort.ItemSortGuild:SetDimensions(16, 32)
 	LibSort.ItemSortGuild:SetAnchor(RIGHT, ZO_GuildBankSortByName, LEFT, -15)
-	ZO_SortHeader_SetMouseCallback(ItemSortGuild,    function(header, eventType)
-                                                            if(eventType == "OnMouseEnter") then
-                                                                InitializeTooltip(InformationTooltip, ItemSortGuild, BOTTOMRIGHT, 0, 32)
-                                                                SetTooltipText(InformationTooltip, "Sort")
-                                                            else
-                                                                ClearTooltip(InformationTooltip)
-                                                            end
-                                                        end)
-    ZO_PlayerInventory_InitSortHeaderIcon(LibSort.ItemSortGuild,
-                                    "EsoUI/Art/Miscellaneous/list_sortHeader_icon_neutral.dds",
-                                    "EsoUI/Art/Miscellaneous/list_sortHeader_icon_sortUp.dds",
-                                    "EsoUI/Art/Miscellaneous/list_sortHeader_icon_sortDown.dds",
-                                    "EsoUI/Art/Miscellaneous/list_sortHeader_icon_over.dds",
-                                    "age")
+	ZO_SortHeader_SetTooltip(LibSort.ItemSortGuild, "Sort", BOTTOMRIGHT, 0, 32)
+    ZO_SortHeader_InitializeArrowHeader(LibSort.ItemSortGuild, "age", ZO_SORT_ORDER_DOWN)
+
     PLAYER_INVENTORY.inventories[INVENTORY_GUILD_BANK].sortHeaders:AddHeader(ItemSortGuild)
 end