feat: Warn for commands with duplicate triggers (#4322)
Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
committed by
GitHub
parent
0322d37650
commit
46c5609736
@@ -47,6 +47,7 @@
|
|||||||
- Minor: 7TV emotes now have a 4x image rather than a 3x image. (#5209)
|
- Minor: 7TV emotes now have a 4x image rather than a 3x image. (#5209)
|
||||||
- Minor: Add wrappers for Lua `io` library for experimental plugins feature. (#5231)
|
- Minor: Add wrappers for Lua `io` library for experimental plugins feature. (#5231)
|
||||||
- Minor: Add permissions to experimental plugins feature. (#5231)
|
- Minor: Add permissions to experimental plugins feature. (#5231)
|
||||||
|
- Minor: Added warning message if you have multiple commands with the same trigger. (#4322)
|
||||||
- Minor: Add support to send /announce[color] commands. (#5250)
|
- Minor: Add support to send /announce[color] commands. (#5250)
|
||||||
- Minor: Added drop indicator line while dragging in tables. (#5252)
|
- Minor: Added drop indicator line while dragging in tables. (#5252)
|
||||||
- Bugfix: Fixed an issue where certain emojis did not send to Twitch chat correctly. (#4840)
|
- Bugfix: Fixed an issue where certain emojis did not send to Twitch chat correctly. (#4840)
|
||||||
|
|||||||
@@ -165,12 +165,22 @@ public:
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
int vecRow = this->getVectorIndexFromModelIndex(row);
|
int vecRow = this->getVectorIndexFromModelIndex(row);
|
||||||
|
// TODO: This is only a safety-thing for when we modify data that's being modified right now.
|
||||||
|
// It should not be necessary, but it would require some rethinking about this surrounding logic
|
||||||
|
if (vecRow >= this->vector_->readOnly()->size())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
this->vector_->removeAt(vecRow, this);
|
this->vector_->removeAt(vecRow, this);
|
||||||
|
|
||||||
assert(this->rows_[row].original);
|
assert(this->rows_[row].original);
|
||||||
TVectorItem item = this->getItemFromRow(
|
TVectorItem item = this->getItemFromRow(
|
||||||
this->rows_[row].items, this->rows_[row].original.value());
|
this->rows_[row].items, this->rows_[row].original.value());
|
||||||
this->vector_->insert(item, vecRow, this);
|
this->vector_->insert(item, vecRow, this);
|
||||||
|
|
||||||
|
QVector<int> roles = QVector<int>();
|
||||||
|
roles.append(role);
|
||||||
|
emit dataChanged(index, index, roles);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "util/StandardItemHelper.hpp"
|
#include "util/StandardItemHelper.hpp"
|
||||||
#include "widgets/helper/EditableModelView.hpp"
|
#include "widgets/helper/EditableModelView.hpp"
|
||||||
|
|
||||||
|
#include <QColor>
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
@@ -22,26 +23,73 @@
|
|||||||
#define TEXT "{1} => first word {1+} => first word and after {{ => { <a href='https://chatterino.com/help/commands'>more info</a>"
|
#define TEXT "{1} => first word {1+} => first word and after {{ => { <a href='https://chatterino.com/help/commands'>more info</a>"
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
namespace chatterino {
|
|
||||||
namespace {
|
namespace {
|
||||||
QString c1settingsPath()
|
|
||||||
|
using namespace chatterino;
|
||||||
|
|
||||||
|
QString c1settingsPath()
|
||||||
|
{
|
||||||
|
return combinePath(qgetenv("appdata"), "Chatterino\\Custom\\Commands.txt");
|
||||||
|
}
|
||||||
|
|
||||||
|
void checkCommandDuplicates(EditableModelView *view, QLabel *duplicateWarning)
|
||||||
|
{
|
||||||
|
bool foundDuplicateTrigger = false;
|
||||||
|
|
||||||
|
// Maps command triggers to model row indices
|
||||||
|
std::unordered_map<QString, std::vector<int>> commands;
|
||||||
|
|
||||||
|
for (int i = 0; i < view->getModel()->rowCount(); i++)
|
||||||
{
|
{
|
||||||
return combinePath(qgetenv("appdata"),
|
QString commandTrigger =
|
||||||
"Chatterino\\Custom\\Commands.txt");
|
view->getModel()->index(i, 0).data().toString();
|
||||||
|
commands[commandTrigger].push_back(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const auto &[commandTrigger, rowIndices] : commands)
|
||||||
|
{
|
||||||
|
assert(!rowIndices.empty());
|
||||||
|
|
||||||
|
if (rowIndices.size() > 1)
|
||||||
|
{
|
||||||
|
foundDuplicateTrigger = true;
|
||||||
|
|
||||||
|
for (const auto &rowIndex : rowIndices)
|
||||||
|
{
|
||||||
|
view->getModel()->setData(view->getModel()->index(rowIndex, 0),
|
||||||
|
QColor("yellow"), Qt::ForegroundRole);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
view->getModel()->setData(view->getModel()->index(rowIndices[0], 0),
|
||||||
|
QColor("white"), Qt::ForegroundRole);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (foundDuplicateTrigger)
|
||||||
|
{
|
||||||
|
duplicateWarning->show();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
duplicateWarning->hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
|
||||||
CommandPage::CommandPage()
|
CommandPage::CommandPage()
|
||||||
{
|
{
|
||||||
auto *app = getApp();
|
|
||||||
|
|
||||||
LayoutCreator<CommandPage> layoutCreator(this);
|
LayoutCreator<CommandPage> layoutCreator(this);
|
||||||
auto layout = layoutCreator.setLayoutType<QVBoxLayout>();
|
auto layout = layoutCreator.setLayoutType<QVBoxLayout>();
|
||||||
|
|
||||||
EditableModelView *view = layout
|
auto *view = layout
|
||||||
.emplace<EditableModelView>(
|
.emplace<EditableModelView>(
|
||||||
app->getCommands()->createModel(nullptr))
|
getIApp()->getCommands()->createModel(nullptr))
|
||||||
.getElement();
|
.getElement();
|
||||||
|
|
||||||
view->setTitles({"Trigger", "Command", "Show In\nMessage Menu"});
|
view->setTitles({"Trigger", "Command", "Show In\nMessage Menu"});
|
||||||
view->getTableView()->horizontalHeader()->setSectionResizeMode(
|
view->getTableView()->horizontalHeader()->setSectionResizeMode(
|
||||||
@@ -83,6 +131,39 @@ CommandPage::CommandPage()
|
|||||||
text->setStyleSheet("color: #bbb");
|
text->setStyleSheet("color: #bbb");
|
||||||
text->setOpenExternalLinks(true);
|
text->setOpenExternalLinks(true);
|
||||||
|
|
||||||
|
auto *duplicateWarning =
|
||||||
|
layout
|
||||||
|
.emplace<QLabel>("Multiple commands with the same trigger found. "
|
||||||
|
"Only one of the commands will work.")
|
||||||
|
.getElement();
|
||||||
|
duplicateWarning->setStyleSheet("color: yellow");
|
||||||
|
|
||||||
|
// 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(view->getModel(), &QAbstractItemModel::rowsRemoved, this,
|
||||||
|
[view, duplicateWarning]() {
|
||||||
|
checkCommandDuplicates(view, duplicateWarning);
|
||||||
|
});
|
||||||
|
|
||||||
|
QObject::connect(view->getModel(), &QAbstractItemModel::dataChanged, this,
|
||||||
|
[view, duplicateWarning](const QModelIndex &topLeft,
|
||||||
|
const QModelIndex &bottomRight,
|
||||||
|
const QVector<int> &roles) {
|
||||||
|
(void)topLeft;
|
||||||
|
(void)bottomRight;
|
||||||
|
if (roles.contains(Qt::EditRole))
|
||||||
|
{
|
||||||
|
checkCommandDuplicates(view, duplicateWarning);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
checkCommandDuplicates(view, duplicateWarning);
|
||||||
|
|
||||||
// ---- end of layout
|
// ---- end of layout
|
||||||
this->commandsEditTimer_.setSingleShot(true);
|
this->commandsEditTimer_.setSingleShot(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
#include "widgets/settingspages/SettingsPage.hpp"
|
#include "widgets/settingspages/SettingsPage.hpp"
|
||||||
|
|
||||||
#include <QTextEdit>
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|||||||
Reference in New Issue
Block a user