From 4379f1e84fcc82b59e18c98dc6abf2b41444968b Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Fri, 23 Apr 2021 16:43:36 +0200 Subject: [PATCH] Make dynamicComponents usable for addons, rather than the components directly rawButton({ html: ... }) instead of { component: RawButton, html: ... } --- qt/aqt/editor.py | 12 +++---- ts/editor-toolbar/SelectButton.d.ts | 18 +++++++++++ ts/editor-toolbar/SelectButton.svelte | 7 +--- ts/editor-toolbar/dynamicComponents.ts | 9 ++++++ ts/editor/addons.ts | 45 +++++++++++++++----------- ts/sass/base.scss | 3 +- 6 files changed, 60 insertions(+), 34 deletions(-) create mode 100644 ts/editor-toolbar/SelectButton.d.ts diff --git a/qt/aqt/editor.py b/qt/aqt/editor.py index 808cdf86c..0b0f9ce07 100644 --- a/qt/aqt/editor.py +++ b/qt/aqt/editor.py @@ -155,7 +155,7 @@ class Editor: gui_hooks.editor_did_init_left_buttons(lefttopbtns, self) lefttopbtns_defs = [ - f"$editorToolbar.addButton({{ component: editorToolbar.RawButton, html: `{button}` }}, 'notetype');" + f"$editorToolbar.addButton(editorToolbar.rawButton({{ html: `{button}` }}), 'notetype');" for button in lefttopbtns ] lefttopbtns_js = "\n".join(lefttopbtns_defs) @@ -167,7 +167,7 @@ class Editor: righttopbtns_defs = "\n".join( [ - f"{{ component: editorToolbar.RawButton, html: `{button}` }}," + f"editorToolbar.rawButton({{ html: `{button}` }})," for button in righttopbtns ] ) @@ -1277,13 +1277,9 @@ gui_hooks.editor_will_munge_html.append(reverse_url_quoting) def set_cloze_button(editor: Editor) -> None: if editor.note.model()["type"] == MODEL_CLOZE: - editor.web.eval( - 'document.getElementById("editorToolbar").showButton("template", "cloze"); ' - ) + editor.web.eval('$editorToolbar.showButton("template", "cloze"); ') else: - editor.web.eval( - 'document.getElementById("editorToolbar").hideButton("template", "cloze"); ' - ) + editor.web.eval('$editorToolbar.hideButton("template", "cloze"); ') gui_hooks.editor_did_load_note.append(set_cloze_button) diff --git a/ts/editor-toolbar/SelectButton.d.ts b/ts/editor-toolbar/SelectButton.d.ts new file mode 100644 index 000000000..854f7eb97 --- /dev/null +++ b/ts/editor-toolbar/SelectButton.d.ts @@ -0,0 +1,18 @@ +// Copyright: Ankitects Pty Ltd and contributors +// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +import type { ToolbarItem } from "./types"; + +export interface Option { + label: string; + value: string; + selected: boolean; +} + +export interface SelectButtonProps { + id: string; + className?: string; + tooltip?: string; + buttons: ToolbarItem[]; + disables: boolean; + options: Option[]; +} diff --git a/ts/editor-toolbar/SelectButton.svelte b/ts/editor-toolbar/SelectButton.svelte index 559ab8cfc..81afa44d8 100644 --- a/ts/editor-toolbar/SelectButton.svelte +++ b/ts/editor-toolbar/SelectButton.svelte @@ -4,16 +4,11 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -->