Fixes #1912074 [Enhancement Request: Increase size of Edit Saved Search](https://bugs.launchpad.net/calibre/+bug/1912074)
Fixes #1912081 [Saved searches are case-sensitive](https://bugs.launchpad.net/calibre/+bug/1912081)
This commit is contained in:
Kovid Goyal 2021-01-17 19:16:57 +05:30
commit e3cde00f98
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 32 additions and 14 deletions

View File

@ -424,7 +424,11 @@ class SavedSearchQueries(object): # {{{
db._set_pref(self.opt_name, self.queries) db._set_pref(self.opt_name, self.queries)
def lookup(self, name): 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): def delete(self, name):
db = self.db db = self.db

View File

@ -4,7 +4,8 @@
from PyQt5.Qt import ( 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 from calibre import prepare_string_for_xml
@ -51,12 +52,12 @@ class AddSavedSearch(Dialog):
l.addRow(_('&Name:'), n) l.addRow(_('&Name:'), n)
n.setPlaceholderText(_('The Saved search name')) n.setPlaceholderText(_('The Saved search name'))
self.search = s = QLineEdit(self) self.search = s = QPlainTextEdit(self)
s.setMinimumWidth(400) s.setMinimumWidth(400)
l.addRow(_('&Search:'), s) l.addRow(_('&Search:'), s)
s.setPlaceholderText(_('The search expression')) s.setPlaceholderText(_('The search expression'))
if self.initial_search: if self.initial_search:
s.setText(self.initial_search) s.setPlainText(self.initial_search)
n.setFocus(Qt.FocusReason.OtherFocusReason) n.setFocus(Qt.FocusReason.OtherFocusReason)
l.addRow(self.bb) l.addRow(self.bb)
@ -68,7 +69,7 @@ class AddSavedSearch(Dialog):
_('No search name'), _('No search name'),
_('You must specify a name for the Saved search'), _('You must specify a name for the Saved search'),
show=True) show=True)
expression = self.search.text().strip() expression = self.search.toPlainText().strip()
if not expression: if not expression:
return error_dialog( return error_dialog(
self, self,
@ -182,7 +183,7 @@ class SavedSearchEditor(Dialog):
validate=self.validate_edit) validate=self.validate_edit)
d.setWindowTitle(_('Edit saved search')) d.setWindowTitle(_('Edit saved search'))
d.sname.setText(n) d.sname.setText(n)
d.search.setText(self.searches[n]) d.search.setPlainText(self.searches[n])
if d.exec_() != QDialog.DialogCode.Accepted: if d.exec_() != QDialog.DialogCode.Accepted:
return return
name, expression = d.accepted_data name, expression = d.accepted_data

View File

@ -348,9 +348,11 @@ class TemplateDialog(QDialog, Ui_TemplateDialog):
func_names = sorted(self.funcs) func_names = sorted(self.funcs)
self.function.clear() self.function.clear()
self.function.addItem('') 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.setCurrentIndex(0)
self.function.currentIndexChanged[native_string_type].connect(self.function_changed) self.function.currentIndexChanged.connect(self.function_changed)
self.textbox_changed() self.textbox_changed()
self.rule = (None, '') self.rule = (None, '')
@ -440,8 +442,18 @@ class TemplateDialog(QDialog, Ui_TemplateDialog):
self.highlighter.check_cursor_pos(t[position-1], block_number, self.highlighter.check_cursor_pos(t[position-1], block_number,
pos_in_block) 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): def function_changed(self, toWhat):
name = unicode_type(toWhat) name = unicode_type(self.function.itemData(toWhat))
self.source_code.clear() self.source_code.clear()
self.documentation.clear() self.documentation.clear()
self.func_type.clear() self.func_type.clear()
@ -451,10 +463,7 @@ class TemplateDialog(QDialog, Ui_TemplateDialog):
self.source_code.setPlainText(self.builtin_source_dict[name]) self.source_code.setPlainText(self.builtin_source_dict[name])
else: else:
self.source_code.setPlainText(self.funcs[name].program_text) self.source_code.setPlainText(self.funcs[name].program_text)
if self.funcs[name].is_python: self.func_type.setText(self.function_type_string(name, longform=True))
self.func_type.setText(_('Template function in Python'))
else:
self.func_type.setText(_('Stored template'))
def accept(self): def accept(self):
txt = unicode_type(self.textbox.toPlainText()).rstrip() txt = unicode_type(self.textbox.toPlainText()).rstrip()

View File

@ -66,7 +66,11 @@ class SavedSearchQueries(object):
self.save_queries() self.save_queries()
def lookup(self, name): 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): def delete(self, name):
self.queries.pop(self.force_unicode(name), False) self.queries.pop(self.force_unicode(name), False)