undo in background, and show progress window

This commit is contained in:
Damien Elmes 2021-03-12 17:54:56 +10:00
parent d92f1499ff
commit 57a05a2ae3
2 changed files with 54 additions and 46 deletions

View file

@ -72,6 +72,7 @@ class Checkpoint:
class BackendUndo:
name: str
UndoResult = Union[None, BackendUndo, Checkpoint, ReviewUndo]
class Collection:
sched: Union[V1Scheduler, V2Scheduler]
@ -794,7 +795,7 @@ table.review-log {{ {revlog_style} }}
is run."""
self._undo = None
def undo(self) -> Union[None, BackendUndo, Checkpoint, ReviewUndo]:
def undo(self) -> UndoResult:
"""Returns ReviewUndo if undoing a v1/v2 scheduler review.
Returns None if the undo queue was empty."""
# backend?

View file

@ -27,7 +27,8 @@ import aqt.toolbar
import aqt.webview
from anki import hooks
from anki._backend import RustBackend as _RustBackend
from anki.collection import BackendUndo, Checkpoint, Collection, Config, ReviewUndo
from anki.collection import BackendUndo, Checkpoint, Collection, Config, \
ReviewUndo, UndoResult
from anki.decks import Deck
from anki.hooks import runHook
from anki.sound import AVTag, SoundOrVideoTag
@ -1029,9 +1030,10 @@ title="%s" %s>%s</button>""" % (
# Undo & autosave
##########################################################################
def onUndo(self) -> None:
def undo(self, on_done: Optional[Callable[[UndoResult], None]]) -> None:
def on_done_outer(fut: Future) -> None:
result = fut.result()
reviewing = self.state == "review"
result = self.col.undo()
just_refresh_reviewer = False
if result is None:
@ -1076,6 +1078,10 @@ title="%s" %s>%s</button>""" % (
tooltip(tr(TR.UNDO_ACTION_UNDONE, action=name))
gui_hooks.state_did_revert(name)
self.update_undo_actions()
if on_done:
on_done(result)
self.taskman.with_progress(self.col.undo, on_done_outer)
def update_undo_actions(self) -> None:
"""Update menu text and enable/disable menu item as appropriate.
@ -1105,6 +1111,7 @@ title="%s" %s>%s</button>""" % (
self.update_undo_actions()
maybeEnableUndo = update_undo_actions
onUndo = undo
# Other menu operations
##########################################################################