avoid hanging UI when undoing in browse screen

This commit is contained in:
Damien Elmes 2021-03-12 17:56:13 +10:00
parent 57a05a2ae3
commit 44dc3f494c
3 changed files with 21 additions and 3 deletions

View file

@ -72,8 +72,10 @@ class Checkpoint:
class BackendUndo:
name: str
UndoResult = Union[None, BackendUndo, Checkpoint, ReviewUndo]
class Collection:
sched: Union[V1Scheduler, V2Scheduler]

View file

@ -518,7 +518,7 @@ class Browser(QMainWindow):
# actions
f = self.form
# edit
qconnect(f.actionUndo.triggered, self.mw.onUndo)
qconnect(f.actionUndo.triggered, self.undo)
qconnect(f.actionInvertSelection.triggered, self.invertSelection)
qconnect(f.actionSelectNotes.triggered, self.selectNotes)
if not isMac:
@ -1498,6 +1498,16 @@ where id in %s"""
def on_tag_list_update(self) -> None:
self.sidebar.refresh()
# Undo
######################################################################
def undo(self) -> None:
# need to make sure we don't hang the UI by redrawing the card list
# during the long-running op. mw.undo will take care of the progress
# dialog
self.setUpdatesEnabled(False)
self.mw.undo(lambda _: self.setUpdatesEnabled(True))
def onUndoState(self, on: bool) -> None:
self.form.actionUndo.setEnabled(on)
if on:

View file

@ -27,8 +27,14 @@ 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, UndoResult
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