Enable deleting multiple saved searches

This commit is contained in:
RumovZ 2021-03-01 09:41:41 +01:00
parent e199bf0b47
commit f4aeb0c097
2 changed files with 22 additions and 5 deletions

View File

@ -21,6 +21,11 @@ browsing-change-note-type2 = Change Note Type...
browsing-change-to = Change { $val } to:
browsing-clear-unused = Clear Unused
browsing-clear-unused-tags = Clear Unused Tags
browsing-confirm-saved-searches-deletion =
{ $count ->
[one] Are you sure you want to delete the selected saved search?
*[other] Are you sure you want to delete the { $count } selected saved searches?
}
browsing-created = Created
browsing-ctrlandshiftande = Ctrl+Shift+E
browsing-current-deck = Current Deck

View File

@ -353,7 +353,7 @@ class SidebarTreeView(QTreeView):
),
SidebarItemType.SAVED_SEARCH: (
(tr(TR.ACTIONS_RENAME), self.rename_saved_search),
(tr(TR.ACTIONS_DELETE), self.remove_saved_search),
(tr(TR.ACTIONS_DELETE), self.remove_saved_searches),
),
SidebarItemType.NOTETYPE: ((tr(TR.ACTIONS_MANAGE), self.manage_notetype),),
SidebarItemType.SAVED_SEARCH_ROOT: (
@ -1177,12 +1177,17 @@ class SidebarTreeView(QTreeView):
def _set_saved_searches(self, searches: Dict[str, str]) -> None:
self.col.set_config(self._saved_searches_key, searches)
def remove_saved_search(self, item: SidebarItem) -> None:
name = item.name
if not askUser(tr(TR.BROWSING_REMOVE_FROM_YOUR_SAVED_SEARCHES, val=name)):
def remove_saved_searches(self, _item: SidebarItem) -> None:
selected = self._selected_saved_searches()
if len(selected) == 1:
query = tr(TR.BROWSING_REMOVE_FROM_YOUR_SAVED_SEARCHES, val=selected[0])
else:
query = tr(TR.BROWSING_CONFIRM_SAVED_SEARCHES_DELETION, count=len(selected))
if not askUser(query):
return
conf = self._get_saved_searches()
del conf[name]
for name in selected:
del conf[name]
self._set_saved_searches(conf)
self.refresh()
@ -1234,3 +1239,10 @@ class SidebarTreeView(QTreeView):
for item in self._selected_items()
if item.item_type == SidebarItemType.DECK
]
def _selected_saved_searches(self) -> List[str]:
return [
item.name
for item in self._selected_items()
if item.item_type == SidebarItemType.SAVED_SEARCH
]