ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Remove /slash command from autocomplete? (https://www.esoui.com/forums/showthread.php?t=7676)

Phuein 03/17/18 03:40 PM

[SOLVED] Remove /slash command from autocomplete?
 
I added a /slash command to my addon, and then added a menu toggle to turn it on/off. When off, it's an invalid command. But the autocomplete menu still shows it! I don't want to request a UI restart. How can I remove it from autocomplete?

Code:

SLASH_COMMANDS["/myspecialcommand"] = nil
tl;dr Removes the command, but not the autocomplete.

I searched for a while but couldn't find an answer. References:
https://wiki.esoui.com/API#libraries.5Cutility
(Scroll down a bit for autocomplete section)
http://esoapi.uesp.net/100018/src/li...plete.lua.html
(Saw the Add function, but not a Remove function. Tried it, didn't work.)

Dolgubon 03/17/18 09:02 PM

Take a look at the esoui source code on github, and check out SlashCommandAutoComplete:GetAutoCompletionResults. You night just need to overmore or less paste it in your code and change just a bit, or maybe just post hook it.

sirinsidiator 03/18/18 06:35 AM

No need to overwrite anything. It should be enough to call SLASH_COMMAND_AUTO_COMPLETE:InvalidateSlashCommandCache()

Phuein 03/18/18 08:36 AM

Quote:

Originally Posted by sirinsidiator (Post 34166)
No need to overwrite anything. It should be enough to call SLASH_COMMAND_AUTO_COMPLETE:InvalidateSlashCommandCache()

Wouldn't that lose ALL the other autocompletes as well? I assume I can't just take the specific autocomplete item from:
Code:

self.possibleMatches

Shadowfen 03/18/18 09:00 AM

Just judging from the function name, it would force the autocomplete cache to refresh itself from the current values of the SLASHCOMMAND table - which you have removed your entry from. Testing is, of course, required. :)

sirinsidiator 03/18/18 09:58 AM

Removing it manually from the table when there is a nice function that will invalidate the cache for you is a bad idea. You don't know how the internal implementation will change in the future, so it might just break your addon when you do it like that. And as Shadowfen said, it will just force the slash command table from getting scanned again which is exactly what you want when you remove a command.

Phuein 03/19/18 03:52 PM

I agree with you guys. And after testing it now, I'm very surprised to see it's not working. Tried and tried, that function doesn't actually do what it should - the command when removed (verified) is still in autocomplete - made sure to save addon and restart UI and all, even restarted game (unrelated.)

I'm stumped. Any ideas? It'd suck to ask users to restart UI for this small thing. Bad implementation from dev's, eh.

sirinsidiator 03/19/18 04:09 PM

I just tried the following two commands with and without any addons enabled and it works fine for me:
Code:

/script SLASH_COMMANDS["/sleep"] = nil
/script SLASH_COMMAND_AUTO_COMPLETE:InvalidateSlashCommandCache()

After running them, the sleep command won't show up in the results for the autocomplete, where it did before.

Phuein 03/20/18 09:26 AM

Quote:

Originally Posted by sirinsidiator (Post 34192)
I just tried the following two commands with and without any addons enabled and it works fine for me:
Code:

/script SLASH_COMMANDS["/sleep"] = nil
/script SLASH_COMMAND_AUTO_COMPLETE:InvalidateSlashCommandCache()

After running them, the sleep command won't show up in the results for the autocomplete, where it did before.

SMH Of course!
Code:

/script SlashCommandAutoComplete:InvalidateSlashCommandCache()
I took the naming convention from original script, instead of globals lol. I'll try again.

Phuein 03/20/18 09:33 AM

Ok, definitely works, no issues. Cheers guys!


All times are GMT -6. The time now is 07:02 PM.

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