From d21bc5faf1a49475928b6f6fbc1ac4e2e25e0e75 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Mar 2026 03:55:52 +0000 Subject: [PATCH] ManageTagList: remember expanded/collapsed state between invocations Fixes #3026 --- src/calibre/gui2/tweak_book/__init__.py | 1 + src/calibre/gui2/tweak_book/widgets.py | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/tweak_book/__init__.py b/src/calibre/gui2/tweak_book/__init__.py index 44fe06ee01..6a81964f1a 100644 --- a/src/calibre/gui2/tweak_book/__init__.py +++ b/src/calibre/gui2/tweak_book/__init__.py @@ -58,6 +58,7 @@ d['pretty_print_on_open'] = False d['disable_completion_popup_for_search'] = False d['saved_searches'] = [] d['insert_tag_mru'] = ['p', 'div', 'li', 'h1', 'h2', 'h3', 'h4', 'em', 'strong', 'td', 'tr'] +d['manage_tag_list_collapsed_tags'] = [] d['spell_check_case_sensitive_sort'] = False d['inline_spell_check'] = True d['custom_themes'] = {} diff --git a/src/calibre/gui2/tweak_book/widgets.py b/src/calibre/gui2/tweak_book/widgets.py index a31a3471d8..4a8b0ce690 100644 --- a/src/calibre/gui2/tweak_book/widgets.py +++ b/src/calibre/gui2/tweak_book/widgets.py @@ -121,6 +121,7 @@ class ManageTagList(Dialog): # {{{ def __init__(self, parent=None): self._entries = list(tprefs['insert_tag_mru']) + self._collapsed_tags = set(tprefs.get('manage_tag_list_collapsed_tags', [])) Dialog.__init__(self, _('Manage tag list'), 'manage-insert-tag-listx', parent=parent) def sizeHint(self): @@ -160,6 +161,7 @@ class ManageTagList(Dialog): # {{{ return m.group() if m else entry def _populate_tree(self): + self._save_expanded_state() self.tree.clear() groups = {} for entry in self._entries: @@ -173,7 +175,7 @@ class ManageTagList(Dialog): # {{{ child.setData(0, Qt.ItemDataRole.UserRole, entry) parent_item.addChild(child) self.tree.addTopLevelItem(parent_item) - parent_item.setExpanded(True) + parent_item.setExpanded(tag_name not in self._collapsed_tags) self._update_button_states() def _current_entry(self): @@ -230,10 +232,25 @@ class ManageTagList(Dialog): # {{{ pass self._populate_tree() + def _save_expanded_state(self): + root = self.tree.invisibleRootItem() + for i in range(root.childCount()): + item = root.child(i) + if item.isExpanded(): + self._collapsed_tags.discard(item.text(0)) + else: + self._collapsed_tags.add(item.text(0)) + tprefs['manage_tag_list_collapsed_tags'] = list(self._collapsed_tags) + def accept(self): + self._save_expanded_state() tprefs['insert_tag_mru'] = self._entries super().accept() + def reject(self): + self._save_expanded_state() + super().reject() + # }}}