From 8085d6f633da2347afa8aa0a2ba3f76a3926d600 Mon Sep 17 00:00:00 2001 From: apa420 <17131426+apa420@users.noreply.github.com> Date: Sat, 19 Jul 2025 11:07:04 +0000 Subject: [PATCH] feat: Search commandpage [8/9] (#5891) Co-authored-by: Rasmus Karlsson --- CHANGELOG.md | 1 + src/widgets/settingspages/CommandPage.cpp | 60 +++++++++++++---------- src/widgets/settingspages/CommandPage.hpp | 4 ++ 3 files changed, 38 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae46497a..bcc9e9be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - Minor: Allow disabling of double-click tab renaming through setting. (#6163, #6184) - Minor: The JSON selector in the upload response can now query arrays using their indices like `foo.0`. (#6193) - Minor: Made nicknames searchable in the Settings dialog search bar. (#5886) +- Minor: Made commands searchable using the Settings dialog search bar. (#5891) - Minor: Added hotkey Action for opening account selector. (#6192) - Minor: Add a setting to change the emote and badge thumbnail size. (#6126) - Minor: Add an import and export button to image uploader settings. (#6284) diff --git a/src/widgets/settingspages/CommandPage.cpp b/src/widgets/settingspages/CommandPage.cpp index 2ce5ff96..efff8029 100644 --- a/src/widgets/settingspages/CommandPage.cpp +++ b/src/widgets/settingspages/CommandPage.cpp @@ -1,14 +1,12 @@ #include "widgets/settingspages/CommandPage.hpp" #include "Application.hpp" -#include "common/Literals.hpp" +#include "common/Literals.hpp" // IWYU pragma: keep #include "controllers/commands/Command.hpp" #include "controllers/commands/CommandController.hpp" #include "controllers/commands/CommandModel.hpp" -#include "singletons/Settings.hpp" #include "util/CombinePath.hpp" #include "util/LayoutCreator.hpp" -#include "util/StandardItemHelper.hpp" #include "widgets/helper/EditableModelView.hpp" #include @@ -87,16 +85,16 @@ CommandPage::CommandPage() LayoutCreator layoutCreator(this); auto layout = layoutCreator.setLayoutType(); - auto *view = layout + this->view = layout .emplace( getApp()->getCommands()->createModel(nullptr)) .getElement(); - view->setTitles({"Trigger", "Command", "Show In\nMessage Menu"}); - view->getTableView()->horizontalHeader()->setSectionResizeMode( + this->view->setTitles({"Trigger", "Command", "Show In\nMessage Menu"}); + this->view->getTableView()->horizontalHeader()->setSectionResizeMode( 1, QHeaderView::Stretch); // We can safely ignore this signal connection since we own the view - std::ignore = view->addButtonPressed.connect([] { + std::ignore = this->view->addButtonPressed.connect([] { getApp()->getCommands()->items.append( Command{"/command", "I made a new command HeyGuys"}); }); @@ -105,7 +103,7 @@ CommandPage::CommandPage() if (QFile(c1settingsPath()).exists()) { auto *button = new QPushButton("Import commands from Chatterino 1"); - view->addCustomButton(button); + this->view->addCustomButton(button); QObject::connect(button, &QPushButton::clicked, this, [] { QFile c1settings(c1settingsPath()); @@ -114,7 +112,7 @@ CommandPage::CommandPage() QString(c1settings.readAll()) .split(QRegularExpression("[\r\n]"), Qt::SkipEmptyParts)) { - if (int index = line.indexOf(' '); index != -1) + if (auto index = line.indexOf(' '); index != -1) { getApp()->getCommands()->items.insert( Command(line.mid(0, index), line.mid(index + 1))); @@ -137,32 +135,40 @@ CommandPage::CommandPage() // NOTE: These signals mean that the duplicate check happens in the middle of a row being moved, where he index can be wrong. // This should be reconsidered, or potentially changed in the signalvectormodel. Or maybe we rely on a SignalVectorModel signal instead - QObject::connect(view->getModel(), &QAbstractItemModel::rowsInserted, this, - [view, duplicateWarning]() { - checkCommandDuplicates(view, duplicateWarning); + QObject::connect(this->view->getModel(), &QAbstractItemModel::rowsInserted, + this, [this, duplicateWarning]() { + checkCommandDuplicates(this->view, duplicateWarning); }); - QObject::connect(view->getModel(), &QAbstractItemModel::rowsRemoved, this, - [view, duplicateWarning]() { - checkCommandDuplicates(view, duplicateWarning); + QObject::connect(this->view->getModel(), &QAbstractItemModel::rowsRemoved, + this, [this, duplicateWarning]() { + checkCommandDuplicates(this->view, duplicateWarning); }); - QObject::connect(view->getModel(), &QAbstractItemModel::dataChanged, this, - [view, duplicateWarning](const QModelIndex &topLeft, - const QModelIndex &bottomRight, - const QVector &roles) { - (void)topLeft; - (void)bottomRight; - if (roles.contains(Qt::EditRole)) - { - checkCommandDuplicates(view, duplicateWarning); - } - }); + QObject::connect( + this->view->getModel(), &QAbstractItemModel::dataChanged, this, + [this, duplicateWarning](const QModelIndex &topLeft, + const QModelIndex &bottomRight, + const QVector &roles) { + (void)topLeft; + (void)bottomRight; + if (roles.contains(Qt::EditRole)) + { + checkCommandDuplicates(this->view, duplicateWarning); + } + }); - checkCommandDuplicates(view, duplicateWarning); + checkCommandDuplicates(this->view, duplicateWarning); // ---- end of layout this->commandsEditTimer_.setSingleShot(true); } +bool CommandPage::filterElements(const QString &query) +{ + std::array fields{0, 1}; + + return this->view->filterSearchResults(query, fields); +} + } // namespace chatterino diff --git a/src/widgets/settingspages/CommandPage.hpp b/src/widgets/settingspages/CommandPage.hpp index d88c00a6..b095dc94 100644 --- a/src/widgets/settingspages/CommandPage.hpp +++ b/src/widgets/settingspages/CommandPage.hpp @@ -6,13 +6,17 @@ namespace chatterino { +class EditableModelView; + class CommandPage : public SettingsPage { public: CommandPage(); + bool filterElements(const QString &query) override; private: QTimer commandsEditTimer_; + EditableModelView *view; }; } // namespace chatterino