Thread Tools Display Modes
11-29-12, 07:33 AM   #1
Tonyleila
A Molten Giant
 
Tonyleila's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 758
Item Link Macros

ItemLinkMacros

ItemLinkMacros is an addon which allows you to add item links into your macros simply by Shift-LClicking an item link while the macro window is open.
The macro link part of this addon is still working fine BUT since 5.1 it blocks Shift klicking items to search them inside profession windows. Can anyone tell me how to fix this please?

Lua Code:
  1. local _G = getfenv(0)
  2. --stack references for globals
  3. local GetItemInfo = _G.GetItemInfo
  4. local GetItemSpell = _G.GetItemSpell
  5.  
  6. local strfind = _G.strfind
  7. ------- Replacing the ChatEdit_InsertLink function
  8. local oldFunction = ChatEdit_InsertLink
  9.  
  10. ChatEdit_InsertLink = function(text)
  11.    if ( not text ) then
  12.       return false;
  13.    end
  14.    local activeWindow = ChatEdit_GetActiveWindow();
  15.    if ( activeWindow ) then
  16.       activeWindow:Insert(text);
  17.       return true;
  18.    end
  19.    if ( BrowseName and BrowseName:IsVisible() ) then
  20.       local item;
  21.       if ( strfind(text, "item:", 1, true) ) then
  22.          item = GetItemInfo(text);
  23.       end
  24.       if ( item ) then
  25.          BrowseName:SetText(item);
  26.          return true;
  27.       end
  28.    end
  29.    if ( MacroFrameText and MacroFrameText:IsVisible() ) then
  30.       local macroText = MacroFrameText:GetText();
  31.      
  32.       local item;
  33.       if ( strfind(text, "item:", 1, true) ) then
  34.          item = GetItemInfo(text);
  35.       end
  36.       -- my check for whether this is a spell or "other" link is kinda bad.  I could improve it with a Regex, but I doubt there will be many problems
  37.       local spellLink = strfind(text, "|Hspell:", 1, true)
  38.      
  39.       local enchantLink = strfind(text, "|Henchant:", 1, true)
  40.       local achievementLink = strfind(text, "|Hachievement:", 1, true)
  41.       local talentLink = strfind(text, "|Htalent:", 1, true)
  42.       local otherLink = enchantLink or achievementLink or talentLink
  43.      
  44.       if ( not otherLink and macroText == "" and not item ) then
  45.          MacroFrameText:Insert(SLASH_CAST1.." "..text);
  46.       elseif ( not otherLink and not spellLink and ( strfind(macroText, SLASH_USE1, 1, true) or strfind(macroText, SLASH_EQUIP1, 1, true) or strfind(macroText, SLASH_CAST1, 1, true) ) ) then
  47.          MacroFrameText:Insert(item or text);
  48.       else
  49.          MacroFrameText:Insert(text);
  50.       end
  51.       return true;
  52.    end
  53.    return false;
  54. end
  55. SLASH_ADDTEXT1="/addtext"
  56. SlashCmdList["ADDTEXT"] = function(text)
  57.    if ( MacroFrameText and MacroFrameText:IsVisible() ) then
  58.       MacroFrameText:Insert(text)
  59.    end
  60. end
__________________
Author of: LeilaUI and Aurora: Missing Textures
__________________

Last edited by Tonyleila : 11-29-12 at 07:36 AM.
  Reply With Quote
11-29-12, 09:02 AM   #2
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
Just beware that changing the global function ChatEdit_InsertLink will taint and break any secure code used by the chat and such, so if chat related stuff start to stop working, keep this in mind.
__________________
Profile: Curse | Wowhead
  Reply With Quote
11-29-12, 10:59 AM   #3
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
You're missing this block of code that should be after the MacroFrameText check.
Lua Code:
  1. if ( TradeSkillFrame and TradeSkillFrame:IsShown() )  then
  2.     local item;
  3.     if ( strfind(text, "item:", 1, true) ) then
  4.         item = GetItemInfo(text);
  5.     end
  6.     if ( item ) then
  7.         TradeSkillFrameSearchBox:SetFontObject("ChatFontSmall");
  8.         TradeSkillFrameSearchBoxSearchIcon:SetVertexColor(1.0, 1.0, 1.0);
  9.         TradeSkillFrameSearchBox:SetText(item);
  10.         return true;
  11.     end
  12. end
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 11-29-12 at 11:22 AM.
  Reply With Quote
11-29-12, 06:01 PM   #4
Tonyleila
A Molten Giant
 
Tonyleila's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 758
Originally Posted by SDPhantom View Post
You're missing this block of code that should be after the...
Thanks for the code works fine now!
I'll send the code to author so he can update it
__________________
Author of: LeilaUI and Aurora: Missing Textures
__________________
  Reply With Quote
11-30-12, 06:12 PM   #5
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
That came out of the last half of the function the author copied from and modified the macro handling of. He just missed including it in his code.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
12-01-12, 01:07 PM   #6
natassja72
A Wyrmkin Dreamwalker
Join Date: Aug 2008
Posts: 59
Untill it gets updated, if at all, would it be possible to put here all code, including the fix? I don't want to mess things up myself...
  Reply With Quote
12-01-12, 05:23 PM   #7
Tonyleila
A Molten Giant
 
Tonyleila's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 758
Originally Posted by natassja72 View Post
Untill it gets updated, if at all, would it be possible to put here all code, including the fix? I don't want to mess things up myself...
http://www.wowinterface.com/download...FanUpdate.html
__________________
Author of: LeilaUI and Aurora: Missing Textures
__________________
  Reply With Quote
12-02-12, 02:31 PM   #8
natassja72
A Wyrmkin Dreamwalker
Join Date: Aug 2008
Posts: 59
Thanks! Advertising now is made easy)
  Reply With Quote
06-05-13, 01:43 PM   #9
Tonyleila
A Molten Giant
 
Tonyleila's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 758
I just found out that my ItemLinkMacrosFanUpdate needs a fix. Can someone please help me with it?

For some reason it blocks to copy pet cages names into the auction house window. I can't copy the name from a petcage in my bag into the AH and not from the chat into AH.

Lua Code:
  1. local _G = getfenv(0)
  2.     --stack references for globals
  3.     local GetItemInfo = _G.GetItemInfo
  4.     local GetItemSpell = _G.GetItemSpell
  5.      
  6.     local strfind = _G.strfind
  7.     ------- Replacing the ChatEdit_InsertLink function
  8.     local oldFunction = ChatEdit_InsertLink
  9.      
  10.     ChatEdit_InsertLink = function(text)
  11.        if ( not text ) then
  12.           return false;
  13.        end
  14.        local activeWindow = ChatEdit_GetActiveWindow();
  15.        if ( activeWindow ) then
  16.           activeWindow:Insert(text);
  17.           return true;
  18.        end
  19.        if ( BrowseName and BrowseName:IsVisible() ) then
  20.           local item;
  21.           if ( strfind(text, "item:", 1, true) ) then
  22.              item = GetItemInfo(text);
  23.           end
  24.           if ( item ) then
  25.              BrowseName:SetText(item);
  26.              return true;
  27.           end
  28.        end
  29.            if ( TradeSkillFrame and TradeSkillFrame:IsShown() )  then
  30.         local item;
  31.         if ( strfind(text, "item:", 1, true) ) then
  32.             item = GetItemInfo(text);
  33.         end
  34.         if ( item ) then
  35.             TradeSkillFrameSearchBox:SetFontObject("ChatFontSmall");
  36.             TradeSkillFrameSearchBoxSearchIcon:SetVertexColor(1.0, 1.0, 1.0);
  37.             TradeSkillFrameSearchBox:SetText(item);
  38.             return true;
  39.         end
  40.     end
  41.        if ( MacroFrameText and MacroFrameText:IsVisible() ) then
  42.           local macroText = MacroFrameText:GetText();
  43.          
  44.           local item;
  45.           if ( strfind(text, "item:", 1, true) ) then
  46.              item = GetItemInfo(text);
  47.           end
  48.           -- my check for whether this is a spell or "other" link is kinda bad.  I could improve it with a Regex, but I doubt there will be many problems
  49.           local spellLink = strfind(text, "|Hspell:", 1, true)
  50.          
  51.           local enchantLink = strfind(text, "|Henchant:", 1, true)
  52.           local achievementLink = strfind(text, "|Hachievement:", 1, true)
  53.           local talentLink = strfind(text, "|Htalent:", 1, true)
  54.           local otherLink = enchantLink or achievementLink or talentLink
  55.          
  56.           if ( not otherLink and macroText == "" and not item ) then
  57.              MacroFrameText:Insert(SLASH_CAST1.." "..text);
  58.           elseif ( not otherLink and not spellLink and ( strfind(macroText, SLASH_USE1, 1, true) or strfind(macroText, SLASH_EQUIP1, 1, true) or strfind(macroText, SLASH_CAST1, 1, true) ) ) then
  59.              MacroFrameText:Insert(item or text);
  60.           else
  61.              MacroFrameText:Insert(text);
  62.           end
  63.           return true;
  64.        end
  65.        return false;
  66.     end
  67.     SLASH_ADDTEXT1="/addtext"
  68.     SlashCmdList["ADDTEXT"] = function(text)
  69.        if ( MacroFrameText and MacroFrameText:IsVisible() ) then
  70.           MacroFrameText:Insert(text)
  71.        end
  72.     end
__________________
Author of: LeilaUI and Aurora: Missing Textures
__________________
  Reply With Quote
06-05-13, 03:15 PM   #10
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Pre-hooking ChatEdit_InsertLink is a bad idea, as it will cause taint, and your particular hook is especially bad since you completely replicate the original function instead of just calling it -- so any time Blizzard changes the function, you either have to update your addon immediately, or you're breaking default UI functionality for your users.

You should use a secure post-hook instead:

Code:
hooksecurefunc("ChatEdit_InsertLink", function(link)
    if MyEditBox:IsVisible() and MyEditBox:HasFocus() then
        MyEditBox:Insert(link)
    end
end)
On a side note, upvaluing _G and then upvaluing _G.GetSpellInfo confers no benefit over just upvaluing GetSpellInfo directly -- and for code that only runs when the user shift-clicks a link in chat, there's no benefit in upvaluing anything at all. Just get rid of that clutter and make your code more readable.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
06-05-13, 03:43 PM   #11
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
It's not his code though Phanx, he just wanted to apply a patch to it.
  Reply With Quote
06-05-13, 03:53 PM   #12
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Doesn't matter who wrote it. The problems are still the same.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
06-05-13, 05:11 PM   #13
Tonyleila
A Molten Giant
 
Tonyleila's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 758
Yep its not my code and thats why I don't know now what to do with the fix you posted my lua knowledge is more like "copy-past" or edit only
However I understand that the addon maybe needs a rewrite but I don't know how...
__________________
Author of: LeilaUI and Aurora: Missing Textures
__________________

Last edited by Tonyleila : 06-05-13 at 05:15 PM.
  Reply With Quote
06-05-13, 07:15 PM   #14
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Based on the addon's description and code, it looks like the only thing it does is put the raw item link into the macro instead of just the item's name. Accordingly, the following code should work (for all link types, even). After the original ChatEdit_InsertLink function has run, it will check if the macro edit box has focus. If so, it will check if the macro already contains the link name. If not, it will insert the raw link.

This should work, because if the original function would handle the link (eg. shift-clicking a spell for a /cast command) then once your function runs, the edit box will already contain the link name (eg. the name of the spell).

Code:
hooksecurefunc("ChatEdit_InsertLink", function(link)
	if MacroFrameText and MacroFrameText:HasFocus() then
		local text = MacroFrameText:GetText()
		local name = strmatch(link, "%[(.-)%]")
		if not strfind(text, name, 1, true) then
			MacroFrameText:Insert(link)
		end
	end
end)
If you really only want it to work for links, change it accordingly:
Code:
	if MacroFrameText and MacroFrameText:HasFocus() and strfind(link, "|Hitem:", 1, true) then
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
06-05-13, 07:22 PM   #15
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
The whole point of the addon is to have item links instead of item names, thus you'd have to match and replace.

Edit: You'd also have to make sure it only works when not combined with /equip or the like, and aswell when replacing that you don't exceed the character cap of macros.

Last edited by p3lim : 06-05-13 at 07:25 PM.
  Reply With Quote
06-05-13, 07:35 PM   #16
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
This should do the job

Lua Code:
  1. local commands = {
  2.     [string.gsub(SLASH_CAST1, '/', '')] = true,
  3.     [string.gsub(SLASH_EQUIP1, '/', '')] = true,
  4.     [string.gsub(SLASH_USE1, '/', '')] = true,
  5.     ['cast'] = true,
  6.     ['equip'] = true,
  7.     ['use'] = true,
  8. }
  9.  
  10. hooksecurefunc('ChatEdit_InsertLink', function(link)
  11.     if(MacroFrameText and MacroFrameText:HasFocus() and string.find(link, 'item:', 1, true)) then
  12.         local macroText = MacroFrameText:GetText()
  13.         local _, _, commandName = string.find(macroText, '/(%l+)')
  14.         if(not commands[commandName]) then
  15.             local item = string.match(link, '%[(.-)%]')
  16.             if(string.find(macroText, item, 1, true)) then
  17.                 item = string.gsub(item, '%-', '%%-')
  18.  
  19.                 local newline = string.find(macroText, '\n$') and '\n' or ''
  20.                 local newMacroText = string.gsub(string.gsub(macroText, item .. '$', ''), item .. '\n$', '') .. link .. newline
  21.                 if(string.len(newMacroText) <= 255) then
  22.                     MacroFrameText:SetText(newMacroText)
  23.                 end
  24.             end
  25.         end
  26.     end
  27. end)

Last edited by p3lim : 06-06-13 at 01:50 PM.
  Reply With Quote
06-05-13, 09:23 PM   #17
Tonyleila
A Molten Giant
 
Tonyleila's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 758
Thank you for your work!
Well my description is not all that was on the original addon page. Will your code also make this possible?
Because there are cases where you don't want an item link, and you want plain text, ItemLinkMacros automatically adds plain text if your macro contains any of these strings:
/use
/cast
/equip

New slash command: /addtext
To make adding links to macros easier, I've added the slash command /addtext. As you would expect, it simply inserts the text following it into the macro edit box, including any link contained therein.
This also makes it easy to add in item links to a macro where you also have the string /use, /cast, or /equip.
__________________
Author of: LeilaUI and Aurora: Missing Textures
__________________
  Reply With Quote
06-05-13, 09:33 PM   #18
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
The only thing missing is the slashcommand, which you could just copy/paste.
  Reply With Quote
06-05-13, 10:32 PM   #19
Tonyleila
A Molten Giant
 
Tonyleila's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 758
Originally Posted by p3lim View Post
The only thing missing is the slashcommand, which you could just copy/paste.
I just copy and replaced your code with the old one of ILM and its not working. Had no errors but when trying to shift klick items into the macro window it shows item name with a slash in front of it: like /equip itemname.

May I also need a part of the old code?
__________________
Author of: LeilaUI and Aurora: Missing Textures
__________________
  Reply With Quote
06-05-13, 10:40 PM   #20
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
Originally Posted by Tonyleila View Post
I just copy and replaced your code with the old one of ILM and its not working. Had no errors but when trying to shift klick items into the macro window it shows item name with a slash in front of it: like /equip itemname.

May I also need a part of the old code?
That's the default behavior, if you want to use it for anything else you'd want to prefix the macro like you would in any case, with /say or /2 or whatever.
Write /say then shift-click, which is what I thought was the idea of it.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Search/Requests » Item Link Macros

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off