mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
fix lookup, bug in addcards, tag completer
This commit is contained in:
parent
2a66095eed
commit
37f96fb5a7
5 changed files with 28 additions and 29 deletions
|
@ -98,8 +98,6 @@ class AddCards(QDialog):
|
|||
ui.utils.showInfo(_(
|
||||
"Some fields are missing or not unique."),
|
||||
parent=self, help="AddItems#AddError")
|
||||
if w:
|
||||
w.setFocus()
|
||||
return
|
||||
if not cards:
|
||||
ui.utils.showWarning(_("""\
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
from PyQt4.QtGui import *
|
||||
from PyQt4.QtCore import *
|
||||
import re, os, sys
|
||||
from anki.utils import parseTags, stripHTML, tidyHTML
|
||||
from anki.utils import stripHTML, tidyHTML, canonifyTags
|
||||
from anki.sound import playFromText
|
||||
import anki.sound
|
||||
from ankiqt import ui
|
||||
|
@ -381,7 +381,7 @@ class FactEditor(object):
|
|||
self.factState = "invalid"
|
||||
|
||||
def onTagChange(self):
|
||||
self.fact.tags = unicode(self.tags.text())
|
||||
self.fact.tags = canonifyTags(unicode(self.tags.text()))
|
||||
if self.onChange:
|
||||
self.onChange(None)
|
||||
self.fact.setModified(textChanged=True)
|
||||
|
|
|
@ -16,7 +16,8 @@ class Lookup(object):
|
|||
|
||||
def selection(self, function):
|
||||
"Get the selected text and look it up with FUNCTION."
|
||||
text = unicode(self.main.mainWin.mainText.textCursor().selectedText())
|
||||
text = unicode(self.main.mainWin.mainText.selectedText())
|
||||
text = text.strip()
|
||||
if "\n" in text:
|
||||
self.main.setStatus(_("Can't look up a selection with a newline."))
|
||||
return
|
||||
|
|
|
@ -75,6 +75,7 @@ class AnkiQt(QMainWindow):
|
|||
self.mainWin.setupUi(self)
|
||||
self.mainWin.mainText = ui.view.AnkiWebView(self.mainWin.mainTextFrame)
|
||||
self.mainWin.mainText.setObjectName("mainText")
|
||||
self.mainWin.mainText.setFocusPolicy(Qt.ClickFocus)
|
||||
self.mainWin.vboxlayout.addWidget(self.mainWin.mainText)
|
||||
self.mainWin.buttonWidget = QWidget(self.mainWin.mainTextFrame)
|
||||
self.mainWin.buttonWidget.setObjectName("buttonWidget")
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
|
||||
from PyQt4.QtGui import *
|
||||
from PyQt4.QtCore import *
|
||||
from anki.utils import parseTags
|
||||
from anki.utils import parseTags, canonifyTags, joinTags
|
||||
|
||||
class TagEdit(QLineEdit):
|
||||
|
||||
def __init__(self, parent, *args):
|
||||
QLineEdit.__init__(self, parent, *args)
|
||||
self.model = QStringListModel()
|
||||
self.completer = TagCompleter(self.model, parent)
|
||||
self.completer = TagCompleter(self.model, parent, self)
|
||||
self.completer.setCompletionMode(QCompleter.UnfilteredPopupCompletion)
|
||||
self.completer.setCaseSensitivity(Qt.CaseInsensitive)
|
||||
self.setCompleter(self.completer)
|
||||
|
@ -18,21 +18,9 @@ class TagEdit(QLineEdit):
|
|||
def setDeck(self, deck):
|
||||
"Set the current deck, updating list of available tags."
|
||||
self.deck = deck
|
||||
tags = self.deck.allTags()
|
||||
tags = self.deck.allUserTags()
|
||||
self.model.setStringList(
|
||||
QStringList(sorted(tags)))
|
||||
|
||||
def keyPressEvent(self, evt):
|
||||
if evt.key() in (Qt.Key_Enter,
|
||||
Qt.Key_Return):
|
||||
evt.accept()
|
||||
cur = self.completer.currentCompletion()
|
||||
if cur and not str(cur).strip().endswith(","):
|
||||
self.setText(self.completer.currentCompletion())
|
||||
else:
|
||||
self.completer.popup().close()
|
||||
else:
|
||||
QLineEdit.keyPressEvent(self, evt)
|
||||
QStringList(tags))
|
||||
|
||||
def focusOutEvent(self, evt):
|
||||
QLineEdit.focusOutEvent(self, evt)
|
||||
|
@ -40,18 +28,29 @@ class TagEdit(QLineEdit):
|
|||
|
||||
class TagCompleter(QCompleter):
|
||||
|
||||
def __init__(self, *args):
|
||||
QCompleter.__init__(self, *args)
|
||||
def __init__(self, model, parent, edit, *args):
|
||||
QCompleter.__init__(self, model, parent)
|
||||
self.tags = []
|
||||
self.edit = edit
|
||||
|
||||
def splitPath(self, str):
|
||||
self.tags = parseTags(unicode(str))
|
||||
if self.tags:
|
||||
return QStringList(self.tags[-1])
|
||||
return QStringList("")
|
||||
str = unicode(str)
|
||||
if str.strip().startswith(","):
|
||||
self.cursor = 0
|
||||
return QStringList("")
|
||||
self.tags = parseTags(str)
|
||||
self.tags.append(u"")
|
||||
p = self.edit.cursorPosition()
|
||||
self.cursor = str.count(",", 0, p)
|
||||
return QStringList(self.tags[self.cursor])
|
||||
|
||||
def pathFromIndex(self, idx):
|
||||
ret = QCompleter.pathFromIndex(self, idx)
|
||||
self.tags = self.tags[0:-1]
|
||||
self.tags.append(unicode(ret))
|
||||
if u"" not in self.tags:
|
||||
self.tags.append(u"")
|
||||
self.tags[self.cursor] = unicode(ret)
|
||||
try:
|
||||
self.tags.remove(u"")
|
||||
except ValueError:
|
||||
pass
|
||||
return ", ".join(self.tags)
|
||||
|
|
Loading…
Reference in a new issue