Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Warn for commands with duplicate triggers #4322

Merged
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d2720cb
Add tooltip warning if previous command trigger was a duplicate
askepticaldreamer Jan 21, 2023
2c7a6ec
Change duplicate triggers to yellow and revert to white when fixed
askepticaldreamer Jan 22, 2023
a1c0d50
Fix formating
askepticaldreamer Jan 22, 2023
fb24cb5
Remove unneeded include and change label text
askepticaldreamer Jan 22, 2023
9f0b6f6
Fix formatting
askepticaldreamer Jan 22, 2023
7712f96
Make model view and checkCommandDuplicates private
askepticaldreamer Jan 22, 2023
8a6b93c
Fix formatting with clang-format
askepticaldreamer Jan 22, 2023
829fee4
Move duplicateCommandWarning show/hide to checkCommandDuplicates func…
askepticaldreamer Jan 22, 2023
ae1b04a
Merge branch 'master' into skep/handle-duplicate-command-names
pajlada Feb 12, 2023
4645273
Add button to re-check duplicate commands
askepticaldreamer Feb 12, 2023
c7674aa
Revert "Add button to re-check duplicate commands"
askepticaldreamer Feb 12, 2023
dafcb8d
Prevent setting data when row doesn't exist in vector
askepticaldreamer Feb 12, 2023
a4eb7f3
Updated changelog
askepticaldreamer Feb 12, 2023
4845187
Emit dataChanged signal in setData and check for duplicates on rowsIn…
askepticaldreamer Feb 15, 2023
9429380
Merge remote-tracking branch 'origin/master' into skep/handle-duplica…
pajlada Mar 16, 2024
91fe514
Update the warning label
pajlada Mar 16, 2024
21b43f3
Make the `checkCommandDuplicates` an anonymous function
pajlada Mar 16, 2024
5bea193
rename retval variable
pajlada Mar 16, 2024
f829e26
Be more sparing in the parameters we get from signals
pajlada Mar 16, 2024
b8e6f51
Remove return value from checkCommandDuplicates
pajlada Mar 16, 2024
d17bf29
nit: rename map to commands
pajlada Mar 16, 2024
d14731a
nit: Simplify row-insertion
pajlada Mar 16, 2024
f5fa02d
nit: Change the list of model rows indices from a QList to std::vector
pajlada Mar 16, 2024
e03b45a
std::unordered_map instead of QMap
pajlada Mar 16, 2024
2112dc6
rename commandName to commandTrigger
pajlada Mar 16, 2024
ce26953
UNRELATED: move c1settingsPath to newly created anon namespace
pajlada Mar 16, 2024
8c95b19
move c1SettingsPath to top
pajlada Mar 16, 2024
762384e
Add comment to the signalvectormodel stuff
pajlada Mar 16, 2024
a4c765d
nit: use this
pajlada Mar 16, 2024
f8fb5cf
comment on state of signals
pajlada Mar 16, 2024
279e60f
Merge branch 'master' into skep/handle-duplicate-command-names
pajlada Mar 16, 2024
6e54203
Merge remote-tracking branch 'origin/master' into skep/handle-duplica…
pajlada Mar 17, 2024
ca95396
Update changelog entry
pajlada Mar 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/common/SignalVectorModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ class SignalVectorModel : public QAbstractTableModel,
this->rows_[row].items, this->rows_[row].original.get());
this->vector_->insert(item, vecRow, this);
}
emit dataChanged(index, index);

return true;
}
Expand Down
73 changes: 69 additions & 4 deletions src/widgets/settingspages/CommandPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "util/StandardItemHelper.hpp"
#include "widgets/helper/EditableModelView.hpp"

#include <QColor>
#include <QHeaderView>
#include <QLabel>
#include <QPushButton>
Expand Down Expand Up @@ -38,14 +39,14 @@ CommandPage::CommandPage()
LayoutCreator<CommandPage> layoutCreator(this);
auto layout = layoutCreator.setLayoutType<QVBoxLayout>();

EditableModelView *view =
this->view =
layout.emplace<EditableModelView>(app->commands->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);
view->addButtonPressed.connect([] {
this->view->addButtonPressed.connect([] {
getApp()->commands->items.append(
Command{"/command", "I made a new command HeyGuys"});
});
Expand Down Expand Up @@ -81,8 +82,72 @@ CommandPage::CommandPage()
text->setStyleSheet("color: #bbb");
text->setOpenExternalLinks(true);

this->duplicateCommandWarning =
layout.emplace<QLabel>("Duplicate command names / triggers detected")
.getElement();
this->duplicateCommandWarning->setStyleSheet("color: yellow");
this->checkCommandDuplicates();

QPushButton *checkDuplicates = new QPushButton("Check Duplicates");
askepticaldreamer marked this conversation as resolved.
Show resolved Hide resolved
this->view->addCustomButton(checkDuplicates);
QObject::connect(checkDuplicates, &QPushButton::clicked, this, [this] {
this->checkCommandDuplicates();
});

// ---- end of layout
this->commandsEditTimer_.setSingleShot(true);
}

bool CommandPage::checkCommandDuplicates()
{
pajlada marked this conversation as resolved.
Show resolved Hide resolved
bool retval = false;
QMap<QString, QList<int>> map;
for (int i = 0; i < this->view->getModel()->rowCount(); i++)
{
QString commandName =
this->view->getModel()->index(i, 0).data().toString();
if (map.contains(commandName))
{
QList<int> value = map[commandName];
value.append(i);
map.insert(commandName, value);
}
else
{
map.insert(commandName, {i});
}
}

foreach (const QString &key, map.keys())
{
if (map[key].length() != 1)
{
retval = true;
foreach (int value, map[key])
{
this->view->getModel()->setData(
this->view->getModel()->index(value, 0), QColor("yellow"),
Qt::ForegroundRole);
}
}
else
{
this->view->getModel()->setData(
this->view->getModel()->index(map[key][0], 0), QColor("white"),
Qt::ForegroundRole);
}
}

if (retval)
{
this->duplicateCommandWarning->show();
}
else
{
this->duplicateCommandWarning->hide();
}

return retval;
}

} // namespace chatterino
5 changes: 5 additions & 0 deletions src/widgets/settingspages/CommandPage.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "widgets/helper/EditableModelView.hpp"
#include "widgets/settingspages/SettingsPage.hpp"

#include <QTextEdit>
Expand All @@ -14,6 +15,10 @@ class CommandPage : public SettingsPage

private:
QTimer commandsEditTimer_;
QLabel *duplicateCommandWarning;
EditableModelView *view;

bool checkCommandDuplicates();
};

} // namespace chatterino