WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Search/Requests (https://www.wowinterface.com/forums/forumdisplay.php?f=6)
-   -   Item Link Macros (https://www.wowinterface.com/forums/showthread.php?t=45297)

Tonyleila 11-29-12 07:33 AM

Item Link Macros
 
ItemLinkMacros

Quote:

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

Vlad 11-29-12 09:02 AM

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. :D

SDPhantom 11-29-12 10:59 AM

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

Tonyleila 11-29-12 06:01 PM

Quote:

Originally Posted by SDPhantom (Post 269796)
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 ;)

SDPhantom 11-30-12 06:12 PM

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.

natassja72 12-01-12 01:07 PM

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...

Tonyleila 12-01-12 05:23 PM

Quote:

Originally Posted by natassja72 (Post 269988)
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

natassja72 12-02-12 02:31 PM

Thanks! Advertising now is made easy:))

Tonyleila 06-05-13 01:43 PM

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

Phanx 06-05-13 03:15 PM

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.

p3lim 06-05-13 03:43 PM

It's not his code though Phanx, he just wanted to apply a patch to it.

Phanx 06-05-13 03:53 PM

Doesn't matter who wrote it. The problems are still the same. :p

Tonyleila 06-05-13 05:11 PM

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 :D
However I understand that the addon maybe needs a rewrite but I don't know how...

Phanx 06-05-13 07:15 PM

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

p3lim 06-05-13 07:22 PM

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.

p3lim 06-05-13 07:35 PM

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)

Tonyleila 06-05-13 09:23 PM

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?
Quote:

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.

p3lim 06-05-13 09:33 PM

The only thing missing is the slashcommand, which you could just copy/paste.

Tonyleila 06-05-13 10:32 PM

Quote:

Originally Posted by p3lim (Post 279264)
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?

p3lim 06-05-13 10:40 PM

Quote:

Originally Posted by Tonyleila (Post 279270)
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.


All times are GMT -6. The time now is 07:14 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI