I’m trying to make it so that my buttons will only show up if they can be used with the notetype of the note being loaded into the editor. However, the buttons are created before the note is loaded. So when the editor_did_init_buttons hook fires, the given editor.note is still null and I can’t check for the notetype.
def add_audio(editor: Editor):
(...)
def add_audio_btn(buttons: List[str], editor: Editor):
if not has_fields(editor.note.note_type()): # <- doesnt work because its always null
return
buttons += [editor.addButton("", "add_audio", add_audio, "", "Add Audio")]
gui_hooks.editor_did_init_buttons.append(add_audio_btn)
Try adding the button unconditionally in the editor_did_init_buttons hook, but hide it conditionally via JavaScript in the add_cards_did_change_note_type and editor_did_load_note hooks. Maybe try the CSS selector button[title="Add Audio"] to get the button in JavaScript and hide/show it.