From 95fc3978a97a5f048f81a57bba8cb6000f010f0a Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sun, 17 Apr 2011 02:52:03 +0900 Subject: [PATCH] refresh current card on edit --- aqt/browser.py | 16 ++++++++++++++++ aqt/editor.py | 7 ++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/aqt/browser.py b/aqt/browser.py index fc000f460..d02f44473 100644 --- a/aqt/browser.py +++ b/aqt/browser.py @@ -48,6 +48,15 @@ class DeckModel(QAbstractTableModel): self.cardObjs[id] = self.deck.getCard(id) return self.cardObjs[id] + def refreshFact(self, fact): + refresh = False + for c in fact.cards(): + if c.id in self.cardObjs: + del self.cardObjs[c.id] + refresh = True + if refresh: + self.emit(SIGNAL("layoutChanged()")) + # Model interface ###################################################################### @@ -473,6 +482,9 @@ class Browser(QMainWindow): self.showCardInfo(self.card) self.updateToggles() + def refreshCurrentCard(self, fact): + self.model.refreshFact(fact) + # Headers & sorting ###################################################################### @@ -882,10 +894,14 @@ where id in %s""" % ids2str(sf)) def setupHooks(self): addHook("checkpoint", self.onCheckpoint) addHook("reset", self.onReset) + addHook("editTimer", self.refreshCurrentCard) + addHook("editFocusLost", self.refreshCurrentCard) def teardownHooks(self): removeHook("reset", self.onReset) removeHook("checkpoint", self.onCheckpoint) + removeHook("editTimer", self.refreshCurrentCard) + removeHook("editFocusLost", self.refreshCurrentCard) def onCheckpoint(self): if self.mw.form.actionUndo.isEnabled(): diff --git a/aqt/editor.py b/aqt/editor.py index 0d222639d..0b8183218 100644 --- a/aqt/editor.py +++ b/aqt/editor.py @@ -314,13 +314,13 @@ class Editor(object): (type, txt) = str.split(":", 1) self.fact.fields[self.currentField] = self.mungeHTML(txt) self.mw.requireReset() + self.fact.flush() if type == "blur": if not self._keepButtons: self.disableButtons() - runHook("editor.focusLost", self.fact) + runHook("editFocusLost", self.fact) else: - runHook("editor.keyPressed", self.fact) - self.fact.flush() + runHook("editTimer", self.fact) self.checkValid() # focused into field? elif str.startswith("focus"): @@ -474,6 +474,7 @@ class Editor(object): self.fact.updateCardGids() self.fact.tags = parseTags(unicode(self.tags.text())) self.fact.flush() + runHook("tagsAndGroupUpdated", self.fact) # Format buttons ######################################################################