From 44dc3f494c24c3591b466d43cec5203b22ff8e2b Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 12 Mar 2021 17:56:13 +1000 Subject: [PATCH] avoid hanging UI when undoing in browse screen --- pylib/anki/collection.py | 2 ++ qt/aqt/browser.py | 12 +++++++++++- qt/aqt/main.py | 10 ++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/pylib/anki/collection.py b/pylib/anki/collection.py index 2bb63b7c1..3cf5a3ea6 100644 --- a/pylib/anki/collection.py +++ b/pylib/anki/collection.py @@ -72,8 +72,10 @@ class Checkpoint: class BackendUndo: name: str + UndoResult = Union[None, BackendUndo, Checkpoint, ReviewUndo] + class Collection: sched: Union[V1Scheduler, V2Scheduler] diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index 93e9330c1..0ff9db88f 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -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: diff --git a/qt/aqt/main.py b/qt/aqt/main.py index 2b061dbba..eef4e99d0 100644 --- a/qt/aqt/main.py +++ b/qt/aqt/main.py @@ -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