mirror of
https://github.com/ankitects/anki.git
synced 2026-01-13 14:03:55 -05:00
Fix: remove duplicated logic in flip button callback
This commit is contained in:
parent
d27e2705c5
commit
f74f583b7b
1 changed files with 10 additions and 10 deletions
|
|
@ -1792,20 +1792,20 @@ gui_hooks.editor_did_load_note.append(set_cloze_button)
|
|||
gui_hooks.editor_did_load_note.append(set_image_occlusion_button)
|
||||
|
||||
def add_flip_button(buttons, editor: Editor):
|
||||
# Callback-Funktion beim Klick: zuerst Änderungen speichern, dann Flip ausführen
|
||||
|
||||
def on_flip(editor: Editor):
|
||||
editor.saveNow(lambda: flip_fields(editor))
|
||||
# Felder tauschen und Editor aktualisieren
|
||||
|
||||
def flip_fields(editor: Editor):
|
||||
front_text = editor.note["Front"] # aktuellen Front-Text auslesen
|
||||
back_text = editor.note["Back"] # aktuellen Back-Text auslesen
|
||||
editor.note["Front"] = back_text # Front-Feld setzen
|
||||
editor.note["Back"] = front_text # Back-Feld setzen
|
||||
editor.loadNote() # Editor-Ansicht mit neuen Werten aktualisieren
|
||||
if not editor.addMode: # Änderungen in DB schreiben (falls bestehende Notiz)
|
||||
front_text = editor.note["Front"]
|
||||
back_text = editor.note["Back"]
|
||||
editor.note["Front"] = back_text
|
||||
editor.note["Back"] = front_text
|
||||
editor.loadNote()
|
||||
if not editor.addMode:
|
||||
editor.note.flush()
|
||||
tooltip("Fields flipped successfully.") # Erfolgsmeldung anzeigen
|
||||
# Neuen Button dem Editor hinzufügen (↔ Symbol, Tooltip-Text)
|
||||
tooltip("Fields flipped successfully.")
|
||||
|
||||
btn = editor.addButton(
|
||||
icon=None,
|
||||
cmd="flipFields",
|
||||
|
|
|
|||
Loading…
Reference in a new issue