Skip to content

Commit

Permalink
Offer to save changes when card layouts screen is closed (#2899)
Browse files Browse the repository at this point in the history
  • Loading branch information
abdnh authored Dec 22, 2023
1 parent 4908be6 commit 31aba99
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions qt/aqt/clayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from aqt.theme import theme_manager
from aqt.utils import (
HelpPage,
ask_user_dialog,
askUser,
disable_help_button,
downArrow,
Expand Down Expand Up @@ -891,11 +892,30 @@ def on_done(changes: OpChanges) -> None:
).run_in_background()

def reject(self) -> None:
def _reject() -> None:
self.cleanup()
QDialog.reject(self)

def callback(choice: int) -> None:
if choice == 0:
self.accept()
elif choice == 1:
_reject()

if self.change_tracker.changed():
if not askUser(tr.card_templates_discard_changes()):
return
self.cleanup()
return QDialog.reject(self)
ask_user_dialog(
text=tr.card_templates_discard_changes(),
callback=callback,
buttons=[
QMessageBox.StandardButton.Save,
QMessageBox.StandardButton.Discard,
QMessageBox.StandardButton.Cancel,
],
default_button=0,
parent=self,
)
else:
_reject()

def cleanup(self) -> None:
self.cancelPreviewTimer()
Expand Down

0 comments on commit 31aba99

Please sign in to comment.