From 6514dde2055aea647b156ff5369d158e5e86a996 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 19 Apr 2024 07:01:44 +0530 Subject: [PATCH] Edit book: Regex-function mode: Show a confirmation popup when closing the function editor when there are unsaved changes --- src/calibre/gui2/tweak_book/function_replace.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/tweak_book/function_replace.py b/src/calibre/gui2/tweak_book/function_replace.py index 2bdfff212d5e..a81845c3eae0 100644 --- a/src/calibre/gui2/tweak_book/function_replace.py +++ b/src/calibre/gui2/tweak_book/function_replace.py @@ -14,7 +14,8 @@ from calibre.ebooks.oeb.polish.utils import apply_func_to_html_text, apply_func_to_match_groups from calibre.gui2 import error_dialog from calibre.gui2.complete2 import EditWithComplete -from calibre.gui2.tweak_book import dictionaries +from calibre.gui2.dialogs.confirm_delete import confirm +from calibre.gui2.tweak_book import dictionaries, tprefs from calibre.gui2.tweak_book.editor.text import TextEdit from calibre.gui2.tweak_book.widgets import Dialog from calibre.utils.config import JSONConfig @@ -253,6 +254,7 @@ def setup_ui(self): l.addWidget(la) l.addWidget(self.bb) + self.initial_source = self.source def sizeHint(self): fm = QFontMetrics(self.font()) @@ -285,6 +287,13 @@ def accept(self): Dialog.accept(self) + def reject(self): + if self.source != self.initial_source: + if not confirm(_('All unsaved changes will be lost. Are you sure?'), 'function-replace-close-confirm', + parent=self, config_set=tprefs): + return + return super().reject() + # Builtin functions ##########################################################