From b714fc502395acf1cf6b481453efc92241701787 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 16 Jan 2024 21:34:15 +0530 Subject: [PATCH] Category notes browser: Add a button to search for books in the currently selected category. Fixes #2046825 [[Enhancement] Browse category notes](https://bugs.launchpad.net/calibre/+bug/2046825) --- src/calibre/gui2/library/notes.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/calibre/gui2/library/notes.py b/src/calibre/gui2/library/notes.py index 877d7eacdc..963b804f52 100644 --- a/src/calibre/gui2/library/notes.py +++ b/src/calibre/gui2/library/notes.py @@ -454,8 +454,26 @@ class NotesBrowser(Dialog): b.clicked.connect(self.export_selected) b.setToolTip(_('Export the selected notes as HTML files')) h.addWidget(us), h.addStretch(10), h.addWidget(self.bb) + from calibre.gui2.ui import get_gui + gui = get_gui() + if gui is not None: + b = self.bb.addButton(_('Search books'), QDialogButtonBox.ButtonRole.ActionRole) + b.setToolTip(_('Search the calibre library for books in the currently selected category')) + b.clicked.connect(self.search_books) + b.setIcon(QIcon.ic('search.png')) QTimer.singleShot(0, self.do_find) + def search_books(self): + self.notes_display.current_result_changed + item = self.results_list.currentItem() + if item: + r = item.data(0, Qt.ItemDataRole.UserRole) + if isinstance(r, dict): + ival = r['text'].split('\n', 1)[0].replace('"', '\\"') + search_expression = f'{r["field"]}:"={ival}"' + from calibre.gui2.ui import get_gui + get_gui().search.set_search_string(search_expression) + def export_selected(self): results = tuple(self.results_list.selected_results()) if not results: