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:
Ren Tatsumoto 2023-04-27 05:34:33 +00:00 committed by GitHub
parent 13890ffade
commit 57d6e99262
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -562,6 +562,7 @@ class Collection(DeprecatedNamesMixin):
return Note(self, notetype)
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)
note.id = NoteId(out.note_id)
return out.changes

View File

@ -31,6 +31,20 @@ hooks = [
args=["col: anki.collection.Collection", "ids: Sequence[anki.notes.NoteId]"],
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(
name="media_files_did_export",
args=["count: int"],