Fix return value of guiAddCards
* For the case where the current AddCards dialogue has to be closed first
This commit is contained in:
parent
db602ebe9a
commit
1824cd8c1c
@ -980,40 +980,43 @@ class AnkiConnect:
|
|||||||
return ankiNote.id
|
return ankiNote.id
|
||||||
|
|
||||||
elif note is not None:
|
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():
|
def openNewWindow():
|
||||||
|
nonlocal ankiNote
|
||||||
|
|
||||||
addCards = aqt.dialogs.open('AddCards', self.window())
|
addCards = aqt.dialogs.open('AddCards', self.window())
|
||||||
|
|
||||||
if savedMid:
|
if savedMid:
|
||||||
deck['mid'] = savedMid
|
deck['mid'] = savedMid
|
||||||
|
|
||||||
editor = addCards.editor
|
addCards.editor.note = ankiNote
|
||||||
ankiNote = editor.note
|
addCards.editor.loadNote()
|
||||||
|
addCards.editor.updateTags()
|
||||||
# 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.activateWindow()
|
addCards.activateWindow()
|
||||||
|
|
||||||
aqt.dialogs.open('AddCards', self.window())
|
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:
|
if currentWindow is not None:
|
||||||
currentWindow.closeWithCallback(openNewWindow)
|
currentWindow.closeWithCallback(openNewWindow)
|
||||||
else:
|
else:
|
||||||
openNewWindow()
|
openNewWindow()
|
||||||
|
|
||||||
return aqt.dialogs._dialogs['AddCards'][1].editor.note.id
|
return ankiNote.id
|
||||||
|
|
||||||
else:
|
else:
|
||||||
addCards = aqt.dialogs.open('AddCards', self.window())
|
addCards = aqt.dialogs.open('AddCards', self.window())
|
||||||
|
Loading…
Reference in New Issue
Block a user