From af539a9dae9f29640e78a3be1db757344d88d728 Mon Sep 17 00:00:00 2001 From: Bionus Date: Tue, 20 Feb 2024 21:18:30 +0100 Subject: [PATCH] feat: add new "remove" option to tag context menu (fix #3100) --- src/gui/src/tag-context-menu.cpp | 18 +++++++++++++++++- src/gui/src/tag-context-menu.h | 2 ++ .../src/models/filtering/tag-filter-list.cpp | 14 ++++++++++++++ src/lib/src/models/filtering/tag-filter-list.h | 2 ++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/gui/src/tag-context-menu.cpp b/src/gui/src/tag-context-menu.cpp index b94597d59..5c416379b 100644 --- a/src/gui/src/tag-context-menu.cpp +++ b/src/gui/src/tag-context-menu.cpp @@ -35,12 +35,19 @@ TagContextMenu::TagContextMenu(QString tag, QList allTags, QUrl browserUrl, addAction(QIcon(":/images/icons/eye-minus.png"), tr("Blacklist"), this, SLOT(blacklist())); } - // Ignore + // Ignored tags if (profile->getIgnored().contains(m_tag, Qt::CaseInsensitive)) { addAction(QIcon(":/images/icons/eye-plus.png"), tr("Don't ignore"), this, SLOT(unignore())); } else { addAction(QIcon(":/images/icons/eye-minus.png"), tr("Ignore"), this, SLOT(ignore())); } + + // Removed tags + if (profile->getRemovedTags().contains(m_tag)) { + addAction(QIcon(":/images/icons/eye-plus.png"), tr("Don't remove"), this, &TagContextMenu::unremove); + } else { + addAction(QIcon(":/images/icons/eye-minus.png"), tr("Remove"), this, &TagContextMenu::remove); + } addSeparator(); // Copy @@ -92,6 +99,15 @@ void TagContextMenu::unignore() m_profile->removeIgnored(m_tag); } +void TagContextMenu::remove() +{ + m_profile->getRemovedTags().add(m_tag); +} +void TagContextMenu::unremove() +{ + m_profile->getRemovedTags().remove(m_tag); +} + void TagContextMenu::blacklist() { m_profile->addBlacklistedTag(m_tag); diff --git a/src/gui/src/tag-context-menu.h b/src/gui/src/tag-context-menu.h index ebbf2f4c0..4bfe81128 100644 --- a/src/gui/src/tag-context-menu.h +++ b/src/gui/src/tag-context-menu.h @@ -26,6 +26,8 @@ class TagContextMenu : public QMenu void unviewitlater(); void ignore(); void unignore(); + void remove(); + void unremove(); void blacklist(); void unblacklist(); void openInNewTab(); diff --git a/src/lib/src/models/filtering/tag-filter-list.cpp b/src/lib/src/models/filtering/tag-filter-list.cpp index 94880a09a..b6617e220 100644 --- a/src/lib/src/models/filtering/tag-filter-list.cpp +++ b/src/lib/src/models/filtering/tag-filter-list.cpp @@ -19,6 +19,15 @@ void TagFilterList::add(const QStringList &words) } } +void TagFilterList::remove(const QString &word) +{ + if (word.contains('*')) { + m_starTags.removeAll(QRegularExpression::fromWildcard(word, Qt::CaseInsensitive)); + } else { + m_rawTags.removeAll(word); + } +} + void TagFilterList::clear() { m_rawTags.clear(); @@ -48,3 +57,8 @@ QList TagFilterList::filterTags(const QList &tags) const return ret; } + +bool TagFilterList::contains(const QString &word) const +{ + return m_rawTags.contains(word, Qt::CaseInsensitive); +} diff --git a/src/lib/src/models/filtering/tag-filter-list.h b/src/lib/src/models/filtering/tag-filter-list.h index 2f04b57ae..ac824a5eb 100644 --- a/src/lib/src/models/filtering/tag-filter-list.h +++ b/src/lib/src/models/filtering/tag-filter-list.h @@ -14,9 +14,11 @@ class TagFilterList public: void add(const QString &word); void add(const QStringList &words); + void remove(const QString &word); void clear(); QList filterTags(const QList &tags) const; + bool contains(const QString &word) const; private: QStringList m_rawTags;