mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Tag Browser: Allow user to restore hidden categories by a right click even is all categories have been hidden
This commit is contained in:
parent
344b72e74b
commit
be1bd730e2
@ -174,74 +174,81 @@ class TagsView(QTreeView): # {{{
|
|||||||
|
|
||||||
def show_context_menu(self, point):
|
def show_context_menu(self, point):
|
||||||
index = self.indexAt(point)
|
index = self.indexAt(point)
|
||||||
if not index.isValid():
|
self.context_menu = QMenu(self)
|
||||||
return False
|
|
||||||
item = index.internalPointer()
|
|
||||||
tag_name = ''
|
|
||||||
if item.type == TagTreeItem.TAG:
|
|
||||||
tag_item = item
|
|
||||||
tag_name = item.tag.name
|
|
||||||
tag_id = item.tag.id
|
|
||||||
item = item.parent
|
|
||||||
if item.type == TagTreeItem.CATEGORY:
|
|
||||||
category = unicode(item.name.toString())
|
|
||||||
key = item.category_key
|
|
||||||
# Verify that we are working with a field that we know something about
|
|
||||||
if key not in self.db.field_metadata:
|
|
||||||
return True
|
|
||||||
|
|
||||||
self.context_menu = QMenu(self)
|
if index.isValid():
|
||||||
# If the user right-clicked on an editable item, then offer
|
item = index.internalPointer()
|
||||||
# the possibility of renaming that item
|
tag_name = ''
|
||||||
if tag_name and \
|
|
||||||
(key in ['authors', 'tags', 'series', 'publisher', 'search'] or \
|
if item.type == TagTreeItem.TAG:
|
||||||
self.db.field_metadata[key]['is_custom'] and \
|
tag_item = item
|
||||||
self.db.field_metadata[key]['datatype'] != 'rating'):
|
tag_name = item.tag.name
|
||||||
self.context_menu.addAction(_('Rename \'%s\'')%tag_name,
|
tag_id = item.tag.id
|
||||||
partial(self.context_menu_handler, action='edit_item',
|
item = item.parent
|
||||||
category=tag_item, index=index))
|
|
||||||
if key == 'authors':
|
if item.type == TagTreeItem.CATEGORY:
|
||||||
self.context_menu.addAction(_('Edit sort for \'%s\'')%tag_name,
|
category = unicode(item.name.toString())
|
||||||
partial(self.context_menu_handler,
|
key = item.category_key
|
||||||
action='edit_author_sort', index=tag_id))
|
# Verify that we are working with a field that we know something about
|
||||||
|
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))
|
||||||
|
self.context_menu.addSeparator()
|
||||||
|
# Hide/Show/Restore categories
|
||||||
|
self.context_menu.addAction(_('Hide category %s') % category,
|
||||||
|
partial(self.context_menu_handler, action='hide', category=category))
|
||||||
|
if self.hidden_categories:
|
||||||
|
m = self.context_menu.addMenu(_('Show category'))
|
||||||
|
for col in sorted(self.hidden_categories, cmp=lambda x,y: cmp(x.lower(), y.lower())):
|
||||||
|
m.addAction(col,
|
||||||
|
partial(self.context_menu_handler, action='show', category=col))
|
||||||
|
|
||||||
|
# Offer specific editors for tags/series/publishers/saved searches
|
||||||
self.context_menu.addSeparator()
|
self.context_menu.addSeparator()
|
||||||
# Hide/Show/Restore categories
|
if key in ['tags', 'publisher', 'series'] or \
|
||||||
self.context_menu.addAction(_('Hide category %s') % category,
|
self.db.field_metadata[key]['is_custom']:
|
||||||
partial(self.context_menu_handler, action='hide', category=category))
|
self.context_menu.addAction(_('Manage %s')%category,
|
||||||
if self.hidden_categories:
|
partial(self.context_menu_handler, action='open_editor',
|
||||||
m = self.context_menu.addMenu(_('Show category'))
|
category=tag_name, key=key))
|
||||||
for col in sorted(self.hidden_categories, cmp=lambda x,y: cmp(x.lower(), y.lower())):
|
elif key == 'authors':
|
||||||
m.addAction(col,
|
self.context_menu.addAction(_('Manage %s')%category,
|
||||||
partial(self.context_menu_handler, action='show', category=col))
|
partial(self.context_menu_handler, action='edit_author_sort'))
|
||||||
self.context_menu.addAction(_('Show all categories'),
|
elif key == 'search':
|
||||||
partial(self.context_menu_handler, action='defaults'))
|
self.context_menu.addAction(_('Manage Saved Searches'),
|
||||||
|
partial(self.context_menu_handler, action='manage_searches',
|
||||||
|
category=tag_name))
|
||||||
|
|
||||||
# Offer specific editors for tags/series/publishers/saved searches
|
# Always show the user categories editor
|
||||||
self.context_menu.addSeparator()
|
self.context_menu.addSeparator()
|
||||||
if key in ['tags', 'publisher', 'series'] or \
|
if category in self.db.prefs.get('user_categories', {}).keys():
|
||||||
self.db.field_metadata[key]['is_custom']:
|
self.context_menu.addAction(_('Manage User Categories'),
|
||||||
self.context_menu.addAction(_('Manage %s')%category,
|
partial(self.context_menu_handler, action='manage_categories',
|
||||||
partial(self.context_menu_handler, action='open_editor',
|
category=category))
|
||||||
category=tag_name, key=key))
|
else:
|
||||||
elif key == 'authors':
|
self.context_menu.addAction(_('Manage User Categories'),
|
||||||
self.context_menu.addAction(_('Manage %s')%category,
|
partial(self.context_menu_handler, action='manage_categories',
|
||||||
partial(self.context_menu_handler, action='edit_author_sort'))
|
category=None))
|
||||||
elif key == 'search':
|
|
||||||
self.context_menu.addAction(_('Manage Saved Searches'),
|
|
||||||
partial(self.context_menu_handler, action='manage_searches',
|
|
||||||
category=tag_name))
|
|
||||||
|
|
||||||
# Always show the user categories editor
|
if self.hidden_categories:
|
||||||
self.context_menu.addSeparator()
|
if not self.context_menu.isEmpty():
|
||||||
if category in self.db.prefs.get('user_categories', {}).keys():
|
self.context_menu.addSeparator()
|
||||||
self.context_menu.addAction(_('Manage User Categories'),
|
self.context_menu.addAction(_('Show all categories'),
|
||||||
partial(self.context_menu_handler, action='manage_categories',
|
partial(self.context_menu_handler, action='defaults'))
|
||||||
category=category))
|
|
||||||
else:
|
|
||||||
self.context_menu.addAction(_('Manage User Categories'),
|
|
||||||
partial(self.context_menu_handler, action='manage_categories',
|
|
||||||
category=None))
|
|
||||||
|
|
||||||
|
if not self.context_menu.isEmpty():
|
||||||
self.context_menu.popup(self.mapToGlobal(point))
|
self.context_menu.popup(self.mapToGlobal(point))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user