make sure to save facts before closing editor, etc

This commit is contained in:
Damien Elmes 2008-11-27 15:58:00 +09:00
parent 7f83f471e2
commit 7563879093
4 changed files with 21 additions and 2 deletions

View file

@ -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)

View file

@ -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):

View file

@ -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 = []

View file

@ -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)