refresh current card on edit

This commit is contained in:
Damien Elmes 2011-04-17 02:52:03 +09:00
parent 270bfab5a7
commit 95fc3978a9
2 changed files with 20 additions and 3 deletions

View file

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

View file

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