Exemplo n.º 1
0
    def _note_can_be_added(self, note: Note) -> bool:
        result = note.duplicate_or_empty()
        if result == DuplicateOrEmptyResult.EMPTY:
            problem = tr.adding_the_first_field_is_empty()
        else:
            # duplicate entries are allowed these days
            problem = None

        # filter problem through add-ons
        problem = gui_hooks.add_cards_will_add_note(problem, note)
        if problem is not None:
            showWarning(problem, help=HelpPage.ADDING_CARD_AND_NOTE)
            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
Exemplo n.º 2
0
 def addNote(self, note: Note) -> Optional[Note]:
     note.model()["did"] = self.deckChooser.selectedId()
     ret = note.dupeOrEmpty()
     problem = None
     if ret == 1:
         problem = tr(TR.ADDING_THE_FIRST_FIELD_IS_EMPTY)
     problem = gui_hooks.add_cards_will_add_note(problem, note)
     if problem is not None:
         showWarning(problem, help=HelpPage.ADDING_CARD_AND_NOTE)
         return None
     if note.model()["type"] == MODEL_CLOZE:
         if not note.cloze_numbers_in_fields():
             if not askUser(tr(TR.ADDING_YOU_HAVE_A_CLOZE_DELETION_NOTE)):
                 return None
     self.mw.col.add_note(note, self.deckChooser.selectedId())
     self.mw.col.clearUndo()
     self.addHistory(note)
     self.previousNote = note
     self.mw.requireReset(reason=ResetReason.AddCardsAddNote, context=self)
     gui_hooks.add_cards_did_add_note(note)
     return note