support searching for 'no tag' in editor

This commit is contained in:
Damien Elmes 2008-11-14 16:36:43 +09:00
parent 5219783182
commit 00a9b572c3

View file

@ -11,7 +11,7 @@ from ankiqt import ui
from anki.cards import cardsTable, Card from anki.cards import cardsTable, Card
from anki.facts import factsTable, fieldsTable, Fact from anki.facts import factsTable, fieldsTable, Fact
from anki.utils import fmtTimeSpan, parseTags, findTag, addTags, deleteTags, \ from anki.utils import fmtTimeSpan, parseTags, findTag, addTags, deleteTags, \
stripHTML stripHTML, ids2str
from ankiqt.ui.utils import saveGeom, restoreGeom from ankiqt.ui.utils import saveGeom, restoreGeom
from anki.errors import * from anki.errors import *
from anki.db import * from anki.db import *
@ -110,9 +110,12 @@ class DeckModel(QAbstractTableModel):
# tags # tags
tagLimit = "" tagLimit = ""
if self.tag: if self.tag:
tagLimit = "cards.id in (%s)" % ( if self.tag == "notag":
",".join([str(id) for (id, tags, pri) in self.deck.tagsList() tagLimit = "cards.id in %s" % ids2str(self.deck.cardsWithNoTags())
if findTag(self.tag, parseTags(tags))])) else:
tagLimit = "cards.id in %s" % ids2str(
[id for (id, tags, pri) in self.deck.tagsList()
if findTag(self.tag, parseTags(tags))])
# sorting # sorting
sort = "" sort = ""
ads = [] ads = []
@ -298,10 +301,10 @@ class EditDeck(QDialog):
self.alltags.sort() self.alltags.sort()
self.dialog.tagList.clear() self.dialog.tagList.clear()
self.dialog.tagList.addItems(QStringList( self.dialog.tagList.addItems(QStringList(
[_('All tags')] + self.alltags)) [_('All tags'), _('No tags')] + self.alltags))
if self.currentTag: if self.currentTag:
try: try:
idx = self.alltags.index(self.currentTag) + 1 idx = self.alltags.index(self.currentTag) + 2
except ValueError: except ValueError:
idx = 0 idx = 0
self.dialog.tagList.setCurrentIndex(idx) self.dialog.tagList.setCurrentIndex(idx)
@ -351,8 +354,10 @@ class EditDeck(QDialog):
def tagChanged(self, idx): def tagChanged(self, idx):
if idx == 0: if idx == 0:
self.currentTag = None self.currentTag = None
elif idx == 1:
self.currentTag = "notag"
else: else:
self.currentTag = self.alltags[idx-1] self.currentTag = self.alltags[idx-2]
if unicode(self.dialog.filterEdit.text()) in ( if unicode(self.dialog.filterEdit.text()) in (
u"<current>", u"<last>"): u"<current>", u"<last>"):
self.dialog.filterEdit.blockSignals(True) self.dialog.filterEdit.blockSignals(True)