Add decorator to save editor in sidebar

This commit is contained in:
RumovZ 2021-03-11 22:25:18 +01:00
parent 9bf93573da
commit 538afd94bc
2 changed files with 14 additions and 7 deletions

View File

@ -24,6 +24,7 @@ from aqt.utils import (
TR,
askUser,
getOnlyText,
save_browser_editor,
show_invalid_search_error,
showInfo,
showWarning,
@ -1142,10 +1143,8 @@ class SidebarTreeView(QTreeView):
self.mw.deckBrowser.refresh()
self.mw.update_undo_actions()
def remove_tags(self, item: SidebarItem) -> None:
self.browser.editor.saveNow(lambda: self._remove_tags(item))
def _remove_tags(self, _item: SidebarItem) -> None:
@save_browser_editor
def remove_tags(self, _item: SidebarItem) -> None:
tags = self._selected_tags()
def do_remove() -> int:
@ -1195,10 +1194,8 @@ class SidebarTreeView(QTreeView):
self.browser.model.beginReset()
self.mw.taskman.with_progress(do_rename, on_done)
@save_browser_editor
def delete_decks(self, _item: SidebarItem) -> None:
self.browser.editor.saveNow(self._delete_decks)
def _delete_decks(self) -> None:
def do_delete() -> int:
return self.mw.col.decks.remove(dids)

View File

@ -986,3 +986,13 @@ def save_editor(func: Callable) -> Callable:
return decorated
def save_browser_editor(func: Callable) -> Callable:
"""Call editor.saveNow with the decorated method as callback. The method's owner
must hold a reference to the Editor's Browser.
"""
def decorated(self: Any, *args: Any, **kwargs: Any) -> None:
self.browser.editor.saveNow(lambda: func(self, *args, **kwargs))
return decorated