mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
Use same constraints for deleting by key press ...
... as for deleting via context menu, i.e., delete key does nothing if not all selected items are of the same type.
This commit is contained in:
parent
9ba02b5ca6
commit
53665f0cf4
1 changed files with 19 additions and 12 deletions
|
@ -553,7 +553,7 @@ class SidebarTreeView(QTreeView):
|
||||||
if not self.isPersistentEditorOpen(index):
|
if not self.isPersistentEditorOpen(index):
|
||||||
self._on_search(index)
|
self._on_search(index)
|
||||||
elif event.key() == Qt.Key_Delete:
|
elif event.key() == Qt.Key_Delete:
|
||||||
self._on_delete(index)
|
self._on_delete_key(index)
|
||||||
else:
|
else:
|
||||||
super().keyPressEvent(event)
|
super().keyPressEvent(event)
|
||||||
|
|
||||||
|
@ -641,14 +641,23 @@ class SidebarTreeView(QTreeView):
|
||||||
if search_node := item.search_node:
|
if search_node := item.search_node:
|
||||||
self.update_search(search_node)
|
self.update_search(search_node)
|
||||||
|
|
||||||
def _on_delete(self, index: QModelIndex) -> None:
|
def _on_delete_key(self, index: QModelIndex) -> None:
|
||||||
if item := self.model().item_for_index(index):
|
if item := self.model().item_for_index(index):
|
||||||
if item.item_type == SidebarItemType.SAVED_SEARCH:
|
if self._enable_delete(item):
|
||||||
self.remove_saved_searches(item)
|
self._on_delete(item)
|
||||||
elif item.item_type == SidebarItemType.DECK:
|
|
||||||
self.delete_decks(item)
|
def _enable_delete(self, item: SidebarItem) -> bool:
|
||||||
elif item.item_type == SidebarItemType.TAG:
|
return item.item_type.is_deletable() and all(
|
||||||
self.remove_tags(item)
|
s.item_type == item.item_type for s in self._selected_items()
|
||||||
|
)
|
||||||
|
|
||||||
|
def _on_delete(self, item: SidebarItem) -> None:
|
||||||
|
if item.item_type == SidebarItemType.SAVED_SEARCH:
|
||||||
|
self.remove_saved_searches(item)
|
||||||
|
elif item.item_type == SidebarItemType.DECK:
|
||||||
|
self.delete_decks(item)
|
||||||
|
elif item.item_type == SidebarItemType.TAG:
|
||||||
|
self.remove_tags(item)
|
||||||
|
|
||||||
def _on_expansion(self, idx: QModelIndex) -> None:
|
def _on_expansion(self, idx: QModelIndex) -> None:
|
||||||
if self.current_search:
|
if self.current_search:
|
||||||
|
@ -1059,10 +1068,8 @@ class SidebarTreeView(QTreeView):
|
||||||
def _maybe_add_delete_action(
|
def _maybe_add_delete_action(
|
||||||
self, menu: QMenu, item: SidebarItem, index: QModelIndex
|
self, menu: QMenu, item: SidebarItem, index: QModelIndex
|
||||||
) -> None:
|
) -> None:
|
||||||
if item.item_type.is_deletable() and all(
|
if self._enable_delete(item):
|
||||||
s.item_type == item.item_type for s in self._selected_items()
|
menu.addAction(tr(TR.ACTIONS_DELETE), lambda: self._on_delete(item))
|
||||||
):
|
|
||||||
menu.addAction(tr(TR.ACTIONS_DELETE), lambda: self._on_delete(index))
|
|
||||||
|
|
||||||
def _maybe_add_rename_action(
|
def _maybe_add_rename_action(
|
||||||
self, menu: QMenu, item: SidebarItem, index: QModelIndex
|
self, menu: QMenu, item: SidebarItem, index: QModelIndex
|
||||||
|
|
Loading…
Reference in a new issue