mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12: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,9 +1030,10 @@ title="%s" %s>%s</button>""" % (
|
||||||
# Undo & autosave
|
# 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"
|
reviewing = self.state == "review"
|
||||||
result = self.col.undo()
|
|
||||||
just_refresh_reviewer = False
|
just_refresh_reviewer = False
|
||||||
|
|
||||||
if result is None:
|
if result is None:
|
||||||
|
@ -1076,6 +1078,10 @@ title="%s" %s>%s</button>""" % (
|
||||||
tooltip(tr(TR.UNDO_ACTION_UNDONE, action=name))
|
tooltip(tr(TR.UNDO_ACTION_UNDONE, action=name))
|
||||||
gui_hooks.state_did_revert(name)
|
gui_hooks.state_did_revert(name)
|
||||||
self.update_undo_actions()
|
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:
|
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