Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/cbhaley/calibre
Browse files Browse the repository at this point in the history
  • Loading branch information
kovidgoyal committed Jan 10, 2025
2 parents d592a8d + cd0d2eb commit 330ca48
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 83 deletions.
9 changes: 9 additions & 0 deletions src/calibre/gui2/tag_browser/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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']
Expand Down
140 changes: 57 additions & 83 deletions src/calibre/gui2/tag_browser/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 330ca48

Please sign in to comment.