From a3ac8e3c0a25ad6020d4e1d0e3aa31a0f0c3c24b Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 5 Dec 2008 19:25:09 +0900 Subject: [PATCH] fix tag saving, remember added tags without having to reopen, fix ret in add --- ankiqt/ui/addcards.py | 8 ++++++-- ankiqt/ui/facteditor.py | 1 + ankiqt/ui/modelchooser.py | 1 + ankiqt/ui/tagedit.py | 5 +++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ankiqt/ui/addcards.py b/ankiqt/ui/addcards.py index 2d3acdf1d..b71c8b70c 100644 --- a/ankiqt/ui/addcards.py +++ b/ankiqt/ui/addcards.py @@ -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): diff --git a/ankiqt/ui/facteditor.py b/ankiqt/ui/facteditor.py index 2c1e3a58d..f55b76d49 100644 --- a/ankiqt/ui/facteditor.py +++ b/ankiqt/ui/facteditor.py @@ -359,6 +359,7 @@ class FactEditor(object): w = self.focusedEdit() if w: self.onFocusLost(w) + self.onTagChange() # ensure valid self.checkValid() diff --git a/ankiqt/ui/modelchooser.py b/ankiqt/ui/modelchooser.py index db612b251..f63998df4 100644 --- a/ankiqt/ui/modelchooser.py +++ b/ankiqt/ui/modelchooser.py @@ -52,6 +52,7 @@ class ModelChooser(QHBoxLayout): label = QLabel(_("Cards:")) self.addWidget(label) self.cards = QPushButton() + self.cards.setAutoDefault(False) self.connect(self.cards, SIGNAL("clicked()"), self.onCardChange) self.addWidget(self.cards) self.drawCardModels() diff --git a/ankiqt/ui/tagedit.py b/ankiqt/ui/tagedit.py index 5a6d12ee1..749621a62 100644 --- a/ankiqt/ui/tagedit.py +++ b/ankiqt/ui/tagedit.py @@ -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"))