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: