Check for out-of-place/missing clozes when adding
This commit is contained in:
parent
aeedb4dc11
commit
9acc03773a
@ -6,4 +6,6 @@ adding-history = History
|
|||||||
adding-note-deleted = (Note deleted)
|
adding-note-deleted = (Note deleted)
|
||||||
adding-shortcut = Shortcut: { $val }
|
adding-shortcut = Shortcut: { $val }
|
||||||
adding-the-first-field-is-empty = The first field is empty.
|
adding-the-first-field-is-empty = The first field is empty.
|
||||||
adding-you-have-a-cloze-deletion-note = You have a cloze deletion note type but have not made any cloze deletions. Proceed?
|
adding-missing-cloze = You have a cloze notetype but have not made any cloze deletions.
|
||||||
|
adding-cloze-outside-cloze-notetype = Cloze deletion can only be used on cloze notetypes.
|
||||||
|
adding-cloze-outside-cloze-field = Cloze deletion can only be used in fields which use the 'cloze:' filter (see 'Cards...').
|
||||||
|
@ -11,7 +11,7 @@ ignored-classes=
|
|||||||
QueuedCards,
|
QueuedCards,
|
||||||
UnburyDeckIn,
|
UnburyDeckIn,
|
||||||
BuryOrSuspendCardsIn,
|
BuryOrSuspendCardsIn,
|
||||||
NoteIsDuplicateOrEmptyOut,
|
NoteFieldsCheckOut,
|
||||||
BackendError,
|
BackendError,
|
||||||
SetDeckCollapsedIn,
|
SetDeckCollapsedIn,
|
||||||
|
|
||||||
|
@ -6,10 +6,9 @@ from typing import Callable, List, Optional
|
|||||||
import aqt.editor
|
import aqt.editor
|
||||||
import aqt.forms
|
import aqt.forms
|
||||||
from anki.collection import OpChanges, SearchNode
|
from anki.collection import OpChanges, SearchNode
|
||||||
from anki.consts import MODEL_CLOZE
|
|
||||||
from anki.decks import DeckId
|
from anki.decks import DeckId
|
||||||
from anki.models import NotetypeId
|
from anki.models import NotetypeId
|
||||||
from anki.notes import DuplicateOrEmptyResult, Note, NoteId
|
from anki.notes import Note, NoteFieldsCheckResult, NoteId
|
||||||
from anki.utils import htmlToTextLine, isMac
|
from anki.utils import htmlToTextLine, isMac
|
||||||
from aqt import AnkiQt, gui_hooks
|
from aqt import AnkiQt, gui_hooks
|
||||||
from aqt.deckchooser import DeckChooser
|
from aqt.deckchooser import DeckChooser
|
||||||
@ -231,9 +230,15 @@ class AddCards(QDialog):
|
|||||||
).run_in_background()
|
).run_in_background()
|
||||||
|
|
||||||
def _note_can_be_added(self, note: Note) -> bool:
|
def _note_can_be_added(self, note: Note) -> bool:
|
||||||
result = note.duplicate_or_empty()
|
result = note.fields_check()
|
||||||
if result == DuplicateOrEmptyResult.EMPTY:
|
if result == NoteFieldsCheckResult.EMPTY:
|
||||||
problem = tr.adding_the_first_field_is_empty()
|
problem = tr.adding_the_first_field_is_empty()
|
||||||
|
elif result == NoteFieldsCheckResult.MISSING_CLOZE:
|
||||||
|
problem = tr.adding_missing_cloze()
|
||||||
|
elif result == NoteFieldsCheckResult.NOTETYPE_NOT_CLOZE:
|
||||||
|
problem = tr.adding_cloze_outside_cloze_notetype()
|
||||||
|
elif result == NoteFieldsCheckResult.FIELD_NOT_CLOZE:
|
||||||
|
problem = tr.adding_cloze_outside_cloze_field()
|
||||||
else:
|
else:
|
||||||
# duplicate entries are allowed these days
|
# duplicate entries are allowed these days
|
||||||
problem = None
|
problem = None
|
||||||
@ -244,12 +249,6 @@ class AddCards(QDialog):
|
|||||||
showWarning(problem, help=HelpPage.ADDING_CARD_AND_NOTE)
|
showWarning(problem, help=HelpPage.ADDING_CARD_AND_NOTE)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# missing cloze deletion?
|
|
||||||
if note.model()["type"] == MODEL_CLOZE:
|
|
||||||
if not note.cloze_numbers_in_fields():
|
|
||||||
if not askUser(tr.adding_you_have_a_cloze_deletion_note()):
|
|
||||||
return False
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def keyPressEvent(self, evt: QKeyEvent) -> None:
|
def keyPressEvent(self, evt: QKeyEvent) -> None:
|
||||||
|
Loading…
Reference in New Issue
Block a user