mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Improvements to using the current search as a restriction
This commit is contained in:
parent
b4dda27923
commit
d7f17e9a19
@ -156,8 +156,6 @@ class SearchBar(QWidget): # {{{
|
|||||||
x = ComboBoxWithHelp(self)
|
x = ComboBoxWithHelp(self)
|
||||||
x.setMaximumSize(QSize(150, 16777215))
|
x.setMaximumSize(QSize(150, 16777215))
|
||||||
x.setObjectName("search_restriction")
|
x.setObjectName("search_restriction")
|
||||||
x.setToolTip(_('Books display will be restricted to those matching the '
|
|
||||||
'selected saved search'))
|
|
||||||
l.addWidget(x)
|
l.addWidget(x)
|
||||||
parent.search_restriction = x
|
parent.search_restriction = x
|
||||||
|
|
||||||
|
@ -17,6 +17,10 @@ class SearchRestrictionMixin(object):
|
|||||||
self.search_restriction.setMinimumContentsLength(10)
|
self.search_restriction.setMinimumContentsLength(10)
|
||||||
self.search_restriction.setStatusTip(self.search_restriction.toolTip())
|
self.search_restriction.setStatusTip(self.search_restriction.toolTip())
|
||||||
self.search_count.setText(_("(all books)"))
|
self.search_count.setText(_("(all books)"))
|
||||||
|
self.search_restriction_tooltip = \
|
||||||
|
_('Books display will be restricted to those matching a '
|
||||||
|
'selected saved search')
|
||||||
|
self.search_restriction.setToolTip(self.search_restriction_tooltip)
|
||||||
|
|
||||||
def apply_named_search_restriction(self, name):
|
def apply_named_search_restriction(self, name):
|
||||||
if not name:
|
if not name:
|
||||||
@ -30,29 +34,38 @@ class SearchRestrictionMixin(object):
|
|||||||
self.apply_search_restriction(r)
|
self.apply_search_restriction(r)
|
||||||
|
|
||||||
def apply_text_search_restriction(self, search):
|
def apply_text_search_restriction(self, search):
|
||||||
|
search = unicode(search)
|
||||||
if not search:
|
if not search:
|
||||||
self.search_restriction.setItemText(1, _('*Current search'))
|
|
||||||
self.search_restriction.setCurrentIndex(0)
|
self.search_restriction.setCurrentIndex(0)
|
||||||
else:
|
else:
|
||||||
self.search_restriction.setCurrentIndex(1)
|
s = '*' + search
|
||||||
self.search_restriction.setItemText(1, search)
|
if self.search_restriction.count() > 1:
|
||||||
|
txt = unicode(self.search_restriction.itemText(2))
|
||||||
|
if txt.startswith('*'):
|
||||||
|
self.search_restriction.setItemText(2, s)
|
||||||
|
else:
|
||||||
|
self.search_restriction.insertItem(2, s)
|
||||||
|
else:
|
||||||
|
self.search_restriction.insertItem(2, s)
|
||||||
|
self.search_restriction.setCurrentIndex(2)
|
||||||
|
self.search_restriction.setToolTip('<p>' +
|
||||||
|
self.search_restriction_tooltip +
|
||||||
|
_(' or the search ') + "'" + search + "'</p>")
|
||||||
self._apply_search_restriction(search)
|
self._apply_search_restriction(search)
|
||||||
|
|
||||||
def apply_search_restriction(self, i):
|
def apply_search_restriction(self, i):
|
||||||
self.search_restriction.setItemText(1, _('*Current search'))
|
|
||||||
if i == 1:
|
if i == 1:
|
||||||
restriction = unicode(self.search.currentText())
|
self.apply_text_search_restriction(unicode(self.search.currentText()))
|
||||||
if not restriction:
|
elif i == 2 and unicode(self.search_restriction.currentText()).startswith('*'):
|
||||||
self.search_restriction.setCurrentIndex(0)
|
self.apply_text_search_restriction(
|
||||||
else:
|
unicode(self.search_restriction.currentText())[1:])
|
||||||
self.search_restriction.setItemText(1, restriction)
|
|
||||||
else:
|
else:
|
||||||
r = unicode(self.search_restriction.currentText())
|
r = unicode(self.search_restriction.currentText())
|
||||||
if r is not None and r != '':
|
if r is not None and r != '':
|
||||||
restriction = 'search:"%s"'%(r)
|
restriction = 'search:"%s"'%(r)
|
||||||
else:
|
else:
|
||||||
restriction = ''
|
restriction = ''
|
||||||
self._apply_search_restriction(restriction)
|
self._apply_search_restriction(restriction)
|
||||||
|
|
||||||
def _apply_search_restriction(self, restriction):
|
def _apply_search_restriction(self, restriction):
|
||||||
self.saved_search.clear()
|
self.saved_search.clear()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user