From f07890c178053265bfc76edfbc9a670ad60b4007 Mon Sep 17 00:00:00 2001 From: RumovZ Date: Sun, 7 Mar 2021 11:40:11 +0100 Subject: [PATCH] Ask before removing tags from collection --- ftl/core/browsing.ftl | 2 ++ qt/aqt/sidebar.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/ftl/core/browsing.ftl b/ftl/core/browsing.ftl index 06160d468..222843473 100644 --- a/ftl/core/browsing.ftl +++ b/ftl/core/browsing.ftl @@ -134,3 +134,5 @@ browsing-edited-today = Edited browsing-sidebar-due-today = Due browsing-sidebar-untagged = Untagged browsing-sidebar-overdue = Overdue +browsing-sidebar-remove-tag = Are you sure you want to delete the tag “{ $name }” from { $count } notes? +browsing-sidebar-remove-tags = Are you sure you want to delete all selected tags from { $count } notes? diff --git a/qt/aqt/sidebar.py b/qt/aqt/sidebar.py index 20ada84cd..2709335ed 100644 --- a/qt/aqt/sidebar.py +++ b/qt/aqt/sidebar.py @@ -1142,6 +1142,8 @@ class SidebarTreeView(QTreeView): def _remove_tags(self, _item: SidebarItem) -> None: tags = self._selected_tags() + if not self.ask_remove_tags(tags): + return def do_remove() -> None: self.col._backend.expunge_tags(" ".join(tags)) @@ -1349,3 +1351,19 @@ class SidebarTreeView(QTreeView): for item in self._selected_items() if item.item_type == SidebarItemType.TAG ] + + def ask_remove_tags(self, tags: List[str]) -> bool: + count = len( + self.col.find_notes( + self.col.build_search_string( + *(SearchNode(tag=tag) for tag in tags), joiner="OR" + ) + ) + ) + if not count: + return True + if len(tags) == 1: + return askUser( + tr(TR.BROWSING_SIDEBAR_REMOVE_TAG, name=tags[0], count=count) + ) + return askUser(tr(TR.BROWSING_SIDEBAR_REMOVE_TAGS, count=count))