1) Fix bug where search was shown as a searchable category

2) Add search for item
This commit is contained in:
Charles Haley 2011-01-25 13:33:27 +00:00
parent d9c9accdda
commit 8b62f6be45

View File

@ -98,6 +98,7 @@ class TagsView(QTreeView): # {{{
self.collapse_model = 'disable'
else:
self.collapse_model = gprefs['tags_browser_partition_method']
self.search_icon = QIcon(I('search.png'))
def set_pane_is_visible(self, to_what):
pv = self.pane_is_visible
@ -199,6 +200,10 @@ class TagsView(QTreeView): # {{{
if action == 'manage_categories':
self.user_category_edit.emit(category)
return
if action == 'search':
self.tags_marked.emit(('not ' if negate else '') +
category + ':"=' + key + '"')
return
if action == 'search_category':
self.tags_marked.emit(category + ':' + str(not negate))
return
@ -208,6 +213,7 @@ class TagsView(QTreeView): # {{{
if action == 'edit_author_sort':
self.author_sort_edit.emit(self, index)
return
if action == 'hide':
self.hidden_categories.add(category)
elif action == 'show':
@ -248,19 +254,36 @@ class TagsView(QTreeView): # {{{
if key not in self.db.field_metadata:
return True
# If the user right-clicked on an editable item, then offer
# the possibility of renaming that item
if tag_name and \
(key in ['authors', 'tags', 'series', 'publisher', 'search'] or \
self.db.field_metadata[key]['is_custom'] and \
self.db.field_metadata[key]['datatype'] != 'rating'):
self.context_menu.addAction(_('Rename \'%s\'')%tag_name,
partial(self.context_menu_handler, action='edit_item',
category=tag_item, index=index))
if key == 'authors':
self.context_menu.addAction(_('Edit sort for \'%s\'')%tag_name,
partial(self.context_menu_handler,
action='edit_author_sort', index=tag_id))
# Did the user click on a leaf node?
if tag_name:
# If the user right-clicked on an editable item, then offer
# the possibility of renaming that item.
if key in ['authors', 'tags', 'series', 'publisher', 'search'] or \
(self.db.field_metadata[key]['is_custom'] and \
self.db.field_metadata[key]['datatype'] != 'rating'):
# Add the 'rename' items
self.context_menu.addAction(_('Rename %s')%tag_name,
partial(self.context_menu_handler, action='edit_item',
category=tag_item, index=index))
if key == 'authors':
self.context_menu.addAction(_('Edit sort for %s')%tag_name,
partial(self.context_menu_handler,
action='edit_author_sort', index=tag_id))
# Add the search for value items
n = tag_name
c = category
if self.db.field_metadata[key]['datatype'] == 'rating':
n = str(len(tag_name))
elif self.db.field_metadata[key]['kind'] in ['user', 'search']:
c = tag_item.tag.category
self.context_menu.addAction(self.search_icon,
_('Search for %s')%tag_name,
partial(self.context_menu_handler, action='search',
category=c, key=n, negate=False))
self.context_menu.addAction(self.search_icon,
_('Search for everything but %s')%tag_name,
partial(self.context_menu_handler, action='search',
category=c, key=n, negate=True))
self.context_menu.addSeparator()
# Hide/Show/Restore categories
self.context_menu.addAction(_('Hide category %s') % category,
@ -272,14 +295,15 @@ class TagsView(QTreeView): # {{{
partial(self.context_menu_handler, action='show', category=col))
# search by category
self.context_menu.addAction(
_('Search for books in category %s')%category,
partial(self.context_menu_handler, action='search_category',
category=key, negate=False))
self.context_menu.addAction(
_('Search for books not in category %s')%category,
partial(self.context_menu_handler, action='search_category',
category=key, negate=True))
if key != 'search':
self.context_menu.addAction(self.search_icon,
_('Search for books in category %s')%category,
partial(self.context_menu_handler, action='search_category',
category=key, negate=False))
self.context_menu.addAction(self.search_icon,
_('Search for books not in category %s')%category,
partial(self.context_menu_handler, action='search_category',
category=key, negate=True))
# Offer specific editors for tags/series/publishers/saved searches
self.context_menu.addSeparator()
if key in ['tags', 'publisher', 'series'] or \