feat: Search commandpage [8/9] (#5891)

Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
apa420
2025-07-19 11:07:04 +00:00
committed by GitHub
parent f20945edc7
commit 8085d6f633
3 changed files with 38 additions and 27 deletions
+1
View File
@@ -15,6 +15,7 @@
- Minor: Allow disabling of double-click tab renaming through setting. (#6163, #6184) - 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: 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 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: Added hotkey Action for opening account selector. (#6192)
- Minor: Add a setting to change the emote and badge thumbnail size. (#6126) - 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) - Minor: Add an import and export button to image uploader settings. (#6284)
+33 -27
View File
@@ -1,14 +1,12 @@
#include "widgets/settingspages/CommandPage.hpp" #include "widgets/settingspages/CommandPage.hpp"
#include "Application.hpp" #include "Application.hpp"
#include "common/Literals.hpp" #include "common/Literals.hpp" // IWYU pragma: keep
#include "controllers/commands/Command.hpp" #include "controllers/commands/Command.hpp"
#include "controllers/commands/CommandController.hpp" #include "controllers/commands/CommandController.hpp"
#include "controllers/commands/CommandModel.hpp" #include "controllers/commands/CommandModel.hpp"
#include "singletons/Settings.hpp"
#include "util/CombinePath.hpp" #include "util/CombinePath.hpp"
#include "util/LayoutCreator.hpp" #include "util/LayoutCreator.hpp"
#include "util/StandardItemHelper.hpp"
#include "widgets/helper/EditableModelView.hpp" #include "widgets/helper/EditableModelView.hpp"
#include <QColor> #include <QColor>
@@ -87,16 +85,16 @@ CommandPage::CommandPage()
LayoutCreator<CommandPage> layoutCreator(this); LayoutCreator<CommandPage> layoutCreator(this);
auto layout = layoutCreator.setLayoutType<QVBoxLayout>(); auto layout = layoutCreator.setLayoutType<QVBoxLayout>();
auto *view = layout this->view = layout
.emplace<EditableModelView>( .emplace<EditableModelView>(
getApp()->getCommands()->createModel(nullptr)) getApp()->getCommands()->createModel(nullptr))
.getElement(); .getElement();
view->setTitles({"Trigger", "Command", "Show In\nMessage Menu"}); this->view->setTitles({"Trigger", "Command", "Show In\nMessage Menu"});
view->getTableView()->horizontalHeader()->setSectionResizeMode( this->view->getTableView()->horizontalHeader()->setSectionResizeMode(
1, QHeaderView::Stretch); 1, QHeaderView::Stretch);
// We can safely ignore this signal connection since we own the view // 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( getApp()->getCommands()->items.append(
Command{"/command", "I made a new command HeyGuys"}); Command{"/command", "I made a new command HeyGuys"});
}); });
@@ -105,7 +103,7 @@ CommandPage::CommandPage()
if (QFile(c1settingsPath()).exists()) if (QFile(c1settingsPath()).exists())
{ {
auto *button = new QPushButton("Import commands from Chatterino 1"); auto *button = new QPushButton("Import commands from Chatterino 1");
view->addCustomButton(button); this->view->addCustomButton(button);
QObject::connect(button, &QPushButton::clicked, this, [] { QObject::connect(button, &QPushButton::clicked, this, [] {
QFile c1settings(c1settingsPath()); QFile c1settings(c1settingsPath());
@@ -114,7 +112,7 @@ CommandPage::CommandPage()
QString(c1settings.readAll()) QString(c1settings.readAll())
.split(QRegularExpression("[\r\n]"), Qt::SkipEmptyParts)) .split(QRegularExpression("[\r\n]"), Qt::SkipEmptyParts))
{ {
if (int index = line.indexOf(' '); index != -1) if (auto index = line.indexOf(' '); index != -1)
{ {
getApp()->getCommands()->items.insert( getApp()->getCommands()->items.insert(
Command(line.mid(0, index), line.mid(index + 1))); 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. // 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 // 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, QObject::connect(this->view->getModel(), &QAbstractItemModel::rowsInserted,
[view, duplicateWarning]() { this, [this, duplicateWarning]() {
checkCommandDuplicates(view, duplicateWarning); checkCommandDuplicates(this->view, duplicateWarning);
}); });
QObject::connect(view->getModel(), &QAbstractItemModel::rowsRemoved, this, QObject::connect(this->view->getModel(), &QAbstractItemModel::rowsRemoved,
[view, duplicateWarning]() { this, [this, duplicateWarning]() {
checkCommandDuplicates(view, duplicateWarning); checkCommandDuplicates(this->view, duplicateWarning);
}); });
QObject::connect(view->getModel(), &QAbstractItemModel::dataChanged, this, QObject::connect(
[view, duplicateWarning](const QModelIndex &topLeft, this->view->getModel(), &QAbstractItemModel::dataChanged, this,
const QModelIndex &bottomRight, [this, duplicateWarning](const QModelIndex &topLeft,
const QVector<int> &roles) { const QModelIndex &bottomRight,
(void)topLeft; const QVector<int> &roles) {
(void)bottomRight; (void)topLeft;
if (roles.contains(Qt::EditRole)) (void)bottomRight;
{ if (roles.contains(Qt::EditRole))
checkCommandDuplicates(view, duplicateWarning); {
} checkCommandDuplicates(this->view, duplicateWarning);
}); }
});
checkCommandDuplicates(view, duplicateWarning); checkCommandDuplicates(this->view, duplicateWarning);
// ---- end of layout // ---- end of layout
this->commandsEditTimer_.setSingleShot(true); this->commandsEditTimer_.setSingleShot(true);
} }
bool CommandPage::filterElements(const QString &query)
{
std::array fields{0, 1};
return this->view->filterSearchResults(query, fields);
}
} // namespace chatterino } // namespace chatterino
@@ -6,13 +6,17 @@
namespace chatterino { namespace chatterino {
class EditableModelView;
class CommandPage : public SettingsPage class CommandPage : public SettingsPage
{ {
public: public:
CommandPage(); CommandPage();
bool filterElements(const QString &query) override;
private: private:
QTimer commandsEditTimer_; QTimer commandsEditTimer_;
EditableModelView *view;
}; };
} // namespace chatterino } // namespace chatterino