From 9c0fabff25fe944d6a11446731d58ce810db0ba7 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Sun, 17 Jan 2021 10:59:15 +0000 Subject: [PATCH 1/3] Enhancement #1912074: make the saved search editor multiline. --- src/calibre/gui2/dialogs/saved_search_editor.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/calibre/gui2/dialogs/saved_search_editor.py b/src/calibre/gui2/dialogs/saved_search_editor.py index 21c1723ac3..8f1fa84e18 100644 --- a/src/calibre/gui2/dialogs/saved_search_editor.py +++ b/src/calibre/gui2/dialogs/saved_search_editor.py @@ -4,7 +4,8 @@ from PyQt5.Qt import ( - QFormLayout, QIcon, QLabel, QLineEdit, QListWidget, Qt, QVBoxLayout, QDialog, QDialogButtonBox + QFormLayout, QIcon, QLabel, QLineEdit, QListWidget, Qt, QVBoxLayout, QDialog, + QDialogButtonBox, QPlainTextEdit ) from calibre import prepare_string_for_xml @@ -51,12 +52,12 @@ class AddSavedSearch(Dialog): l.addRow(_('&Name:'), n) n.setPlaceholderText(_('The Saved search name')) - self.search = s = QLineEdit(self) + self.search = s = QPlainTextEdit(self) s.setMinimumWidth(400) l.addRow(_('&Search:'), s) s.setPlaceholderText(_('The search expression')) if self.initial_search: - s.setText(self.initial_search) + s.setPlainText(self.initial_search) n.setFocus(Qt.FocusReason.OtherFocusReason) l.addRow(self.bb) @@ -68,7 +69,7 @@ class AddSavedSearch(Dialog): _('No search name'), _('You must specify a name for the Saved search'), show=True) - expression = self.search.text().strip() + expression = self.search.toPlainText().strip() if not expression: return error_dialog( self, @@ -182,7 +183,7 @@ class SavedSearchEditor(Dialog): validate=self.validate_edit) d.setWindowTitle(_('Edit saved search')) d.sname.setText(n) - d.search.setText(self.searches[n]) + d.search.setPlainText(self.searches[n]) if d.exec_() != QDialog.DialogCode.Accepted: return name, expression = d.accepted_data From 9df7d7ead9e6e522aa0d654e3f61d9ad6584e299 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Sun, 17 Jan 2021 11:09:31 +0000 Subject: [PATCH 2/3] Enhancement #1912081: make saved search lookup case insensitive. --- src/calibre/db/search.py | 6 +++++- src/calibre/utils/search_query_parser.py | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/calibre/db/search.py b/src/calibre/db/search.py index 50474507ae..4d82931d8b 100644 --- a/src/calibre/db/search.py +++ b/src/calibre/db/search.py @@ -424,7 +424,11 @@ class SavedSearchQueries(object): # {{{ db._set_pref(self.opt_name, self.queries) def lookup(self, name): - return self.queries.get(self.force_unicode(name), None) + sn = self.force_unicode(name).lower() + for n,q in self.queries.items(): + if sn == n.lower(): + return q + return None def delete(self, name): db = self.db diff --git a/src/calibre/utils/search_query_parser.py b/src/calibre/utils/search_query_parser.py index d639424483..4aca17f8eb 100644 --- a/src/calibre/utils/search_query_parser.py +++ b/src/calibre/utils/search_query_parser.py @@ -66,7 +66,11 @@ class SavedSearchQueries(object): self.save_queries() def lookup(self, name): - return self.queries.get(self.force_unicode(name), None) + sn = self.force_unicode(name).lower() + for n,q in self.queries.items(): + if sn == n.lower(): + return q + return None def delete(self, name): self.queries.pop(self.force_unicode(name), False) From aec0185f0cc81f245fecc931c9042b10878e480a Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Sun, 17 Jan 2021 11:27:42 +0000 Subject: [PATCH 3/3] Show template function type in the template editor's function list. --- src/calibre/gui2/dialogs/template_dialog.py | 23 ++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/calibre/gui2/dialogs/template_dialog.py b/src/calibre/gui2/dialogs/template_dialog.py index 74d89a7b11..bdbf3f2ea2 100644 --- a/src/calibre/gui2/dialogs/template_dialog.py +++ b/src/calibre/gui2/dialogs/template_dialog.py @@ -348,9 +348,11 @@ class TemplateDialog(QDialog, Ui_TemplateDialog): func_names = sorted(self.funcs) self.function.clear() self.function.addItem('') - self.function.addItems(func_names) + for f in func_names: + self.function.addItem('{} -- {}'.format(f, + self.function_type_string(f, longform=False)), f) self.function.setCurrentIndex(0) - self.function.currentIndexChanged[native_string_type].connect(self.function_changed) + self.function.currentIndexChanged.connect(self.function_changed) self.textbox_changed() self.rule = (None, '') @@ -440,8 +442,18 @@ class TemplateDialog(QDialog, Ui_TemplateDialog): self.highlighter.check_cursor_pos(t[position-1], block_number, pos_in_block) + def function_type_string(self, name, longform=True): + if self.funcs[name].is_python: + if name in self.builtins: + return (_('Built-in template function') if longform else + _('Built-in function')) + return (_('User defined Python template function') if longform else + _('User function')) + else: + return (_('Stored user defined template') if longform else _('Stored template')) + def function_changed(self, toWhat): - name = unicode_type(toWhat) + name = unicode_type(self.function.itemData(toWhat)) self.source_code.clear() self.documentation.clear() self.func_type.clear() @@ -451,10 +463,7 @@ class TemplateDialog(QDialog, Ui_TemplateDialog): self.source_code.setPlainText(self.builtin_source_dict[name]) else: self.source_code.setPlainText(self.funcs[name].program_text) - if self.funcs[name].is_python: - self.func_type.setText(_('Template function in Python')) - else: - self.func_type.setText(_('Stored template')) + self.func_type.setText(self.function_type_string(name, longform=True)) def accept(self): txt = unicode_type(self.textbox.toPlainText()).rstrip()