From 31604beed3daef297dcafb5ab303ecb15d5bf524 Mon Sep 17 00:00:00 2001 From: Mm2PL Date: Wed, 1 Feb 2023 00:03:32 +0100 Subject: [PATCH] Fix up completion for plugin commands --- src/common/CompletionModel.cpp | 4 ++++ src/common/CompletionModel.hpp | 1 + src/controllers/commands/CommandController.cpp | 7 +++++++ src/controllers/commands/CommandController.hpp | 6 ++++++ 4 files changed, 18 insertions(+) diff --git a/src/common/CompletionModel.cpp b/src/common/CompletionModel.cpp index 08bddf2e8..b7f2f879f 100644 --- a/src/common/CompletionModel.cpp +++ b/src/common/CompletionModel.cpp @@ -231,6 +231,10 @@ void CompletionModel::refresh(const QString &prefix, bool isFirstWord) addString(emote.first.string, TaggedString::Type::BTTVGlobalEmote); } + for (const auto &command : getApp()->commands->pluginCommands()) + { + addString(command, TaggedString::PluginCommand); + } // Custom Chatterino commands for (const auto &command : getApp()->commands->items) { diff --git a/src/common/CompletionModel.hpp b/src/common/CompletionModel.hpp index c2670c08e..a1b1c882b 100644 --- a/src/common/CompletionModel.hpp +++ b/src/common/CompletionModel.hpp @@ -34,6 +34,7 @@ class CompletionModel : public QAbstractListModel CustomCommand, ChatterinoCommand, TwitchCommand, + PluginCommand, }; TaggedString(QString _string, Type type); diff --git a/src/controllers/commands/CommandController.cpp b/src/controllers/commands/CommandController.cpp index e4014c122..6e3a41350 100644 --- a/src/controllers/commands/CommandController.cpp +++ b/src/controllers/commands/CommandController.cpp @@ -3231,13 +3231,20 @@ bool CommandController::registerPluginCommand(const QString &commandName) this->commands_[commandName] = [commandName](const CommandContext &ctx) { return getApp()->plugins->tryExecPluginCommand(commandName, ctx); }; + this->pluginCommands_.append(commandName); return true; } bool CommandController::unregisterPluginCommand(const QString &commandName) { + if (!this->pluginCommands_.contains(commandName)) + { + return false; + } + this->pluginCommands_.removeAll(commandName); return this->commands_.erase(commandName) != 0; } + void CommandController::registerCommand(const QString &commandName, CommandFunctionVariants commandFunction) { diff --git a/src/controllers/commands/CommandController.hpp b/src/controllers/commands/CommandController.hpp index 3a8834415..ee4b2f9e2 100644 --- a/src/controllers/commands/CommandController.hpp +++ b/src/controllers/commands/CommandController.hpp @@ -46,6 +46,11 @@ public: bool registerPluginCommand(const QString &commandName); bool unregisterPluginCommand(const QString &commandName); + const QStringList &pluginCommands() + { + return this->pluginCommands_; + } + private: void load(Paths &paths); @@ -76,6 +81,7 @@ private: commandsSetting_; QStringList defaultChatterinoCommandAutoCompletions_; + QStringList pluginCommands_; }; } // namespace chatterino