mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
undo in background, and show progress window
This commit is contained in:
parent
d92f1499ff
commit
57a05a2ae3
2 changed files with 54 additions and 46 deletions
|
@ -72,6 +72,7 @@ class Checkpoint:
|
||||||
class BackendUndo:
|
class BackendUndo:
|
||||||
name: str
|
name: str
|
||||||
|
|
||||||
|
UndoResult = Union[None, BackendUndo, Checkpoint, ReviewUndo]
|
||||||
|
|
||||||
class Collection:
|
class Collection:
|
||||||
sched: Union[V1Scheduler, V2Scheduler]
|
sched: Union[V1Scheduler, V2Scheduler]
|
||||||
|
@ -794,7 +795,7 @@ table.review-log {{ {revlog_style} }}
|
||||||
is run."""
|
is run."""
|
||||||
self._undo = None
|
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 ReviewUndo if undoing a v1/v2 scheduler review.
|
||||||
Returns None if the undo queue was empty."""
|
Returns None if the undo queue was empty."""
|
||||||
# backend?
|
# backend?
|
||||||
|
|
|
@ -27,7 +27,8 @@ import aqt.toolbar
|
||||||
import aqt.webview
|
import aqt.webview
|
||||||
from anki import hooks
|
from anki import hooks
|
||||||
from anki._backend import RustBackend as _RustBackend
|
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.decks import Deck
|
||||||
from anki.hooks import runHook
|
from anki.hooks import runHook
|
||||||
from anki.sound import AVTag, SoundOrVideoTag
|
from anki.sound import AVTag, SoundOrVideoTag
|
||||||
|
@ -1029,53 +1030,58 @@ title="%s" %s>%s</button>""" % (
|
||||||
# Undo & autosave
|
# Undo & autosave
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
def onUndo(self) -> None:
|
def undo(self, on_done: Optional[Callable[[UndoResult], None]]) -> None:
|
||||||
reviewing = self.state == "review"
|
def on_done_outer(fut: Future) -> None:
|
||||||
result = self.col.undo()
|
result = fut.result()
|
||||||
just_refresh_reviewer = False
|
reviewing = self.state == "review"
|
||||||
|
just_refresh_reviewer = False
|
||||||
|
|
||||||
if result is None:
|
if result is None:
|
||||||
# should not happen
|
# should not happen
|
||||||
showInfo("nothing to undo")
|
showInfo("nothing to undo")
|
||||||
|
self.update_undo_actions()
|
||||||
|
return
|
||||||
|
|
||||||
|
elif isinstance(result, ReviewUndo):
|
||||||
|
name = tr(TR.SCHEDULING_REVIEW)
|
||||||
|
|
||||||
|
if reviewing:
|
||||||
|
# push the undone card to the top of the queue
|
||||||
|
cid = result.card.id
|
||||||
|
card = self.col.getCard(cid)
|
||||||
|
self.reviewer.cardQueue.append(card)
|
||||||
|
|
||||||
|
gui_hooks.review_did_undo(cid)
|
||||||
|
|
||||||
|
just_refresh_reviewer = True
|
||||||
|
|
||||||
|
elif isinstance(result, BackendUndo):
|
||||||
|
name = result.name
|
||||||
|
|
||||||
|
if reviewing and self.col.sched.version == 3:
|
||||||
|
# new scheduler will have taken care of updating queue
|
||||||
|
just_refresh_reviewer = True
|
||||||
|
|
||||||
|
elif isinstance(result, Checkpoint):
|
||||||
|
name = result.name
|
||||||
|
|
||||||
|
else:
|
||||||
|
assert_exhaustive(result)
|
||||||
|
assert False
|
||||||
|
|
||||||
|
if just_refresh_reviewer:
|
||||||
|
self.reviewer.nextCard()
|
||||||
|
else:
|
||||||
|
# full queue+gui reset required
|
||||||
|
self.reset()
|
||||||
|
|
||||||
|
tooltip(tr(TR.UNDO_ACTION_UNDONE, action=name))
|
||||||
|
gui_hooks.state_did_revert(name)
|
||||||
self.update_undo_actions()
|
self.update_undo_actions()
|
||||||
return
|
if on_done:
|
||||||
|
on_done(result)
|
||||||
|
|
||||||
elif isinstance(result, ReviewUndo):
|
self.taskman.with_progress(self.col.undo, on_done_outer)
|
||||||
name = tr(TR.SCHEDULING_REVIEW)
|
|
||||||
|
|
||||||
if reviewing:
|
|
||||||
# push the undone card to the top of the queue
|
|
||||||
cid = result.card.id
|
|
||||||
card = self.col.getCard(cid)
|
|
||||||
self.reviewer.cardQueue.append(card)
|
|
||||||
|
|
||||||
gui_hooks.review_did_undo(cid)
|
|
||||||
|
|
||||||
just_refresh_reviewer = True
|
|
||||||
|
|
||||||
elif isinstance(result, BackendUndo):
|
|
||||||
name = result.name
|
|
||||||
|
|
||||||
if reviewing and self.col.sched.version == 3:
|
|
||||||
# new scheduler will have taken care of updating queue
|
|
||||||
just_refresh_reviewer = True
|
|
||||||
|
|
||||||
elif isinstance(result, Checkpoint):
|
|
||||||
name = result.name
|
|
||||||
|
|
||||||
else:
|
|
||||||
assert_exhaustive(result)
|
|
||||||
assert False
|
|
||||||
|
|
||||||
if just_refresh_reviewer:
|
|
||||||
self.reviewer.nextCard()
|
|
||||||
else:
|
|
||||||
# full queue+gui reset required
|
|
||||||
self.reset()
|
|
||||||
|
|
||||||
tooltip(tr(TR.UNDO_ACTION_UNDONE, action=name))
|
|
||||||
gui_hooks.state_did_revert(name)
|
|
||||||
self.update_undo_actions()
|
|
||||||
|
|
||||||
def update_undo_actions(self) -> None:
|
def update_undo_actions(self) -> None:
|
||||||
"""Update menu text and enable/disable menu item as appropriate.
|
"""Update menu text and enable/disable menu item as appropriate.
|
||||||
|
@ -1105,6 +1111,7 @@ title="%s" %s>%s</button>""" % (
|
||||||
self.update_undo_actions()
|
self.update_undo_actions()
|
||||||
|
|
||||||
maybeEnableUndo = update_undo_actions
|
maybeEnableUndo = update_undo_actions
|
||||||
|
onUndo = undo
|
||||||
|
|
||||||
# Other menu operations
|
# Other menu operations
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
Loading…
Reference in a new issue