Add a hook that allows to edit a note before it is added. (#2481)
* add note_will_be_added hook * attempt to fix Tests.buildkite/linux/entrypoint * attempt to fix Tests.buildkite/linux/entrypoint * apply patch
This commit is contained in:
parent
13890ffade
commit
57d6e99262
@ -562,6 +562,7 @@ class Collection(DeprecatedNamesMixin):
|
|||||||
return Note(self, notetype)
|
return Note(self, notetype)
|
||||||
|
|
||||||
def add_note(self, note: Note, deck_id: DeckId) -> OpChanges:
|
def add_note(self, note: Note, deck_id: DeckId) -> OpChanges:
|
||||||
|
hooks.note_will_be_added(self, note, deck_id)
|
||||||
out = self._backend.add_note(note=note._to_backend_note(), deck_id=deck_id)
|
out = self._backend.add_note(note=note._to_backend_note(), deck_id=deck_id)
|
||||||
note.id = NoteId(out.note_id)
|
note.id = NoteId(out.note_id)
|
||||||
return out.changes
|
return out.changes
|
||||||
|
@ -31,6 +31,20 @@ hooks = [
|
|||||||
args=["col: anki.collection.Collection", "ids: Sequence[anki.notes.NoteId]"],
|
args=["col: anki.collection.Collection", "ids: Sequence[anki.notes.NoteId]"],
|
||||||
legacy_hook="remNotes",
|
legacy_hook="remNotes",
|
||||||
),
|
),
|
||||||
|
Hook(
|
||||||
|
name="note_will_be_added",
|
||||||
|
args=[
|
||||||
|
"col: anki.collection.Collection",
|
||||||
|
"note: anki.notes.Note",
|
||||||
|
"deck_id: anki.decks.DeckId",
|
||||||
|
],
|
||||||
|
doc="""Allows modifying a note before it's added to the collection.
|
||||||
|
|
||||||
|
This hook may be called both when users use the Add screen, and when
|
||||||
|
add-ons like AnkiConnect add notes. It is not called when importing. If
|
||||||
|
you wish to alter the Add screen, use gui_hooks.add_cards_will_add_note
|
||||||
|
instead.""",
|
||||||
|
),
|
||||||
Hook(
|
Hook(
|
||||||
name="media_files_did_export",
|
name="media_files_did_export",
|
||||||
args=["count: int"],
|
args=["count: int"],
|
||||||
|
Loading…
Reference in New Issue
Block a user