mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Merge pull request #1295 from leon-richardt/regex-case-sensitivity
Add Setting for Case-Sensitivity in Highlights
This commit is contained in:
commit
4846479d36
|
@ -8,7 +8,7 @@ namespace chatterino {
|
||||||
|
|
||||||
// commandmodel
|
// commandmodel
|
||||||
HighlightModel::HighlightModel(QObject *parent)
|
HighlightModel::HighlightModel(QObject *parent)
|
||||||
: SignalVectorModel<HighlightPhrase>(4, parent)
|
: SignalVectorModel<HighlightPhrase>(5, parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,12 +16,13 @@ HighlightModel::HighlightModel(QObject *parent)
|
||||||
HighlightPhrase HighlightModel::getItemFromRow(
|
HighlightPhrase HighlightModel::getItemFromRow(
|
||||||
std::vector<QStandardItem *> &row, const HighlightPhrase &original)
|
std::vector<QStandardItem *> &row, const HighlightPhrase &original)
|
||||||
{
|
{
|
||||||
// key, alert, sound, regex
|
// key, alert, sound, regex, case-sensitivity
|
||||||
|
|
||||||
return HighlightPhrase{row[0]->data(Qt::DisplayRole).toString(),
|
return HighlightPhrase{row[0]->data(Qt::DisplayRole).toString(),
|
||||||
row[1]->data(Qt::CheckStateRole).toBool(),
|
row[1]->data(Qt::CheckStateRole).toBool(),
|
||||||
row[2]->data(Qt::CheckStateRole).toBool(),
|
row[2]->data(Qt::CheckStateRole).toBool(),
|
||||||
row[3]->data(Qt::CheckStateRole).toBool()};
|
row[3]->data(Qt::CheckStateRole).toBool(),
|
||||||
|
row[4]->data(Qt::CheckStateRole).toBool()};
|
||||||
}
|
}
|
||||||
|
|
||||||
// turns a row in the model into a vector item
|
// turns a row in the model into a vector item
|
||||||
|
@ -32,6 +33,7 @@ void HighlightModel::getRowFromItem(const HighlightPhrase &item,
|
||||||
setBoolItem(row[1], item.getAlert());
|
setBoolItem(row[1], item.getAlert());
|
||||||
setBoolItem(row[2], item.getSound());
|
setBoolItem(row[2], item.getSound());
|
||||||
setBoolItem(row[3], item.isRegex());
|
setBoolItem(row[3], item.isRegex());
|
||||||
|
setBoolItem(row[4], item.isCaseSensitive());
|
||||||
}
|
}
|
||||||
|
|
||||||
void HighlightModel::afterInit()
|
void HighlightModel::afterInit()
|
||||||
|
|
|
@ -15,21 +15,24 @@ public:
|
||||||
bool operator==(const HighlightPhrase &other) const
|
bool operator==(const HighlightPhrase &other) const
|
||||||
{
|
{
|
||||||
return std::tie(this->pattern_, this->sound_, this->alert_,
|
return std::tie(this->pattern_, this->sound_, this->alert_,
|
||||||
this->isRegex_) == std::tie(other.pattern_,
|
this->isRegex_, this->caseSensitive_) ==
|
||||||
other.sound_, other.alert_,
|
std::tie(other.pattern_, other.sound_, other.alert_,
|
||||||
other.isRegex_);
|
other.isRegex_, other.caseSensitive_);
|
||||||
}
|
}
|
||||||
|
|
||||||
HighlightPhrase(const QString &pattern, bool alert, bool sound,
|
HighlightPhrase(const QString &pattern, bool alert, bool sound,
|
||||||
bool isRegex)
|
bool isRegex, bool caseSensitive)
|
||||||
: pattern_(pattern)
|
: pattern_(pattern)
|
||||||
, alert_(alert)
|
, alert_(alert)
|
||||||
, sound_(sound)
|
, sound_(sound)
|
||||||
, isRegex_(isRegex)
|
, isRegex_(isRegex)
|
||||||
, regex_(isRegex_ ? pattern
|
, caseSensitive_(caseSensitive)
|
||||||
: "\\b" + QRegularExpression::escape(pattern) + "\\b",
|
, regex_(
|
||||||
QRegularExpression::CaseInsensitiveOption |
|
isRegex_ ? pattern
|
||||||
QRegularExpression::UseUnicodePropertiesOption)
|
: "\\b" + QRegularExpression::escape(pattern) + "\\b",
|
||||||
|
QRegularExpression::UseUnicodePropertiesOption |
|
||||||
|
(caseSensitive_ ? QRegularExpression::NoPatternOption
|
||||||
|
: QRegularExpression::CaseInsensitiveOption))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,11 +63,17 @@ public:
|
||||||
return this->isValid() && this->regex_.match(subject).hasMatch();
|
return this->isValid() && this->regex_.match(subject).hasMatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isCaseSensitive() const
|
||||||
|
{
|
||||||
|
return this->caseSensitive_;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString pattern_;
|
QString pattern_;
|
||||||
bool alert_;
|
bool alert_;
|
||||||
bool sound_;
|
bool sound_;
|
||||||
bool isRegex_;
|
bool isRegex_;
|
||||||
|
bool caseSensitive_;
|
||||||
QRegularExpression regex_;
|
QRegularExpression regex_;
|
||||||
};
|
};
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
@ -82,6 +91,7 @@ struct Serialize<chatterino::HighlightPhrase> {
|
||||||
chatterino::rj::set(ret, "alert", value.getAlert(), a);
|
chatterino::rj::set(ret, "alert", value.getAlert(), a);
|
||||||
chatterino::rj::set(ret, "sound", value.getSound(), a);
|
chatterino::rj::set(ret, "sound", value.getSound(), a);
|
||||||
chatterino::rj::set(ret, "regex", value.isRegex(), a);
|
chatterino::rj::set(ret, "regex", value.isRegex(), a);
|
||||||
|
chatterino::rj::set(ret, "case", value.isCaseSensitive(), a);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -93,20 +103,24 @@ struct Deserialize<chatterino::HighlightPhrase> {
|
||||||
{
|
{
|
||||||
if (!value.IsObject())
|
if (!value.IsObject())
|
||||||
{
|
{
|
||||||
return chatterino::HighlightPhrase(QString(), true, false, false);
|
return chatterino::HighlightPhrase(QString(), true, false, false,
|
||||||
|
false);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString _pattern;
|
QString _pattern;
|
||||||
bool _alert = true;
|
bool _alert = true;
|
||||||
bool _sound = false;
|
bool _sound = false;
|
||||||
bool _isRegex = false;
|
bool _isRegex = false;
|
||||||
|
bool _caseSensitive = false;
|
||||||
|
|
||||||
chatterino::rj::getSafe(value, "pattern", _pattern);
|
chatterino::rj::getSafe(value, "pattern", _pattern);
|
||||||
chatterino::rj::getSafe(value, "alert", _alert);
|
chatterino::rj::getSafe(value, "alert", _alert);
|
||||||
chatterino::rj::getSafe(value, "sound", _sound);
|
chatterino::rj::getSafe(value, "sound", _sound);
|
||||||
chatterino::rj::getSafe(value, "regex", _isRegex);
|
chatterino::rj::getSafe(value, "regex", _isRegex);
|
||||||
|
chatterino::rj::getSafe(value, "case", _caseSensitive);
|
||||||
|
|
||||||
return chatterino::HighlightPhrase(_pattern, _alert, _sound, _isRegex);
|
return chatterino::HighlightPhrase(_pattern, _alert, _sound,
|
||||||
|
_isRegex, _caseSensitive);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ namespace chatterino {
|
||||||
|
|
||||||
// commandmodel
|
// commandmodel
|
||||||
UserHighlightModel::UserHighlightModel(QObject *parent)
|
UserHighlightModel::UserHighlightModel(QObject *parent)
|
||||||
: SignalVectorModel<HighlightPhrase>(4, parent)
|
: SignalVectorModel<HighlightPhrase>(5, parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,8 @@ HighlightPhrase UserHighlightModel::getItemFromRow(
|
||||||
return HighlightPhrase{row[0]->data(Qt::DisplayRole).toString(),
|
return HighlightPhrase{row[0]->data(Qt::DisplayRole).toString(),
|
||||||
row[1]->data(Qt::CheckStateRole).toBool(),
|
row[1]->data(Qt::CheckStateRole).toBool(),
|
||||||
row[2]->data(Qt::CheckStateRole).toBool(),
|
row[2]->data(Qt::CheckStateRole).toBool(),
|
||||||
row[3]->data(Qt::CheckStateRole).toBool()};
|
row[3]->data(Qt::CheckStateRole).toBool(),
|
||||||
|
row[4]->data(Qt::CheckStateRole).toBool()};
|
||||||
}
|
}
|
||||||
|
|
||||||
// row into vector item
|
// row into vector item
|
||||||
|
@ -32,6 +33,7 @@ void UserHighlightModel::getRowFromItem(const HighlightPhrase &item,
|
||||||
setBoolItem(row[1], item.getAlert());
|
setBoolItem(row[1], item.getAlert());
|
||||||
setBoolItem(row[2], item.getSound());
|
setBoolItem(row[2], item.getSound());
|
||||||
setBoolItem(row[3], item.isRegex());
|
setBoolItem(row[3], item.isRegex());
|
||||||
|
setBoolItem(row[4], item.isCaseSensitive());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -952,7 +952,7 @@ void TwitchMessageBuilder::parseHighlights()
|
||||||
{
|
{
|
||||||
HighlightPhrase selfHighlight(
|
HighlightPhrase selfHighlight(
|
||||||
currentUsername, getSettings()->enableSelfHighlightTaskbar,
|
currentUsername, getSettings()->enableSelfHighlightTaskbar,
|
||||||
getSettings()->enableSelfHighlightSound, false);
|
getSettings()->enableSelfHighlightSound, false, false);
|
||||||
activeHighlights.emplace_back(std::move(selfHighlight));
|
activeHighlights.emplace_back(std::move(selfHighlight));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ HighlightingPage::HighlightingPage()
|
||||||
|
|
||||||
view->addRegexHelpLink();
|
view->addRegexHelpLink();
|
||||||
view->setTitles({"Pattern", "Flash\ntaskbar", "Play\nsound",
|
view->setTitles({"Pattern", "Flash\ntaskbar", "Play\nsound",
|
||||||
"Enable\nregex"});
|
"Enable\nregex", "Case-\nsensitive"});
|
||||||
view->getTableView()->horizontalHeader()->setSectionResizeMode(
|
view->getTableView()->horizontalHeader()->setSectionResizeMode(
|
||||||
QHeaderView::Fixed);
|
QHeaderView::Fixed);
|
||||||
view->getTableView()->horizontalHeader()->setSectionResizeMode(
|
view->getTableView()->horizontalHeader()->setSectionResizeMode(
|
||||||
|
@ -71,8 +71,8 @@ HighlightingPage::HighlightingPage()
|
||||||
});
|
});
|
||||||
|
|
||||||
view->addButtonPressed.connect([] {
|
view->addButtonPressed.connect([] {
|
||||||
getApp()->highlights->phrases.appendItem(
|
getApp()->highlights->phrases.appendItem(HighlightPhrase{
|
||||||
HighlightPhrase{"my phrase", true, false, false});
|
"my phrase", true, false, false, false});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,6 +87,9 @@ HighlightingPage::HighlightingPage()
|
||||||
.getElement();
|
.getElement();
|
||||||
|
|
||||||
view->addRegexHelpLink();
|
view->addRegexHelpLink();
|
||||||
|
|
||||||
|
// Case-sensitivity doesn't make sense for user names so it is
|
||||||
|
// set to "false" by default & no checkbox is shown
|
||||||
view->setTitles({"Username", "Flash\ntaskbar", "Play\nsound",
|
view->setTitles({"Username", "Flash\ntaskbar", "Play\nsound",
|
||||||
"Enable\nregex"});
|
"Enable\nregex"});
|
||||||
view->getTableView()->horizontalHeader()->setSectionResizeMode(
|
view->getTableView()->horizontalHeader()->setSectionResizeMode(
|
||||||
|
@ -103,7 +106,7 @@ HighlightingPage::HighlightingPage()
|
||||||
|
|
||||||
view->addButtonPressed.connect([] {
|
view->addButtonPressed.connect([] {
|
||||||
getApp()->highlights->highlightedUsers.appendItem(
|
getApp()->highlights->highlightedUsers.appendItem(
|
||||||
HighlightPhrase{"highlighted user", true, false,
|
HighlightPhrase{"highlighted user", true, false, false,
|
||||||
false});
|
false});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue