mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Offer to save changes when card layouts screen is closed (#2899)
This commit is contained in:
parent
4908be62ed
commit
31aba99641
1 changed files with 24 additions and 4 deletions
|
@ -26,6 +26,7 @@ from aqt.sound import av_player, play_clicked_audio
|
||||||
from aqt.theme import theme_manager
|
from aqt.theme import theme_manager
|
||||||
from aqt.utils import (
|
from aqt.utils import (
|
||||||
HelpPage,
|
HelpPage,
|
||||||
|
ask_user_dialog,
|
||||||
askUser,
|
askUser,
|
||||||
disable_help_button,
|
disable_help_button,
|
||||||
downArrow,
|
downArrow,
|
||||||
|
@ -891,11 +892,30 @@ class CardLayout(QDialog):
|
||||||
).run_in_background()
|
).run_in_background()
|
||||||
|
|
||||||
def reject(self) -> None:
|
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 self.change_tracker.changed():
|
||||||
if not askUser(tr.card_templates_discard_changes()):
|
ask_user_dialog(
|
||||||
return
|
text=tr.card_templates_discard_changes(),
|
||||||
self.cleanup()
|
callback=callback,
|
||||||
return QDialog.reject(self)
|
buttons=[
|
||||||
|
QMessageBox.StandardButton.Save,
|
||||||
|
QMessageBox.StandardButton.Discard,
|
||||||
|
QMessageBox.StandardButton.Cancel,
|
||||||
|
],
|
||||||
|
default_button=0,
|
||||||
|
parent=self,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
_reject()
|
||||||
|
|
||||||
def cleanup(self) -> None:
|
def cleanup(self) -> None:
|
||||||
self.cancelPreviewTimer()
|
self.cancelPreviewTimer()
|
||||||
|
|
Loading…
Reference in a new issue