Add api method guiEditNote

This commit is contained in:
oakkitten 2022-03-30 20:26:26 +01:00
parent 2313b8ba65
commit 8aa5fdd1de
2 changed files with 38 additions and 0 deletions

View File

@ -1059,6 +1059,34 @@ corresponding to when the API was available for use.
}
```
* **guiEditNote**
Opens the *Edit* dialog with a note corresponding to given note ID.
The dialog is similar to the *Edit Current* dialog, but:
* has a Preview button to preview the cards for the note
* has a Browse button to open the browser with these cards
* has Previous/Back buttons to navigate the history of the dialog
* has no bar with the Close button
*Sample request*:
```json
{
"action": "guiEditNote",
"version": 6,
"params": {
"note": 1649198355435
}
}
```
*Sample result*:
```json
{
"result": null,
"error": null
}
```
* **guiCurrentCard**
Returns information about the current card or `null` if not in review mode.

View File

@ -41,6 +41,8 @@ from anki.exporting import AnkiPackageExporter
from anki.importing import AnkiPackageImporter
from anki.notes import Note
from .edit import Edit
try:
from anki.rsbackend import NotFoundError
except:
@ -1366,6 +1368,12 @@ class AnkiConnect:
return self.findCards(query)
@util.api()
def guiEditNote(self, note):
Edit.open_dialog_and_show_note_with_id(note)
@util.api()
def guiSelectedNotes(self):
(creator, instance) = aqt.dialogs._dialogs['Browser']
@ -1706,6 +1714,8 @@ class AnkiConnect:
# when run inside Anki, `__name__` would be either numeric,
# or, if installed via `link.sh`, `AnkiConnectDev`
if __name__ != "plugin":
Edit.register_with_dialog_manager()
ac = AnkiConnect()
ac.initLogging()
ac.startWebServer()