mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Make the custom columns available in the Alter Tag Browser->Manage sub menu
This commit is contained in:
parent
855f0f4828
commit
51024a7d9d
@ -29,6 +29,44 @@ class TagBrowserMixin(object): # {{{
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def populate_tb_manage_menu(self, db):
|
||||||
|
from calibre.db.categories import find_categories
|
||||||
|
m = self.alter_tb.manage_menu
|
||||||
|
m.clear()
|
||||||
|
for text, func, args, cat_name in (
|
||||||
|
(_('Manage Authors'),
|
||||||
|
self.do_author_sort_edit, (self, None), 'authors'),
|
||||||
|
(_('Manage Series'),
|
||||||
|
self.do_tags_list_edit, (None, 'series'), 'series'),
|
||||||
|
(_('Manage Publishers'),
|
||||||
|
self.do_tags_list_edit, (None, 'publisher'), 'publisher'),
|
||||||
|
(_('Manage Tags'),
|
||||||
|
self.do_tags_list_edit, (None, 'tags'), 'tags'),
|
||||||
|
(_('Manage User Categories'),
|
||||||
|
self.do_edit_user_categories, (None,), 'user:'),
|
||||||
|
(_('Manage Saved Searches'),
|
||||||
|
self.do_saved_search_edit, (None,), 'search')
|
||||||
|
):
|
||||||
|
m.addAction(QIcon(I(category_icon_map[cat_name])), text,
|
||||||
|
partial(func, *args))
|
||||||
|
fm = db.new_api.field_metadata
|
||||||
|
categories = [x[0] for x in find_categories(fm) if fm.is_custom_field(x[0])]
|
||||||
|
if categories:
|
||||||
|
if len(categories) > 5:
|
||||||
|
m = m.addMenu(_('Custom columns'))
|
||||||
|
else:
|
||||||
|
m.addSeparator()
|
||||||
|
|
||||||
|
def cat_key(x):
|
||||||
|
try:
|
||||||
|
return fm[x]['name']
|
||||||
|
except Exception:
|
||||||
|
return ''
|
||||||
|
for cat in sorted(categories, key=cat_key):
|
||||||
|
name = cat_key(cat)
|
||||||
|
if name:
|
||||||
|
m.addAction(_('Manage {}').format(name), partial(self.do_tags_list_edit, None, cat))
|
||||||
|
|
||||||
def init_tag_browser_mixin(self, db):
|
def init_tag_browser_mixin(self, db):
|
||||||
self.library_view.model().count_changed_signal.connect(self.tags_view.recount)
|
self.library_view.model().count_changed_signal.connect(self.tags_view.recount)
|
||||||
self.tags_view.set_database(db, self.alter_tb)
|
self.tags_view.set_database(db, self.alter_tb)
|
||||||
@ -48,24 +86,7 @@ class TagBrowserMixin(object): # {{{
|
|||||||
self.tags_view.restriction_error.connect(self.do_restriction_error,
|
self.tags_view.restriction_error.connect(self.do_restriction_error,
|
||||||
type=Qt.QueuedConnection)
|
type=Qt.QueuedConnection)
|
||||||
self.tags_view.tag_item_delete.connect(self.do_tag_item_delete)
|
self.tags_view.tag_item_delete.connect(self.do_tag_item_delete)
|
||||||
|
self.populate_tb_manage_menu(db)
|
||||||
for text, func, args, cat_name in (
|
|
||||||
(_('Manage Authors'),
|
|
||||||
self.do_author_sort_edit, (self, None), 'authors'),
|
|
||||||
(_('Manage Series'),
|
|
||||||
self.do_tags_list_edit, (None, 'series'), 'series'),
|
|
||||||
(_('Manage Publishers'),
|
|
||||||
self.do_tags_list_edit, (None, 'publisher'), 'publisher'),
|
|
||||||
(_('Manage Tags'),
|
|
||||||
self.do_tags_list_edit, (None, 'tags'), 'tags'),
|
|
||||||
(_('Manage User Categories'),
|
|
||||||
self.do_edit_user_categories, (None,), 'user:'),
|
|
||||||
(_('Manage Saved Searches'),
|
|
||||||
self.do_saved_search_edit, (None,), 'search')
|
|
||||||
):
|
|
||||||
m = self.alter_tb.manage_menu
|
|
||||||
m.addAction(QIcon(I(category_icon_map[cat_name])), text,
|
|
||||||
partial(func, *args))
|
|
||||||
|
|
||||||
def do_restriction_error(self):
|
def do_restriction_error(self):
|
||||||
error_dialog(self.tags_view, _('Invalid search restriction'),
|
error_dialog(self.tags_view, _('Invalid search restriction'),
|
||||||
@ -528,4 +549,3 @@ class TagBrowserWidget(QWidget): # {{{
|
|||||||
self.not_found_label.setVisible(False)
|
self.not_found_label.setVisible(False)
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
@ -373,6 +373,7 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
|
|||||||
|
|
||||||
# ########################## Tags Browser ##############################
|
# ########################## Tags Browser ##############################
|
||||||
TagBrowserMixin.init_tag_browser_mixin(self, db)
|
TagBrowserMixin.init_tag_browser_mixin(self, db)
|
||||||
|
self.library_view.model().database_changed.connect(self.populate_tb_manage_menu, type=Qt.QueuedConnection)
|
||||||
|
|
||||||
# ######################## Search Restriction ##########################
|
# ######################## Search Restriction ##########################
|
||||||
if db.prefs['virtual_lib_on_startup']:
|
if db.prefs['virtual_lib_on_startup']:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user