added editor hook: add_cards_might_add_note (#1992)

* added hook add_cards_might_add_note

* fix failing test
This commit is contained in:
Sam Penny 2022-07-30 11:41:42 +01:00 committed by GitHub
parent d699bc1252
commit 56f806146c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

View file

@ -296,6 +296,11 @@ class AddCards(QMainWindow):
showWarning(problem, help=HelpPage.ADDING_CARD_AND_NOTE)
return False
optional_problems: list[str] = []
gui_hooks.add_cards_might_add_note(optional_problems, note)
if not all(askUser(op) for op in optional_problems):
return False
return True
def keyPressEvent(self, evt: QKeyEvent) -> None:

View file

@ -904,6 +904,26 @@ gui_hooks.webview_did_inject_style_into_page.append(mytest)
replace return the reason to reject. Otherwise return the
input.""",
),
Hook(
name="add_cards_might_add_note",
args=["optional_problems: list[str]", "note: anki.notes.Note"],
doc="""
Allows you to provide an optional reason to reject a note. A
yes / no dialog will open displaying the problem, to which the
user can decide if they would like to add the note anyway.
optional_problems is a list containing the optional reasons for which
you might reject a note. If your add-on wants to add a reason,
it should append the reason to the list.
An example add-on that asks the user for confirmation before adding a
card without tags:
def might_reject_empty_tag(optional_problems, note):
if not any(note.tags):
optional_problems.append("Add cards without tags?")
""",
),
Hook(
name="addcards_will_add_history_entry",
args=["line: str", "note: anki.notes.Note"],