mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Enhancement: arbitrary searches as search restrictions
Bug fix: invalid search restrictions no longer break the tag browser
This commit is contained in:
parent
e753b0fe2a
commit
faf4eddf8a
@ -443,6 +443,7 @@ class SavedSearchBoxMixin(object): # {{{
|
|||||||
# rebuild the restrictions combobox using current saved searches
|
# rebuild the restrictions combobox using current saved searches
|
||||||
self.search_restriction.clear()
|
self.search_restriction.clear()
|
||||||
self.search_restriction.addItem('')
|
self.search_restriction.addItem('')
|
||||||
|
self.search_restriction.addItem(_('*Current search'))
|
||||||
if recount:
|
if recount:
|
||||||
self.tags_view.recount()
|
self.tags_view.recount()
|
||||||
for s in p:
|
for s in p:
|
||||||
|
@ -29,13 +29,32 @@ class SearchRestrictionMixin(object):
|
|||||||
self.search_restriction.setCurrentIndex(r)
|
self.search_restriction.setCurrentIndex(r)
|
||||||
self.apply_search_restriction(r)
|
self.apply_search_restriction(r)
|
||||||
|
|
||||||
def apply_search_restriction(self, i):
|
def apply_text_search_restriction(self, search):
|
||||||
r = unicode(self.search_restriction.currentText())
|
if not search:
|
||||||
if r is not None and r != '':
|
self.search_restriction.setItemText(1, _('*Current search'))
|
||||||
restriction = 'search:"%s"'%(r)
|
self.search_restriction.setCurrentIndex(0)
|
||||||
else:
|
else:
|
||||||
restriction = ''
|
self.search_restriction.setCurrentIndex(1)
|
||||||
|
self.search_restriction.setItemText(1, search)
|
||||||
|
self._apply_search_restriction(search)
|
||||||
|
|
||||||
|
def apply_search_restriction(self, i):
|
||||||
|
self.search_restriction.setItemText(1, _('*Current search'))
|
||||||
|
if i == 1:
|
||||||
|
restriction = unicode(self.search.currentText())
|
||||||
|
if not restriction:
|
||||||
|
self.search_restriction.setCurrentIndex(0)
|
||||||
|
else:
|
||||||
|
self.search_restriction.setItemText(1, restriction)
|
||||||
|
else:
|
||||||
|
r = unicode(self.search_restriction.currentText())
|
||||||
|
if r is not None and r != '':
|
||||||
|
restriction = 'search:"%s"'%(r)
|
||||||
|
else:
|
||||||
|
restriction = ''
|
||||||
|
self._apply_search_restriction(restriction)
|
||||||
|
|
||||||
|
def _apply_search_restriction(self, restriction):
|
||||||
self.saved_search.clear()
|
self.saved_search.clear()
|
||||||
# The order below is important. Set the restriction, force a '' search
|
# The order below is important. Set the restriction, force a '' search
|
||||||
# to apply it, reset the tag browser to take it into account, then set
|
# to apply it, reset the tag browser to take it into account, then set
|
||||||
|
@ -86,6 +86,7 @@ class TagsView(QTreeView): # {{{
|
|||||||
tag_item_renamed = pyqtSignal()
|
tag_item_renamed = pyqtSignal()
|
||||||
search_item_renamed = pyqtSignal()
|
search_item_renamed = pyqtSignal()
|
||||||
drag_drop_finished = pyqtSignal(object)
|
drag_drop_finished = pyqtSignal(object)
|
||||||
|
restriction_error = pyqtSignal()
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
QTreeView.__init__(self, parent=None)
|
QTreeView.__init__(self, parent=None)
|
||||||
@ -1117,9 +1118,13 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
|
|
||||||
# Get the categories
|
# Get the categories
|
||||||
if self.search_restriction:
|
if self.search_restriction:
|
||||||
data = self.db.get_categories(sort=sort,
|
try:
|
||||||
|
data = self.db.get_categories(sort=sort,
|
||||||
icon_map=self.category_icon_map,
|
icon_map=self.category_icon_map,
|
||||||
ids=self.db.search('', return_matches=True))
|
ids=self.db.search('', return_matches=True))
|
||||||
|
except:
|
||||||
|
data = self.db.get_categories(sort=sort, icon_map=self.category_icon_map)
|
||||||
|
self.tags_view.restriction_error.emit()
|
||||||
else:
|
else:
|
||||||
data = self.db.get_categories(sort=sort, icon_map=self.category_icon_map)
|
data = self.db.get_categories(sort=sort, icon_map=self.category_icon_map)
|
||||||
|
|
||||||
@ -1822,9 +1827,15 @@ class TagBrowserMixin(object): # {{{
|
|||||||
self.tags_view.tag_item_renamed.connect(self.do_tag_item_renamed)
|
self.tags_view.tag_item_renamed.connect(self.do_tag_item_renamed)
|
||||||
self.tags_view.search_item_renamed.connect(self.saved_searches_changed)
|
self.tags_view.search_item_renamed.connect(self.saved_searches_changed)
|
||||||
self.tags_view.drag_drop_finished.connect(self.drag_drop_finished)
|
self.tags_view.drag_drop_finished.connect(self.drag_drop_finished)
|
||||||
|
self.tags_view.restriction_error.connect(self.do_restriction_error,
|
||||||
|
type=Qt.QueuedConnection)
|
||||||
self.edit_categories.clicked.connect(lambda x:
|
self.edit_categories.clicked.connect(lambda x:
|
||||||
self.do_edit_user_categories())
|
self.do_edit_user_categories())
|
||||||
|
|
||||||
|
def do_restriction_error(self):
|
||||||
|
error_dialog(self.tags_view, _('Invalid search restriction'),
|
||||||
|
_('The current search restriction is invalid'), show=True)
|
||||||
|
|
||||||
def do_add_subcategory(self, on_category_key, new_category_name=None):
|
def do_add_subcategory(self, on_category_key, new_category_name=None):
|
||||||
'''
|
'''
|
||||||
Add a subcategory to the category 'on_category'. If new_category_name is
|
Add a subcategory to the category 'on_category'. If new_category_name is
|
||||||
|
Loading…
x
Reference in New Issue
Block a user