Add simple version of Chooser buttons
This commit is contained in:
parent
48b7cb49f9
commit
8ecd4f8c95
@ -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(
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user