mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Improve confirmation message in Add screen (#2903)
This commit is contained in:
parent
3378e476e6
commit
e33a2bcb17
3 changed files with 28 additions and 8 deletions
|
@ -1,6 +1,7 @@
|
|||
adding-add-shortcut-ctrlandenter = Add (shortcut: ctrl+enter)
|
||||
adding-added = Added
|
||||
adding-close-and-lose-current-input = Close and lose current input?
|
||||
adding-discard-current-input = Discard current input?
|
||||
adding-keep-editing = Keep Editing
|
||||
adding-edit = Edit "{ $val }"
|
||||
adding-history = History
|
||||
adding-note-deleted = (Note deleted)
|
||||
|
|
|
@ -22,6 +22,7 @@ from aqt.sound import av_player
|
|||
from aqt.utils import (
|
||||
HelpPage,
|
||||
add_close_shortcut,
|
||||
ask_user_dialog,
|
||||
askUser,
|
||||
downArrow,
|
||||
openHelp,
|
||||
|
@ -342,13 +343,23 @@ class AddCards(QMainWindow):
|
|||
self.close()
|
||||
|
||||
def ifCanClose(self, onOk: Callable) -> None:
|
||||
def afterSave() -> None:
|
||||
ok = self.editor.fieldsAreBlank(self._last_added_note) or askUser(
|
||||
tr.adding_close_and_lose_current_input(), defaultno=True
|
||||
)
|
||||
if ok:
|
||||
def callback(choice: int) -> None:
|
||||
if choice == 0:
|
||||
onOk()
|
||||
|
||||
def afterSave() -> None:
|
||||
if self.editor.fieldsAreBlank(self._last_added_note):
|
||||
return onOk()
|
||||
|
||||
ask_user_dialog(
|
||||
tr.adding_discard_current_input(),
|
||||
callback=callback,
|
||||
buttons=[
|
||||
QMessageBox.StandardButton.Discard,
|
||||
(tr.adding_keep_editing(), QMessageBox.ButtonRole.RejectRole),
|
||||
],
|
||||
)
|
||||
|
||||
self.editor.call_after_note_saved(afterSave)
|
||||
|
||||
def closeWithCallback(self, cb: Callable[[], None]) -> None:
|
||||
|
|
|
@ -138,7 +138,10 @@ class MessageBox(QMessageBox):
|
|||
icon: QMessageBox.Icon = QMessageBox.Icon.NoIcon,
|
||||
help: HelpPageArgument | None = None,
|
||||
title: str = "Anki",
|
||||
buttons: Sequence[str | QMessageBox.StandardButton] | None = None,
|
||||
buttons: Sequence[
|
||||
str | QMessageBox.StandardButton | tuple[str, QMessageBox.ButtonRole]
|
||||
]
|
||||
| None = None,
|
||||
default_button: int = 0,
|
||||
textFormat: Qt.TextFormat = Qt.TextFormat.PlainText,
|
||||
modality: Qt.WindowModality = Qt.WindowModality.WindowModal,
|
||||
|
@ -161,6 +164,8 @@ class MessageBox(QMessageBox):
|
|||
b = self.addButton(button, QMessageBox.ButtonRole.ActionRole)
|
||||
elif isinstance(button, QMessageBox.StandardButton):
|
||||
b = self.addButton(button)
|
||||
elif isinstance(button, tuple):
|
||||
b = self.addButton(button[0], button[1])
|
||||
else:
|
||||
continue
|
||||
if callback is not None:
|
||||
|
@ -193,7 +198,10 @@ def ask_user(
|
|||
def ask_user_dialog(
|
||||
text: str,
|
||||
callback: Callable[[int], None],
|
||||
buttons: Sequence[str | QMessageBox.StandardButton] | None = None,
|
||||
buttons: Sequence[
|
||||
str | QMessageBox.StandardButton | tuple[str, QMessageBox.ButtonRole]
|
||||
]
|
||||
| None = None,
|
||||
default_button: int = 1,
|
||||
**kwargs: Any,
|
||||
) -> MessageBox:
|
||||
|
|
Loading…
Reference in a new issue