diff Comments.lua @ 276:a43a9444659e

Added support for commenting on items when the mouse is hovering over them.
author James D. Callahan III <jcallahan@curse.com>
date Tue, 26 Mar 2013 23:38:29 -0500
parents ac6163ed8330
children 7e8e2297614a
line wrap: on
line diff
--- a/Comments.lua	Tue Mar 26 22:57:18 2013 -0500
+++ b/Comments.lua	Tue Mar 26 23:38:29 2013 -0500
@@ -126,6 +126,26 @@
     merchant = "ITEM",
 }
 
+local function CreateItemComment(is_command)
+    local item_name, item_id
+
+    if is_command then
+        local item_link
+        item_name, item_link = _G.GameTooltip:GetItem()
+
+        if not item_name and not item_link then
+            WDP:Print("Your mouse is not over an item.")
+            return
+        end
+        item_id = ItemLinkToID(item_link)
+    else
+        item_id = ItemLinkToID(comment_units.item.link)
+        item_name = comment_units.item.name
+    end
+    table.wipe(comment_units)
+    NewComment("ITEM", item_name, item_id)
+end
+
 local CreateCursorComment
 do
     local CURSOR_DATA_FUNCS = {
@@ -296,6 +316,16 @@
             line = display:AddLine(("Cursor: %s"):format(name_func(data, data_subtype, subdata)))
             display:SetLineScript(line, "OnMouseUp", CreateComment, CreateCursorComment)
         end
+        local item_name, item_link = _G.GameTooltip:GetItem()
+
+        if item_name and item_link then
+            comment_units.item = {
+                link = item_link,
+                name = item_name,
+            }
+            line = display:AddLine(("Item: %s"):format(item_name))
+            display:SetLineScript(line, "OnMouseUp", CreateComment, CreateItemComment)
+        end
 
         local quest_index = _G.GetQuestLogSelection()
 
@@ -333,6 +363,9 @@
     elseif arg == "cursor" then
         CreateCursorComment()
         return
+    elseif arg == "item" then
+        CreateItemComment(true)
+        return
     elseif arg == "quest" then
         CreateQuestComment()
         return
@@ -572,5 +605,8 @@
     --    private.data_obj = data_obj
     --    LibStub("LibDBIcon-1.0"):Register(ADDON_NAME, data_obj, private.db.global.config.minimap_icon)
 
+    _G.GameTooltip:HookScript("OnTooltipSetItem", function(self)
+    end)
+
     _G["BINDING_HEADER_WOWDB_PROFILER"] = "WoWDB Profiler"
 end