From 8ecd4f8c950b53b83132ff60be2876e0027cebc7 Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Fri, 23 Apr 2021 21:25:44 +0200 Subject: [PATCH] Add simple version of Chooser buttons --- qt/aqt/addcards.py | 33 ++++++++++++++++++++++++++++ ts/editor-toolbar/ButtonGroup.svelte | 10 ++++----- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/qt/aqt/addcards.py b/qt/aqt/addcards.py index 2b109e31f..c564340a4 100644 --- a/qt/aqt/addcards.py +++ b/qt/aqt/addcards.py @@ -13,6 +13,7 @@ from anki.notes import DuplicateOrEmptyResult, Note, NoteId from anki.utils import htmlToTextLine, isMac from aqt import AnkiQt, gui_hooks from aqt.deckchooser import DeckChooser +from aqt.editor import Editor from aqt.notetypechooser import NotetypeChooser from aqt.operations.note import add_note from aqt.qt import * @@ -57,7 +58,39 @@ class AddCards(QDialog): self.show() def setupEditor(self) -> None: + def add_choosers(editor: Editor) -> None: + editor._links[ + "choosenotetype" + ] = lambda _editor: self.show_notetype_selector() + editor._links[ + "choosedeck" + ] = lambda _editor: self.deck_chooser.choose_deck() + + editor.web.eval( + f""" +const notetypeChooser = editorToolbar.labelButton({{ + label: `Choose note type`, + onClick: () => bridgeCommand("choosenotetype"), + disables: false, +}}); + +const deckChooser = editorToolbar.labelButton({{ + label: `Choose deck`, + onClick: () => bridgeCommand("choosedeck"), + disables: false, +}}); + +$editorToolbar.insertButton(editorToolbar.buttonGroup({{ + id: "choosers", + fullWidth: true, + items: [notetypeChooser, deckChooser], +}}), 0); +""" + ) + + gui_hooks.editor_did_init.append(add_choosers) self.editor = aqt.editor.Editor(self.mw, self.form.fieldsArea, self, True) + gui_hooks.editor_did_init.remove(add_choosers) def setup_choosers(self) -> None: defaults = self.col.defaults_for_adding( diff --git a/ts/editor-toolbar/ButtonGroup.svelte b/ts/editor-toolbar/ButtonGroup.svelte index b1d47e36a..6600a081a 100644 --- a/ts/editor-toolbar/ButtonGroup.svelte +++ b/ts/editor-toolbar/ButtonGroup.svelte @@ -28,12 +28,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html padding-inline-start: 0; margin: 0 0 calc(var(--toolbar-size) / 10); - } - .border-overlap-group { - :global(button), - :global(select) { - margin-left: -1px; + &.border-overlap-group { + :global(button), + :global(select) { + margin-left: -1px; + } } }