Skip to content

Commit

Permalink
Edit book: Regex-function mode: Show a confirmation popup when closin…
Browse files Browse the repository at this point in the history
…g the function editor when there are unsaved changes
  • Loading branch information
kovidgoyal committed Apr 19, 2024
1 parent 9319cd7 commit 6514dde
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/calibre/gui2/tweak_book/function_replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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 ##########################################################


Expand Down

0 comments on commit 6514dde

Please sign in to comment.