mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
fix IndexError when switching notetypes
Closes #780 https://github.com/ankitects/anki/pull/780
This commit is contained in:
parent
8fa865e8f4
commit
bf72773531
2 changed files with 22 additions and 4 deletions
|
@ -55,7 +55,9 @@ class AddCards(QDialog):
|
||||||
self.editor = aqt.editor.Editor(self.mw, self.form.fieldsArea, self, True)
|
self.editor = aqt.editor.Editor(self.mw, self.form.fieldsArea, self, True)
|
||||||
|
|
||||||
def setupChoosers(self) -> None:
|
def setupChoosers(self) -> None:
|
||||||
self.modelChooser = aqt.modelchooser.ModelChooser(self.mw, self.form.modelArea)
|
self.modelChooser = aqt.modelchooser.ModelChooser(
|
||||||
|
self.mw, self.form.modelArea, on_activated=self.show_notetype_selector
|
||||||
|
)
|
||||||
self.deckChooser = aqt.deckchooser.DeckChooser(self.mw, self.form.deckArea)
|
self.deckChooser = aqt.deckchooser.DeckChooser(self.mw, self.form.deckArea)
|
||||||
|
|
||||||
def helpRequested(self):
|
def helpRequested(self):
|
||||||
|
@ -92,6 +94,9 @@ class AddCards(QDialog):
|
||||||
def setAndFocusNote(self, note: Note) -> None:
|
def setAndFocusNote(self, note: Note) -> None:
|
||||||
self.editor.setNote(note, focusTo=0)
|
self.editor.setNote(note, focusTo=0)
|
||||||
|
|
||||||
|
def show_notetype_selector(self) -> None:
|
||||||
|
self.editor.saveNow(self.modelChooser.onModelChange)
|
||||||
|
|
||||||
def onModelChange(self, unused=None) -> None:
|
def onModelChange(self, unused=None) -> None:
|
||||||
oldNote = self.editor.note
|
oldNote = self.editor.note
|
||||||
note = self.mw.col.newNote()
|
note = self.mw.col.newNote()
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright: Ankitects Pty Ltd and contributors
|
# Copyright: Ankitects Pty Ltd and contributors
|
||||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from anki.lang import _
|
from anki.lang import _
|
||||||
from aqt import AnkiQt, gui_hooks
|
from aqt import AnkiQt, gui_hooks
|
||||||
|
@ -9,12 +10,25 @@ from aqt.utils import shortcut
|
||||||
|
|
||||||
|
|
||||||
class ModelChooser(QHBoxLayout):
|
class ModelChooser(QHBoxLayout):
|
||||||
def __init__(self, mw: AnkiQt, widget: QWidget, label: bool = True) -> None:
|
def __init__(
|
||||||
|
self,
|
||||||
|
mw: AnkiQt,
|
||||||
|
widget: QWidget,
|
||||||
|
label: bool = True,
|
||||||
|
on_activated: Optional[Callable[[], None]] = None,
|
||||||
|
) -> None:
|
||||||
|
"""If provided, on_activated() will be called when the button is clicked,
|
||||||
|
and the caller can call .onModelChange() to pull up the dialog when they
|
||||||
|
are ready."""
|
||||||
QHBoxLayout.__init__(self)
|
QHBoxLayout.__init__(self)
|
||||||
self.widget = widget # type: ignore
|
self.widget = widget # type: ignore
|
||||||
self.mw = mw
|
self.mw = mw
|
||||||
self.deck = mw.col
|
self.deck = mw.col
|
||||||
self.label = label
|
self.label = label
|
||||||
|
if on_activated:
|
||||||
|
self.on_activated = on_activated
|
||||||
|
else:
|
||||||
|
self.on_activated = self.onModelChange
|
||||||
self.setContentsMargins(0, 0, 0, 0)
|
self.setContentsMargins(0, 0, 0, 0)
|
||||||
self.setSpacing(8)
|
self.setSpacing(8)
|
||||||
self.setupModels()
|
self.setupModels()
|
||||||
|
@ -27,9 +41,8 @@ class ModelChooser(QHBoxLayout):
|
||||||
self.addWidget(self.modelLabel)
|
self.addWidget(self.modelLabel)
|
||||||
# models box
|
# models box
|
||||||
self.models = QPushButton()
|
self.models = QPushButton()
|
||||||
# self.models.setStyleSheet("* { text-align: left; }")
|
|
||||||
self.models.setToolTip(shortcut(_("Change Note Type (Ctrl+N)")))
|
self.models.setToolTip(shortcut(_("Change Note Type (Ctrl+N)")))
|
||||||
QShortcut(QKeySequence("Ctrl+N"), self.widget, activated=self.onModelChange) # type: ignore
|
QShortcut(QKeySequence("Ctrl+N"), self.widget, activated=self.on_activated) # type: ignore
|
||||||
self.models.setAutoDefault(False)
|
self.models.setAutoDefault(False)
|
||||||
self.addWidget(self.models)
|
self.addWidget(self.models)
|
||||||
qconnect(self.models.clicked, self.onModelChange)
|
qconnect(self.models.clicked, self.onModelChange)
|
||||||
|
|
Loading…
Reference in a new issue