Factor out addFact logic

This commit is contained in:
Shawn M Moore 2010-02-14 17:50:45 -05:00
parent 79579676c5
commit 02c6e0c2bb

View file

@ -132,12 +132,7 @@ class AddCards(QDialog):
"str": stripHTML(fact[fact.fields[0].name]), "str": stripHTML(fact[fact.fields[0].name]),
}) })
def addCards(self): def addFact(self, fact):
# make sure updated
self.editor.saveFieldsNow()
fact = self.editor.fact
n = _("Add")
self.parent.deck.setUndoStart(n)
try: try:
fact = self.parent.deck.addFact(fact) fact = self.parent.deck.addFact(fact)
except FactInvalidError: except FactInvalidError:
@ -152,6 +147,18 @@ question or answer on all cards."""), parent=self)
return return
self.reportAddedFact(fact) self.reportAddedFact(fact)
return fact
def addCards(self):
# make sure updated
self.editor.saveFieldsNow()
fact = self.editor.fact
n = _("Add")
self.parent.deck.setUndoStart(n)
fact = self.addFact(fact)
if not fact:
return
# stop anything playing # stop anything playing
clearAudioQueue() clearAudioQueue()