From ab1da2ffdcc953ed9a3a6d05b11fb5e45c6c1d8b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 7 Sep 2025 13:41:42 +0530 Subject: [PATCH] Add basic validation for quick action create dialog --- src/calibre/gui2/viewer/llm.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/calibre/gui2/viewer/llm.py b/src/calibre/gui2/viewer/llm.py index 6194831fc0..d63d797b0e 100644 --- a/src/calibre/gui2/viewer/llm.py +++ b/src/calibre/gui2/viewer/llm.py @@ -637,6 +637,18 @@ class ActionEditDialog(QDialog): title = self.name_edit.text().strip() return Action(f'custom-{title}', title, self.prompt_edit.toPlainText().strip()) + def accept(self) -> None: + ac = self.get_action() + if not ac.human_name: + return error_dialog(self, _('No name specified'), _('You must specify a name for the Quick action'), show=True) + if not ac.prompt_template: + return error_dialog(self, _('No prompt specified'), _('You must specify a prompt for the Quick action'), show=True) + try: + ac.prompt_text() + except Exception as e: + return error_dialog(self, _('Invalid prompt'), _('The prompt you specified is not valid. Error: {}').format(e), show=True) + super().accept() + class LLMSettingsWidget(QWidget):