From a7d24e71598b66a349ad0128f050ccad5423028b Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Wed, 14 Apr 2021 20:41:03 +0200 Subject: [PATCH] Add support for Preview button in Browser --- qt/aqt/browser/browser.py | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/qt/aqt/browser/browser.py b/qt/aqt/browser/browser.py index a50d4642f..6e485c83e 100644 --- a/qt/aqt/browser/browser.py +++ b/qt/aqt/browser/browser.py @@ -380,29 +380,25 @@ class Browser(QMainWindow): self.form.gridLayout.addWidget(switch, 0, 0) def setupEditor(self) -> None: - def add_preview_button(leftbuttons: List[str], editor: Editor) -> None: - preview_shortcut = "Ctrl+Shift+P" - leftbuttons.insert( - 0, - editor.addButton( - None, - "preview", - lambda _editor: self.onTogglePreview(), - tr.browsing_preview_selected_card( - val=shortcut(preview_shortcut), - ), - tr.actions_preview(), - id="previewButton", - keys=preview_shortcut, - disables=False, - rightside=False, - toggleable=True, - ), + def add_preview_button(editor: Editor) -> None: + preview_shortcut = "Ctrl+Shift+P" # TODO + + editor._links["preview"] = lambda _editor: self.onTogglePreview() + editor.web.eval( + f""" +$editorToolbar.addButton({{ + component: editorToolbar.LabelButton, + label: `{tr.actions_preview()}`, + tooltip: `{tr.browsing_preview_selected_card(val=shortcut(preview_shortcut))}`, + onClick: () => bridgeCommand("preview"), + disables: false, +}}, "notetype"); +""" ) - gui_hooks.editor_did_init_left_buttons.append(add_preview_button) + gui_hooks.editor_did_init.append(add_preview_button) self.editor = aqt.editor.Editor(self.mw, self.form.fieldsArea, self) - gui_hooks.editor_did_init_left_buttons.remove(add_preview_button) + gui_hooks.editor_did_init.remove(add_preview_button) @ensure_editor_saved def onRowChanged(