diff --git a/aqt/addcards.py b/aqt/addcards.py index 831c91cdf..d5feb9153 100644 --- a/aqt/addcards.py +++ b/aqt/addcards.py @@ -75,7 +75,6 @@ class AddCards(QDialog): b.setEnabled(False) self.historyButton = b - # FIXME: need to make sure to clean up note on exit def setupNewNote(self, set=True): f = self.mw.col.newNote() f.tags = f.model()['tags'] diff --git a/aqt/clayout.py b/aqt/clayout.py index 0bc72361e..748b8e9df 100644 --- a/aqt/clayout.py +++ b/aqt/clayout.py @@ -11,11 +11,9 @@ from aqt.utils import saveGeom, restoreGeom, getBase, mungeQA, \ showWarning, openHelp from anki.utils import isMac, isWin -# raise Exception("Remember to disallow media&latex refs in edit.") - class CardLayout(QDialog): - def __init__(self, mw, note, ord=0, parent=None): + def __init__(self, mw, note, ord=0, parent=None, addMode=False): QDialog.__init__(self, parent or mw, Qt.Window) self.mw = aqt.mw self.parent = parent or mw @@ -24,6 +22,11 @@ class CardLayout(QDialog): self.col = self.mw.col self.mm = self.mw.col.models self.model = note.model() + self.mw.checkpoint(_("Card Layout")) + self.addMode = addMode + if addMode: + # save it to DB temporarily + note.flush() self.setupTabs() self.setupButtons() self.setWindowTitle(_("%s Layout") % self.model['name']) @@ -31,7 +34,6 @@ class CardLayout(QDialog): v1.addWidget(self.tabs) v1.addLayout(self.buttons) self.setLayout(v1) - self.mw.checkpoint(_("Card Layout")) self.redraw() restoreGeom(self, "CardLayout") self.exec_() @@ -257,6 +259,9 @@ Enter deck to place new %s cards in, or leave blank:""") % self.reject() def reject(self): + if self.addMode: + self.mw.col.db.execute("delete from notes where id = ?", + self.note.id) self.mm.save(self.model, templates=True) self.mw.reset() saveGeom(self, "CardLayout") diff --git a/aqt/editor.py b/aqt/editor.py index be3a96514..173dd75e3 100644 --- a/aqt/editor.py +++ b/aqt/editor.py @@ -330,7 +330,8 @@ class Editor(object): ord = self.card.ord else: ord = 0 - CardLayout(self.mw, self.note, ord=ord, parent=self.parentWindow) + CardLayout(self.mw, self.note, ord=ord, parent=self.parentWindow, + addMode=self.addMode) self.loadNote() # JS->Python bridge @@ -345,7 +346,8 @@ class Editor(object): (type, txt) = str.split(":", 1) self.note.fields[self.currentField] = self.mungeHTML(txt) self.mw.requireReset() - self.note.flush() + if not self.addMode: + self.note.flush() if type == "blur": if not self._keepButtons: self.disableButtons() @@ -526,7 +528,8 @@ class Editor(object): m['did'] = self.note.did m['tags'] = self.note.tags self.mw.col.models.save(m) - self.note.flush() + if not self.addMode: + self.note.flush() runHook("tagsUpdated", self.note) # Format buttons