remember tags & group on a per-model basis

This commit is contained in:
Damien Elmes 2011-04-18 07:16:38 +09:00
parent a13b539819
commit e26a735a49
3 changed files with 16 additions and 10 deletions

View file

@ -40,9 +40,6 @@ class AddCards(QDialog):
self.open()
self.setupNewFact()
def focusOutEvent(self, evt):
print "focus lost"
def setupEditor(self):
self.editor = aqt.editor.Editor(self.mw, self.form.fieldsArea, True)
@ -82,9 +79,7 @@ class AddCards(QDialog):
# FIXME: need to make sure to clean up fact on exit
def setupNewFact(self, set=True):
f = self.mw.deck.newFact()
if self.editor.fact:
# keep tags?
f.tags = self.editor.fact.tags
f.tags = f.model().conf['tags']
if set:
self.editor.setFact(f)
return f

View file

@ -191,7 +191,12 @@ class DeckModel(QAbstractTableModel):
######################################################################
def columnType(self, column):
try:
type = self.activeCols[column]
except:
# debugging
print column, self.activeCols
return "factFld"
return type
def columnData(self, index):

View file

@ -187,12 +187,12 @@ $(function () {
# caller is responsible for resetting fact on reset
class Editor(object):
def __init__(self, mw, widget, editableGroup=False):
def __init__(self, mw, widget, addMode=False):
self.widget = widget
self.mw = mw
self.fact = None
self.stealFocus = True
self.editableGroup = editableGroup
self.addMode = addMode
self._loaded = False
self._keepButtons = False
# current card, for card layout
@ -466,7 +466,7 @@ class Editor(object):
tb.setSpacing(12)
tb.setMargin(6)
# group
if self.editableGroup:
if self.addMode:
l = QLabel(_("Group"))
else:
l = QLabel(_("Fact Group"))
@ -501,6 +501,12 @@ class Editor(object):
return
self.fact.gid = self.mw.deck.groupId(unicode(self.group.text()))
self.fact.tags = parseTags(unicode(self.tags.text()))
if self.addMode:
# save group and tags to model
m = self.fact.model()
m.conf['gid'] = self.fact.gid
m.conf['tags'] = self.fact.tags
m.flush()
self.fact.flush()
runHook("tagsAndGroupUpdated", self.fact)