mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12: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-add-shortcut-ctrlandenter = Add (shortcut: ctrl+enter)
|
||||||
adding-added = Added
|
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-edit = Edit "{ $val }"
|
||||||
adding-history = History
|
adding-history = History
|
||||||
adding-note-deleted = (Note deleted)
|
adding-note-deleted = (Note deleted)
|
||||||
|
|
|
@ -22,6 +22,7 @@ from aqt.sound import av_player
|
||||||
from aqt.utils import (
|
from aqt.utils import (
|
||||||
HelpPage,
|
HelpPage,
|
||||||
add_close_shortcut,
|
add_close_shortcut,
|
||||||
|
ask_user_dialog,
|
||||||
askUser,
|
askUser,
|
||||||
downArrow,
|
downArrow,
|
||||||
openHelp,
|
openHelp,
|
||||||
|
@ -342,13 +343,23 @@ class AddCards(QMainWindow):
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
def ifCanClose(self, onOk: Callable) -> None:
|
def ifCanClose(self, onOk: Callable) -> None:
|
||||||
def afterSave() -> None:
|
def callback(choice: int) -> None:
|
||||||
ok = self.editor.fieldsAreBlank(self._last_added_note) or askUser(
|
if choice == 0:
|
||||||
tr.adding_close_and_lose_current_input(), defaultno=True
|
|
||||||
)
|
|
||||||
if ok:
|
|
||||||
onOk()
|
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)
|
self.editor.call_after_note_saved(afterSave)
|
||||||
|
|
||||||
def closeWithCallback(self, cb: Callable[[], None]) -> None:
|
def closeWithCallback(self, cb: Callable[[], None]) -> None:
|
||||||
|
|
|
@ -138,7 +138,10 @@ class MessageBox(QMessageBox):
|
||||||
icon: QMessageBox.Icon = QMessageBox.Icon.NoIcon,
|
icon: QMessageBox.Icon = QMessageBox.Icon.NoIcon,
|
||||||
help: HelpPageArgument | None = None,
|
help: HelpPageArgument | None = None,
|
||||||
title: str = "Anki",
|
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,
|
default_button: int = 0,
|
||||||
textFormat: Qt.TextFormat = Qt.TextFormat.PlainText,
|
textFormat: Qt.TextFormat = Qt.TextFormat.PlainText,
|
||||||
modality: Qt.WindowModality = Qt.WindowModality.WindowModal,
|
modality: Qt.WindowModality = Qt.WindowModality.WindowModal,
|
||||||
|
@ -161,6 +164,8 @@ class MessageBox(QMessageBox):
|
||||||
b = self.addButton(button, QMessageBox.ButtonRole.ActionRole)
|
b = self.addButton(button, QMessageBox.ButtonRole.ActionRole)
|
||||||
elif isinstance(button, QMessageBox.StandardButton):
|
elif isinstance(button, QMessageBox.StandardButton):
|
||||||
b = self.addButton(button)
|
b = self.addButton(button)
|
||||||
|
elif isinstance(button, tuple):
|
||||||
|
b = self.addButton(button[0], button[1])
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
if callback is not None:
|
if callback is not None:
|
||||||
|
@ -193,7 +198,10 @@ def ask_user(
|
||||||
def ask_user_dialog(
|
def ask_user_dialog(
|
||||||
text: str,
|
text: str,
|
||||||
callback: Callable[[int], None],
|
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,
|
default_button: int = 1,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> MessageBox:
|
) -> MessageBox:
|
||||||
|
|
Loading…
Reference in a new issue