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) self.form.gridLayout.addWidget(switch, 0, 0)
def setupEditor(self) -> None: def setupEditor(self) -> None:
def add_preview_button(leftbuttons: List[str], editor: Editor) -> None: def add_preview_button(editor: Editor) -> None:
preview_shortcut = "Ctrl+Shift+P" preview_shortcut = "Ctrl+Shift+P" # TODO
leftbuttons.insert(
0, editor._links["preview"] = lambda _editor: self.onTogglePreview()
editor.addButton( editor.web.eval(
None, f"""
"preview", $editorToolbar.addButton({{
lambda _editor: self.onTogglePreview(), component: editorToolbar.LabelButton,
tr.browsing_preview_selected_card( label: `{tr.actions_preview()}`,
val=shortcut(preview_shortcut), tooltip: `{tr.browsing_preview_selected_card(val=shortcut(preview_shortcut))}`,
), onClick: () => bridgeCommand("preview"),
tr.actions_preview(), disables: false,
id="previewButton", }}, "notetype");
keys=preview_shortcut, """
disables=False,
rightside=False,
toggleable=True,
),
) )
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) 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 @ensure_editor_saved
def onRowChanged( def onRowChanged(