def onUndo(self) -> None: n = self.col.undoName() if not n: return cid = self.col.undo() if cid and self.state == "review": card = self.col.getCard(cid) self.col.sched.reset() self.reviewer.cardQueue.append(card) self.reviewer.nextCard() gui_hooks.review_did_undo(cid) else: self.reset() tooltip(_("Reverted to state prior to '%s'.") % n.lower()) gui_hooks.state_did_revert(n) self.maybeEnableUndo()
def _legacy_undo(*, parent: QWidget) -> None: from aqt import mw assert mw assert mw.col reviewing = mw.state == "review" just_refresh_reviewer = False result = mw.col.undo_legacy() if result is None: # should not happen showInfo("nothing to undo", parent=parent) mw.update_undo_actions() return elif isinstance(result, LegacyReviewUndo): name = tr.scheduling_review() if reviewing: # push the undone card to the top of the queue cid = result.card.id card = mw.col.get_card(cid) mw.reviewer.cardQueue.append(card) gui_hooks.review_did_undo(cid) just_refresh_reviewer = True elif isinstance(result, LegacyCheckpoint): name = result.name else: assert_exhaustive(result) assert False if just_refresh_reviewer: mw.reviewer.nextCard() else: # full queue+gui reset required mw.reset() tooltip(tr.undo_action_undone(action=name), parent=parent) gui_hooks.state_did_revert(name) mw.update_undo_actions()