Fix up completion for plugin commands

This commit is contained in:
Mm2PL 2023-02-01 00:03:32 +01:00
parent 03ad993ab4
commit 31604beed3
No known key found for this signature in database
GPG key ID: 94AC9B80EFA15ED9
4 changed files with 18 additions and 0 deletions

View file

@ -231,6 +231,10 @@ void CompletionModel::refresh(const QString &prefix, bool isFirstWord)
addString(emote.first.string, TaggedString::Type::BTTVGlobalEmote); addString(emote.first.string, TaggedString::Type::BTTVGlobalEmote);
} }
for (const auto &command : getApp()->commands->pluginCommands())
{
addString(command, TaggedString::PluginCommand);
}
// Custom Chatterino commands // Custom Chatterino commands
for (const auto &command : getApp()->commands->items) for (const auto &command : getApp()->commands->items)
{ {

View file

@ -34,6 +34,7 @@ class CompletionModel : public QAbstractListModel
CustomCommand, CustomCommand,
ChatterinoCommand, ChatterinoCommand,
TwitchCommand, TwitchCommand,
PluginCommand,
}; };
TaggedString(QString _string, Type type); TaggedString(QString _string, Type type);

View file

@ -3231,13 +3231,20 @@ bool CommandController::registerPluginCommand(const QString &commandName)
this->commands_[commandName] = [commandName](const CommandContext &ctx) { this->commands_[commandName] = [commandName](const CommandContext &ctx) {
return getApp()->plugins->tryExecPluginCommand(commandName, ctx); return getApp()->plugins->tryExecPluginCommand(commandName, ctx);
}; };
this->pluginCommands_.append(commandName);
return true; return true;
} }
bool CommandController::unregisterPluginCommand(const QString &commandName) bool CommandController::unregisterPluginCommand(const QString &commandName)
{ {
if (!this->pluginCommands_.contains(commandName))
{
return false;
}
this->pluginCommands_.removeAll(commandName);
return this->commands_.erase(commandName) != 0; return this->commands_.erase(commandName) != 0;
} }
void CommandController::registerCommand(const QString &commandName, void CommandController::registerCommand(const QString &commandName,
CommandFunctionVariants commandFunction) CommandFunctionVariants commandFunction)
{ {

View file

@ -46,6 +46,11 @@ public:
bool registerPluginCommand(const QString &commandName); bool registerPluginCommand(const QString &commandName);
bool unregisterPluginCommand(const QString &commandName); bool unregisterPluginCommand(const QString &commandName);
const QStringList &pluginCommands()
{
return this->pluginCommands_;
}
private: private:
void load(Paths &paths); void load(Paths &paths);
@ -76,6 +81,7 @@ private:
commandsSetting_; commandsSetting_;
QStringList defaultChatterinoCommandAutoCompletions_; QStringList defaultChatterinoCommandAutoCompletions_;
QStringList pluginCommands_;
}; };
} // namespace chatterino } // namespace chatterino