fix tag saving, remember added tags without having to reopen, fix ret in add

This commit is contained in:
Damien Elmes 2008-12-05 19:25:09 +09:00
parent 707ae75bd8
commit a3ac8e3c0a
4 changed files with 13 additions and 2 deletions

View file

@ -8,7 +8,7 @@ import ankiqt.forms
import anki
from anki.facts import Fact
from anki.errors import *
from anki.utils import stripHTML
from anki.utils import stripHTML, parseTags
from ankiqt.ui.utils import saveGeom, restoreGeom, saveSplitter, restoreSplitter
from ankiqt import ui
@ -51,14 +51,16 @@ class AddCards(QDialog):
self.dialog.buttonBox.addButton(self.addButton,
QDialogButtonBox.ActionRole)
self.addButton.setShortcut(_("Ctrl+Return"))
self.addButton.setDefault(True)
self.addButton.setAutoDefault(False)
s = QShortcut(QKeySequence(_("Ctrl+Enter")), self)
s.connect(s, SIGNAL("activated()"), self.addButton, SLOT("click()"))
self.connect(self.addButton, SIGNAL("clicked()"), self.addCards)
self.closeButton = QPushButton(_("Close"))
self.closeButton.setAutoDefault(False)
self.dialog.buttonBox.addButton(self.closeButton,
QDialogButtonBox.RejectRole)
self.helpButton = QPushButton(_("Help"))
self.helpButton.setAutoDefault(False)
self.dialog.buttonBox.addButton(self.helpButton,
QDialogButtonBox.HelpRole)
self.connect(self.helpButton, SIGNAL("clicked()"), self.helpRequested)
@ -118,6 +120,8 @@ question or answer on all cards. Can't proceed."""), parent=self)
f = self.parent.deck.newFact()
f.tags = self.parent.deck.lastTags
self.editor.setFact(f, check=True)
# let completer know our extra tags
self.editor.tags.addTags(parseTags(self.parent.deck.lastTags))
self.maybeSave()
def closeEvent(self, evt):

View file

@ -359,6 +359,7 @@ class FactEditor(object):
w = self.focusedEdit()
if w:
self.onFocusLost(w)
self.onTagChange()
# ensure valid
self.checkValid()

View file

@ -52,6 +52,7 @@ class ModelChooser(QHBoxLayout):
label = QLabel(_("<b>Cards</b>:"))
self.addWidget(label)
self.cards = QPushButton()
self.cards.setAutoDefault(False)
self.connect(self.cards, SIGNAL("clicked()"), self.onCardChange)
self.addWidget(self.cards)
self.drawCardModels()

View file

@ -25,6 +25,11 @@ class TagEdit(QLineEdit):
self.model.setStringList(
QStringList(tags))
def addTags(self, tags):
l = list(set([unicode(x) for x in list(self.model.stringList())] +
tags))
self.model.setStringList(QStringList(l))
def focusOutEvent(self, evt):
QLineEdit.focusOutEvent(self, evt)
self.emit(SIGNAL("lostFocus"))