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 5 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
71 changes: 71 additions & 0 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 @@ -50,6 +51,23 @@ CommandPage::CommandPage()
Command{"/command", "I made a new command HeyGuys"});
});

QItemSelectionModel *selectionModel =
view->getTableView()->selectionModel();
QObject::connect(
selectionModel, &QItemSelectionModel::currentChanged, this,
[this, view](const QModelIndex &current, const QModelIndex &previous) {
pajlada marked this conversation as resolved.
Show resolved Hide resolved
pajlada marked this conversation as resolved.
Show resolved Hide resolved
if (this->handleCommandDuplicates(view))
pajlada marked this conversation as resolved.
Show resolved Hide resolved
pajlada marked this conversation as resolved.
Show resolved Hide resolved
{
this->duplicateCommandWarning->show();
}
else
{
this->duplicateCommandWarning->hide();
}
});

bool duplicatesExist = this->handleCommandDuplicates(view);

// TODO: asyncronously check path
if (QFile(c1settingsPath()).exists())
{
Expand Down Expand Up @@ -81,8 +99,61 @@ 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");
if (duplicatesExist)
{
this->duplicateCommandWarning->show();
}
else
{
this->duplicateCommandWarning->hide();
}

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

bool CommandPage::handleCommandDuplicates(EditableModelView *view)
pajlada marked this conversation as resolved.
Show resolved Hide resolved
{
pajlada marked this conversation as resolved.
Show resolved Hide resolved
bool retval = false;
QMap<QString, QList<int>> map = *new QMap<QString, QList<int>>();
askepticaldreamer marked this conversation as resolved.
Show resolved Hide resolved
for (int i = 0; i < view->getModel()->rowCount(); i++)
{
QString commandName = 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])
{
view->getModel()->setData(view->getModel()->index(value, 0),
QColor("yellow"), Qt::ForegroundRole);
}
}
else
{
view->getModel()->setData(view->getModel()->index(map[key][0], 0),
QColor("white"), Qt::ForegroundRole);
}
}

return retval;
}

} // namespace chatterino
3 changes: 3 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 @@ -11,9 +12,11 @@ class CommandPage : public SettingsPage
{
public:
CommandPage();
bool handleCommandDuplicates(EditableModelView *view);
askepticaldreamer marked this conversation as resolved.
Show resolved Hide resolved

private:
QTimer commandsEditTimer_;
QLabel *duplicateCommandWarning;
};

} // namespace chatterino