This commit is contained in:
Kovid Goyal 2023-08-16 19:19:19 +05:30
commit a40a514d35
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -49,7 +49,18 @@ class SaveTemplate(QWidget, Ui_Form):
self.open_editor.clicked.connect(self.do_open_editor) self.open_editor.clicked.connect(self.do_open_editor)
def do_open_editor(self): def do_open_editor(self):
t = TemplateDialog(self, self.opt_template.text(), fm=self.field_metadata) # Try to get selected books
from calibre.gui2.ui import get_gui
db = get_gui().current_db
view = get_gui().library_view
rows = view.selectionModel().selectedRows()[0:10] # Maximum of 10 books
mi = [db.new_api.get_proxy_metadata(db.data.index_to_id(x.row())) for x in rows]
if not mi:
error_dialog(self, _('Must select books'),
_('One or more books must be selected so the template '
'editor can show the template results'), show=True)
return
t = TemplateDialog(self, self.opt_template.text(), fm=self.field_metadata, mi=mi)
t.setWindowTitle(_('Edit template')) t.setWindowTitle(_('Edit template'))
if t.exec(): if t.exec():
self.opt_template.set_value(t.rule[1]) self.opt_template.set_value(t.rule[1])
@ -64,6 +75,9 @@ class SaveTemplate(QWidget, Ui_Form):
custom fields, because they may or may not exist. custom fields, because they may or may not exist.
''' '''
tmpl = preprocess_template(self.opt_template.text()) tmpl = preprocess_template(self.opt_template.text())
# Allow PTM or GPM templates without checking
if tmpl.startswith(('program:', 'python:')):
return True
try: try:
t = validation_formatter.validate(tmpl) t = validation_formatter.validate(tmpl)
if t.find(validation_formatter._validation_string) < 0: if t.find(validation_formatter._validation_string) < 0: