From 55e070682c62a7d79c37b2e856bdd068fd44ed19 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 1 Apr 2026 05:28:50 +0000 Subject: [PATCH] Fix duplicate column names in Show Column and Sort By menus Agent-Logs-Url: https://github.com/kovidgoyal/calibre/sessions/bdadbc3e-805b-48aa-9232-a4c7df75d643 Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com> --- src/calibre/gui2/actions/sort.py | 3 +++ src/calibre/gui2/library/views.py | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/actions/sort.py b/src/calibre/gui2/actions/sort.py index 56bff7cea1..b80d21ed1d 100644 --- a/src/calibre/gui2/actions/sort.py +++ b/src/calibre/gui2/actions/sort.py @@ -5,6 +5,7 @@ __license__ = 'GPL v3' __copyright__ = '2013, Kovid Goyal ' from contextlib import suppress +from collections import Counter from functools import partial from qt.core import ( @@ -37,6 +38,8 @@ def hidden_fields(db): def get_sorted_fields(db): fm = db.field_metadata name_map = [(v,k) for k, v in fm.ui_sortable_field_keys().items()] + counts = Counter(name for name, _ in name_map) + name_map = [(f'{name} [{key}]' if counts[name] > 1 else name, key) for name, key in name_map] return sorted(name_map, key=lambda x: primary_sort_key(x[0])) diff --git a/src/calibre/gui2/library/views.py b/src/calibre/gui2/library/views.py index cf83ccc1e4..f82fc430ae 100644 --- a/src/calibre/gui2/library/views.py +++ b/src/calibre/gui2/library/views.py @@ -7,7 +7,7 @@ __docformat__ = 'restructuredtext en' import itertools import operator -from collections import OrderedDict +from collections import Counter, OrderedDict from functools import partial from qt.core import ( @@ -661,9 +661,11 @@ class BooksView(TableView): # {{{ m.setIcon(QIcon.ic('plus.png')) hcols = [(hcol, str(self.model().headerData(hidx, Qt.Orientation.Horizontal, Qt.ItemDataRole.DisplayRole) or '')) for hcol, hidx in hidden_cols.items()] + name_counts = Counter(hname for _, hname in hcols) hcols.sort(key=lambda x: primary_sort_key(x[1])) for hcol, hname in hcols: - m.addAction(hname.replace('&', '&&'), partial(handler, action='show', column=hcol)) + display = f'{hname} [{hcol}]' if name_counts[hname] > 1 else hname + m.addAction(display.replace('&', '&&'), partial(handler, action='show', column=hcol)) ans.addSeparator() if col == 'ondevice': ans.addAction(_('Remember On Device column width'),