Clean up tag browser context and config menus a bit.

- When right-clicking in tag browser white space, remove any context menu that depends on having an index.
- Remove general subcategorization menu options from the context menu. These are global, not part of context for the current index.
- Add a menu option to the config menu to open Prefs / L&F / Tag browser. This permits easily getting to the global subcat and display options, avoiding adding more menu lines to the config menu.
This commit is contained in:
Charles Haley 2025-01-10 15:56:50 +00:00
parent d592a8d338
commit cd0d2eb53b
2 changed files with 65 additions and 82 deletions

View File

@ -879,6 +879,10 @@ class TagBrowserWidget(QFrame): # {{{
action=ac, group=_('Tag browser')) action=ac, group=_('Tag browser'))
ac.triggered.connect(self.filter_book_list) ac.triggered.connect(self.filter_book_list)
l.m.addSeparator()
ac = l.m.addAction(QIcon.ic('config.png'), _('Preferences / Look & feel / Tag browser'))
ac.triggered.connect(self.show_tag_browser_preferences)
ac = QAction(parent) ac = QAction(parent)
parent.addAction(ac) parent.addAction(ac)
parent.keyboard.register_shortcut('tag browser toggle item', parent.keyboard.register_shortcut('tag browser toggle item',
@ -897,6 +901,11 @@ class TagBrowserWidget(QFrame): # {{{
# self.leak_test_timer.timeout.connect(self.test_for_leak) # self.leak_test_timer.timeout.connect(self.test_for_leak)
# self.leak_test_timer.start(5000) # self.leak_test_timer.start(5000)
def show_tag_browser_preferences(self):
from calibre.gui2.ui import get_gui
get_gui().iactions['Preferences'].do_config(initial_plugin=('Interface', 'Look & Feel', 'tag_browser_tab'),
close_after_initial=True)
def about_to_show_configure_menu(self): def about_to_show_configure_menu(self):
ac = self.alter_tb.m.show_counts_action ac = self.alter_tb.m.show_counts_action
p = gprefs['tag_browser_show_counts'] p = gprefs['tag_browser_show_counts']

View File

@ -1203,90 +1203,64 @@ class TagsView(QTreeView): # {{{
self.context_menu.addSeparator() self.context_menu.addSeparator()
add_show_hidden_categories() add_show_hidden_categories()
# partitioning. If partitioning is active, provide a way to turn it on or if key is not None:
# off for this category. # partitioning. If partitioning is active, provide a way to turn it on or
if gprefs['tags_browser_partition_method'] != 'disable' and key is not None: # off for this category.
m = self.context_menu if gprefs['tags_browser_partition_method'] != 'disable':
p = self.db.prefs.get('tag_browser_dont_collapse', gprefs['tag_browser_dont_collapse']) m = self.context_menu
# Use the prefix for a user category. The p = self.db.prefs.get('tag_browser_dont_collapse', gprefs['tag_browser_dont_collapse'])
if key.startswith('@'): # Use the prefix for a user category. The
k = key.partition('.')[0] if key.startswith('@'):
cat = k[1:] k = key.partition('.')[0]
cat = k[1:]
else:
k = key
cat = category
if k in p:
a = m.addAction(_('Sub-categorize {}').format(cat),
partial(self.context_menu_handler, action='collapse_category',
category=cat, key=k, extra=p))
else:
a = m.addAction(_("Don't sub-categorize {}").format(cat),
partial(self.context_menu_handler, action='dont_collapse_category',
category=cat, key=k, extra=p))
a.setIcon(QIcon.ic('config.png'))
# Add expand menu items
self.context_menu.addSeparator()
m = self.context_menu.addMenu(_('Expand or collapse'))
try:
node_name = self._model.get_node(index).tag.name
except AttributeError:
pass
else: else:
k = key if self.has_children(index) and not self.isExpanded(index):
cat = category m.addAction(self.plus_icon,
if k in p: _('Expand {0}').format(node_name), partial(self.expand, index))
a = m.addAction(_('Sub-categorize {}').format(cat), if self.has_unexpanded_children(index):
partial(self.context_menu_handler, action='collapse_category', m.addAction(self.plus_icon,
category=cat, key=k, extra=p)) _('Expand {0} and its children').format(node_name),
else: partial(self.expand_node_and_children, index))
a = m.addAction(_("Don't sub-categorize {}").format(cat),
partial(self.context_menu_handler, action='dont_collapse_category',
category=cat, key=k, extra=p))
a.setIcon(QIcon.ic('config.png'))
# Set the partitioning scheme
m = self.context_menu.addMenu(_('Change sub-categorization scheme'))
m.setIcon(QIcon.ic('config.png'))
da = m.addAction(_('Disable'),
partial(self.context_menu_handler, action='categorization', category='disable'))
fla = m.addAction(_('By first letter'),
partial(self.context_menu_handler, action='categorization', category='first letter'))
pa = m.addAction(_('Partition'),
partial(self.context_menu_handler, action='categorization', category='partition'))
if self.collapse_model == 'disable':
da.setCheckable(True)
da.setChecked(True)
elif self.collapse_model == 'first letter':
fla.setCheckable(True)
fla.setChecked(True)
else:
pa.setCheckable(True)
pa.setChecked(True)
if config['sort_tags_by'] != "name": # Add menu items to collapse parent nodes
fla.setEnabled(False) idx = index
m.hovered.connect(self.collapse_menu_hovered) paths = []
fla.setToolTip(_('First letter is usable only when sorting by name')) while True:
# Apparently one cannot set a tooltip to empty, so use a star and # First walk up the node tree getting the displayed names of
# deal with it in the hover method # expanded parent nodes
da.setToolTip('*') node = self._model.get_node(idx)
pa.setToolTip('*') if node.type == TagTreeItem.ROOT:
break
# Add expand menu items if self.has_children(idx) and self.isExpanded(idx):
self.context_menu.addSeparator() # leaf nodes don't have children so can't be expanded.
m = self.context_menu.addMenu(_('Expand or collapse')) # Also the leaf node might be collapsed
try: paths.append((node.tag.name, idx))
node_name = self._model.get_node(index).tag.name idx = self._model.parent(idx)
except AttributeError: for p in paths:
pass # Now add the menu items
else: m.addAction(self.minus_icon,
if self.has_children(index) and not self.isExpanded(index): _("Collapse {0}").format(p[0]), partial(self.collapse_node, p[1]))
m.addAction(self.plus_icon, m.addAction(self.minus_icon, _('Collapse all'), self.collapseAll)
_('Expand {0}').format(node_name), partial(self.expand, index))
if self.has_unexpanded_children(index):
m.addAction(self.plus_icon,
_('Expand {0} and its children').format(node_name),
partial(self.expand_node_and_children, index))
# Add menu items to collapse parent nodes
idx = index
paths = []
while True:
# First walk up the node tree getting the displayed names of
# expanded parent nodes
node = self._model.get_node(idx)
if node.type == TagTreeItem.ROOT:
break
if self.has_children(idx) and self.isExpanded(idx):
# leaf nodes don't have children so can't be expanded.
# Also the leaf node might be collapsed
paths.append((node.tag.name, idx))
idx = self._model.parent(idx)
for p in paths:
# Now add the menu items
m.addAction(self.minus_icon,
_("Collapse {0}").format(p[0]), partial(self.collapse_node, p[1]))
m.addAction(self.minus_icon, _('Collapse all'), self.collapseAll)
# Ask plugins if they have any actions to add to the context menu # Ask plugins if they have any actions to add to the context menu
from calibre.gui2.ui import get_gui from calibre.gui2.ui import get_gui