Add support for Preview button in Browser

This commit is contained in:
Henrik Giesel 2021-04-14 20:41:03 +02:00
parent e732eca097
commit a7d24e7159

View File

@ -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(