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)

This commit is contained in:
Kovid Goyal 2024-01-16 21:34:15 +05:30
parent 5875303a48
commit b714fc5023
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -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: