From 75638790930e6c957231c5304be51c85e47a0f72 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 27 Nov 2008 15:58:00 +0900 Subject: [PATCH] make sure to save facts before closing editor, etc --- ankiqt/ui/addcards.py | 3 +-- ankiqt/ui/cardlist.py | 1 + ankiqt/ui/facteditor.py | 18 ++++++++++++++++++ ankiqt/ui/main.py | 1 + 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/ankiqt/ui/addcards.py b/ankiqt/ui/addcards.py index ba9944ba4..ae3a188b1 100644 --- a/ankiqt/ui/addcards.py +++ b/ankiqt/ui/addcards.py @@ -90,8 +90,7 @@ class AddCards(QDialog): def addCards(self): # make sure updated - w = self.editor.focusedEdit() - self.addButton.setFocus() + self.editor.saveFieldsNow() fact = self.editor.fact try: cards = self.parent.deck.addFact(fact) diff --git a/ankiqt/ui/cardlist.py b/ankiqt/ui/cardlist.py index bce5a614e..a59001d91 100644 --- a/ankiqt/ui/cardlist.py +++ b/ankiqt/ui/cardlist.py @@ -631,6 +631,7 @@ where id in (%s)""" % ",".join([ self.updateAfterCardChange(reset=True) def accept(self): + self.editor.saveFieldsNow() self.hide() self.deck.deleteCards(self.model.deleted.keys()) if len(self.model.deleted): diff --git a/ankiqt/ui/facteditor.py b/ankiqt/ui/facteditor.py index 9a5be27b4..6ab739cfb 100644 --- a/ankiqt/ui/facteditor.py +++ b/ankiqt/ui/facteditor.py @@ -37,6 +37,9 @@ class FactEditor(object): "Make FACT the current fact." self.fact = fact self.factState = None + if self.changeTimer: + self.changeTimer.stop() + self.changeTimer = None if self.needToRedraw(): self.drawFields(noFocus, check) else: @@ -330,6 +333,21 @@ class FactEditor(object): self.onChange() self.changeTimer = None + def saveFieldsNow(self): + "Must call this before adding cards, closing dialog, etc." + # disable timer + if self.changeTimer: + self.changeTimer.stop() + self.changeTimer = None + if self.onChange: + self.onChange() + # save fields and run features + w = self.focusedEdit() + if w: + self.onFocusLost(w) + # ensure valid + self.checkValid() + def checkValid(self): empty = [] dupe = [] diff --git a/ankiqt/ui/main.py b/ankiqt/ui/main.py index 0b2ee16d0..6060e24c7 100644 --- a/ankiqt/ui/main.py +++ b/ankiqt/ui/main.py @@ -201,6 +201,7 @@ class AnkiQt(QMainWindow): self.mainWin.fieldsArea.show() self.editor.setFact(self.currentCard.fact) elif state == "saveEdit": + self.editor.saveFieldsNow() self.deck.s.flush() return self.moveToState("auto") self.updateViews(state)