From cd0d2eb53b45186931abaa0c0d16352706bebec4 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Fri, 10 Jan 2025 15:56:50 +0000 Subject: [PATCH] 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. --- src/calibre/gui2/tag_browser/ui.py | 9 ++ src/calibre/gui2/tag_browser/view.py | 140 +++++++++++---------------- 2 files changed, 66 insertions(+), 83 deletions(-) diff --git a/src/calibre/gui2/tag_browser/ui.py b/src/calibre/gui2/tag_browser/ui.py index 22164716353f..e63ec1d1d42e 100644 --- a/src/calibre/gui2/tag_browser/ui.py +++ b/src/calibre/gui2/tag_browser/ui.py @@ -879,6 +879,10 @@ def __init__(self, parent): action=ac, group=_('Tag browser')) 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) parent.addAction(ac) parent.keyboard.register_shortcut('tag browser toggle item', @@ -897,6 +901,11 @@ def __init__(self, parent): # self.leak_test_timer.timeout.connect(self.test_for_leak) # 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): ac = self.alter_tb.m.show_counts_action p = gprefs['tag_browser_show_counts'] diff --git a/src/calibre/gui2/tag_browser/view.py b/src/calibre/gui2/tag_browser/view.py index 1271509da333..129da894e9d6 100644 --- a/src/calibre/gui2/tag_browser/view.py +++ b/src/calibre/gui2/tag_browser/view.py @@ -1203,90 +1203,64 @@ def add_node_tree(tree_dict, m, path): self.context_menu.addSeparator() add_show_hidden_categories() - # partitioning. If partitioning is active, provide a way to turn it on or - # off for this category. - if gprefs['tags_browser_partition_method'] != 'disable' and key is not None: - m = self.context_menu - p = self.db.prefs.get('tag_browser_dont_collapse', gprefs['tag_browser_dont_collapse']) - # Use the prefix for a user category. The - if key.startswith('@'): - 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)) + if key is not None: + # partitioning. If partitioning is active, provide a way to turn it on or + # off for this category. + if gprefs['tags_browser_partition_method'] != 'disable': + m = self.context_menu + p = self.db.prefs.get('tag_browser_dont_collapse', gprefs['tag_browser_dont_collapse']) + # Use the prefix for a user category. The + if key.startswith('@'): + 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: - 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": - fla.setEnabled(False) - m.hovered.connect(self.collapse_menu_hovered) - fla.setToolTip(_('First letter is usable only when sorting by name')) - # Apparently one cannot set a tooltip to empty, so use a star and - # deal with it in the hover method - da.setToolTip('*') - pa.setToolTip('*') - - # 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: - if self.has_children(index) and not self.isExpanded(index): - m.addAction(self.plus_icon, - _('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) + if self.has_children(index) and not self.isExpanded(index): + m.addAction(self.plus_icon, + _('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 from calibre.gui2.ui import get_gui