mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
added editor hook: add_cards_might_add_note (#1992)
* added hook add_cards_might_add_note * fix failing test
This commit is contained in:
parent
d699bc1252
commit
56f806146c
2 changed files with 25 additions and 0 deletions
|
@ -296,6 +296,11 @@ class AddCards(QMainWindow):
|
||||||
showWarning(problem, help=HelpPage.ADDING_CARD_AND_NOTE)
|
showWarning(problem, help=HelpPage.ADDING_CARD_AND_NOTE)
|
||||||
return False
|
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
|
return True
|
||||||
|
|
||||||
def keyPressEvent(self, evt: QKeyEvent) -> None:
|
def keyPressEvent(self, evt: QKeyEvent) -> None:
|
||||||
|
|
|
@ -904,6 +904,26 @@ gui_hooks.webview_did_inject_style_into_page.append(mytest)
|
||||||
replace return the reason to reject. Otherwise return the
|
replace return the reason to reject. Otherwise return the
|
||||||
input.""",
|
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(
|
Hook(
|
||||||
name="addcards_will_add_history_entry",
|
name="addcards_will_add_history_entry",
|
||||||
args=["line: str", "note: anki.notes.Note"],
|
args=["line: str", "note: anki.notes.Note"],
|
||||||
|
|
Loading…
Reference in a new issue