Ask before removing tags from collection

This commit is contained in:
RumovZ 2021-03-07 11:40:11 +01:00
parent 6c4d6457fb
commit f07890c178
2 changed files with 20 additions and 0 deletions

View File

@ -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?

View File

@ -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))