Merge pull request #137 from hgiesel/furtherdev
Make guiAddCards have a return value
This commit is contained in:
commit
96bb9e17c9
@ -1594,6 +1594,8 @@ guarantee that your application continues to function properly in the future.
|
||||
The `closeAfterAdding` member inside `options` group can be set to true to create a dialog that closes upon adding the note.
|
||||
Invoking the action mutliple times with this option will create _multiple windows_.
|
||||
|
||||
The result is the ID of the note which would be added, if the user chose to confirm the *Add Cards* dialogue.
|
||||
|
||||
*Sample request*:
|
||||
```json
|
||||
{
|
||||
@ -1621,7 +1623,7 @@ guarantee that your application continues to function properly in the future.
|
||||
*Sample result*:
|
||||
```json
|
||||
{
|
||||
"result": null,
|
||||
"result": 1496198395707,
|
||||
"error": null
|
||||
}
|
||||
```
|
||||
|
@ -977,44 +977,53 @@ class AnkiConnect:
|
||||
aqt.dialogs.open(windowName, self.window())
|
||||
addCards.setAndFocusNote(editor.note)
|
||||
|
||||
return ankiNote.id
|
||||
|
||||
elif note is not None:
|
||||
currentWindow = aqt.dialogs._dialogs['AddCards'][1]
|
||||
collection = self.collection()
|
||||
ankiNote = anki.notes.Note(collection, model)
|
||||
|
||||
# fill out card beforehand, so we can be sure of the note id
|
||||
if 'fields' in note:
|
||||
for name, value in note['fields'].items():
|
||||
if name in ankiNote:
|
||||
ankiNote[name] = value
|
||||
|
||||
if 'tags' in note:
|
||||
ankiNote.tags = note['tags']
|
||||
|
||||
def openNewWindow():
|
||||
nonlocal ankiNote
|
||||
|
||||
addCards = aqt.dialogs.open('AddCards', self.window())
|
||||
|
||||
if savedMid:
|
||||
deck['mid'] = savedMid
|
||||
|
||||
editor = addCards.editor
|
||||
ankiNote = editor.note
|
||||
|
||||
# we have to fill out the card in the callback
|
||||
# otherwise we can't assure, the new window is open
|
||||
if 'fields' in note:
|
||||
for name, value in note['fields'].items():
|
||||
if name in ankiNote:
|
||||
ankiNote[name] = value
|
||||
editor.loadNote()
|
||||
|
||||
if 'tags' in note:
|
||||
ankiNote.tags = note['tags']
|
||||
editor.updateTags()
|
||||
addCards.editor.note = ankiNote
|
||||
addCards.editor.loadNote()
|
||||
addCards.editor.updateTags()
|
||||
|
||||
addCards.activateWindow()
|
||||
|
||||
aqt.dialogs.open('AddCards', self.window())
|
||||
addCards.setAndFocusNote(editor.note)
|
||||
addCards.setAndFocusNote(addCards.editor.note)
|
||||
|
||||
currentWindow = aqt.dialogs._dialogs['AddCards'][1]
|
||||
|
||||
if currentWindow is not None:
|
||||
currentWindow.closeWithCallback(openNewWindow)
|
||||
else:
|
||||
openNewWindow()
|
||||
|
||||
return ankiNote.id
|
||||
|
||||
else:
|
||||
addCards = aqt.dialogs.open('AddCards', self.window())
|
||||
addCards.activateWindow()
|
||||
|
||||
return addCards.editor.note.id
|
||||
|
||||
@util.api()
|
||||
def guiReviewActive(self):
|
||||
return self.reviewer().card is not None and self.window().state == 'review'
|
||||
|
Loading…
Reference in New Issue
Block a user