This commit is contained in:
Damien Elmes 2014-05-12 15:34:12 +09:00
commit 380080416f
6 changed files with 110 additions and 22 deletions

View file

@ -513,6 +513,9 @@ class Browser(QMainWindow):
self.setTabOrder(self.form.searchEdit, self.form.tableView)
self.form.searchEdit.setCompleter(None)
self.form.searchEdit.addItems(self.mw.pm.profile['searchHistory'])
self.connect(self.form.searchEdit.lineEdit(),
SIGNAL("returnPressed()"),
self.onSearch)
def onSearch(self, reset=True):
"Careful: if reset is true, the current note is saved."
@ -753,6 +756,7 @@ by clicking on one on the left."""))
self.form.tree.clear()
root = self.form.tree
self._systemTagTree(root)
self._favTree(root)
self._decksTree(root)
self._modelTree(root)
self._userTagTree(root)
@ -815,6 +819,18 @@ by clicking on one on the left."""))
item.setIcon(0, QIcon(":/icons/" + icon))
return root
def _favTree(self, root):
saved = self.col.conf.get('savedFilters', [])
if not saved:
# Don't add favourites to tree if none saved
return
root = self.CallbackItem(root, _("My Searches"), None)
root.setExpanded(True)
root.setIcon(0, QIcon(":/icons/emblem-favorite-dark.png"))
for name, filt in saved.items():
item = self.CallbackItem(root, name, lambda s=filt: self.setFilter(s))
item.setIcon(0, QIcon(":/icons/emblem-favorite-dark.png"))
def _userTagTree(self, root):
for t in sorted(self.col.tags.all()):
if t.lower() == "marked" or t.lower() == "leech":
@ -1723,3 +1739,87 @@ a { margin-right: 1em; }
self.browser.addTags()
elif l == "deletetag":
self.browser.deleteTags()
# Favourites button
######################################################################
class FavouritesLineEdit(QLineEdit):
buttonClicked = pyqtSignal(bool)
def __init__(self, mw, browser, parent=None):
super(FavouritesLineEdit, self).__init__(parent)
self.mw = mw
self.browser = browser
# add conf if missing
if not self.mw.col.conf.has_key('savedFilters'):
self.mw.col.conf['savedFilters'] = {}
self.button = QToolButton(self)
self.button.setStyleSheet('border: 0px;')
self.button.setCursor(Qt.ArrowCursor)
self.button.clicked.connect(self.buttonClicked.emit)
self.setIcon(':/icons/emblem-favorite-off.png')
# flag to raise save or delete dialog on button click
self.doSave = True
# name of current saved filter (if query matches)
self.name = None
self.buttonClicked.connect(self.onClicked)
self.connect(self, SIGNAL("textEdited(QString)"), self.updateButton)
def resizeEvent(self, event):
buttonSize = self.button.sizeHint()
frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
self.button.move(self.rect().right() - frameWidth - buttonSize.width(),
(self.rect().bottom() - buttonSize.height() + 1) / 2)
super(FavouritesLineEdit, self).resizeEvent(event)
def setIcon(self, path):
self.button.setIcon(QIcon(path))
def setText(self, txt):
super(FavouritesLineEdit, self).setText(txt)
self.updateButton()
def updateButton(self, reset=True):
# If search text is a saved query, switch to the delete button.
# Otherwise show save button.
txt = unicode(self.text()).strip()
for key, value in self.mw.col.conf['savedFilters'].items():
if txt == value:
self.doSave = False
self.name = key
self.setIcon(QIcon(":/icons/emblem-favorite.png"))
return
self.doSave = True
self.setIcon(QIcon(":/icons/emblem-favorite-off.png"))
def onClicked(self):
if self.doSave:
self.saveClicked()
else:
self.deleteClicked()
def saveClicked(self):
txt = unicode(self.text()).strip()
dlg = QInputDialog(self)
dlg.setInputMode(QInputDialog.TextInput)
dlg.setLabelText(_("The current search terms will be added as a new "
"item in the sidebar.\n"
"Search name:"))
dlg.setWindowTitle(_("Save search"))
ok = dlg.exec_()
name = dlg.textValue()
if ok:
self.mw.col.conf['savedFilters'][name] = txt
self.updateButton()
self.browser.setupTree()
def deleteClicked(self):
msg = _('Remove "%s" from your saved searches?') % self.name
ok = QMessageBox.question(self, _('Remove search'),
msg, QMessageBox.Yes, QMessageBox.No)
if ok == QMessageBox.Yes:
self.mw.col.conf['savedFilters'].pop(self.name, None)
self.updateButton()
self.browser.setupTree()

View file

@ -79,6 +79,9 @@ class ImportDialog(QDialog):
self.updateDelimiterButtonText()
self.frm.allowHTML.setChecked(self.mw.pm.profile.get('allowHTML', True))
self.frm.importMode.setCurrentIndex(self.mw.pm.profile.get('importMode', 1))
# import button
b = QPushButton(_("Import"))
self.frm.buttonBox.addButton(b, QDialogButtonBox.AcceptRole)
self.exec_()
def setupOptions(self):
@ -87,8 +90,6 @@ class ImportDialog(QDialog):
self.mw, self.frm.modelArea, label=False)
self.deck = aqt.deckchooser.DeckChooser(
self.mw, self.frm.deckArea, label=False)
self.connect(self.frm.importButton, SIGNAL("clicked()"),
self.doImport)
def modelChanged(self):
self.importer.model = self.mw.col.models.current()
@ -138,8 +139,8 @@ you can enter it here. Use \\t to represent tab."""),
d = `d`
txt = _("Fields separated by: %s") % d
self.frm.autoDetect.setText(txt)
def doImport(self, update=False):
def accept(self):
self.importer.mapping = self.mapping
if not self.importer.mappingOk():
showWarning(
@ -249,7 +250,7 @@ you can enter it here. Use \\t to represent tab."""),
QDialog.reject(self)
def helpRequested(self):
openHelp("FileImport")
openHelp("importing")
def showUnicodeWarning():

View file

@ -35,6 +35,8 @@
<file>icons/editclear.png</file>
<file>icons/view-statistics.png</file>
<file>icons/emblem-favorite.png</file>
<file>icons/emblem-favorite-dark.png</file>
<file>icons/emblem-favorite-off.png</file>
<file>icons/view-pim-calendar.png</file>
<file>icons/anki-tag.png</file>
<file>icons/edit-redo.png</file>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View file

@ -94,20 +94,6 @@
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="importButton">
<property name="text">
<string>&amp;Import</string>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="0">
<widget class="QScrollArea" name="mappingArea">
<property name="sizePolicy">
@ -133,8 +119,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>402</width>
<height>206</height>
<width>529</width>
<height>251</height>
</rect>
</property>
</widget>
@ -158,7 +144,6 @@
</layout>
</widget>
<tabstops>
<tabstop>importButton</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>