mirror of
https://github.com/ankitects/anki.git
synced 2025-11-06 20:57:13 -05:00
Avoid extra initial loadNote()
This commit is contained in:
parent
0ed12f5c63
commit
783a6d1fa2
3 changed files with 17 additions and 13 deletions
|
|
@ -23,12 +23,7 @@ from aqt.utils import (
|
||||||
|
|
||||||
|
|
||||||
class NewAddCards(QMainWindow):
|
class NewAddCards(QMainWindow):
|
||||||
def __init__(
|
def __init__(self, mw: AnkiQt) -> None:
|
||||||
self,
|
|
||||||
mw: AnkiQt,
|
|
||||||
deck_id: DeckId | None = None,
|
|
||||||
notetype_id: NotetypeId | None = None,
|
|
||||||
) -> None:
|
|
||||||
super().__init__(None, Qt.WindowType.Window)
|
super().__init__(None, Qt.WindowType.Window)
|
||||||
self._close_event_has_cleaned_up = False
|
self._close_event_has_cleaned_up = False
|
||||||
self._close_callback: Callable[[], None] = self._close
|
self._close_callback: Callable[[], None] = self._close
|
||||||
|
|
@ -42,7 +37,6 @@ class NewAddCards(QMainWindow):
|
||||||
self.setMinimumWidth(400)
|
self.setMinimumWidth(400)
|
||||||
self.setupEditor()
|
self.setupEditor()
|
||||||
add_close_shortcut(self)
|
add_close_shortcut(self)
|
||||||
self._load_new_note(deck_id, notetype_id)
|
|
||||||
restoreGeom(self, "add")
|
restoreGeom(self, "add")
|
||||||
gui_hooks.add_cards_did_init(self)
|
gui_hooks.add_cards_did_init(self)
|
||||||
if not is_mac:
|
if not is_mac:
|
||||||
|
|
@ -79,7 +73,7 @@ class NewAddCards(QMainWindow):
|
||||||
def helpRequested(self) -> None:
|
def helpRequested(self) -> None:
|
||||||
openHelp(HelpPage.ADDING_CARD_AND_NOTE)
|
openHelp(HelpPage.ADDING_CARD_AND_NOTE)
|
||||||
|
|
||||||
def _load_new_note(
|
def load_new_note(
|
||||||
self, deck_id: DeckId | None = None, notetype_id: NotetypeId | None = None
|
self, deck_id: DeckId | None = None, notetype_id: NotetypeId | None = None
|
||||||
) -> None:
|
) -> None:
|
||||||
self.editor.load_note(
|
self.editor.load_note(
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,8 @@ from anki.scheduler.base import ScheduleCardsAsNew
|
||||||
from anki.tags import MARKED_TAG
|
from anki.tags import MARKED_TAG
|
||||||
from anki.utils import is_mac
|
from anki.utils import is_mac
|
||||||
from aqt import AnkiQt, gui_hooks
|
from aqt import AnkiQt, gui_hooks
|
||||||
|
from aqt.addcards import NewAddCards
|
||||||
|
from aqt.addcards_legacy import AddCards
|
||||||
from aqt.errors import show_exception
|
from aqt.errors import show_exception
|
||||||
from aqt.exporting import ExportDialog as LegacyExportDialog
|
from aqt.exporting import ExportDialog as LegacyExportDialog
|
||||||
from aqt.import_export.exporting import ExportDialog
|
from aqt.import_export.exporting import ExportDialog
|
||||||
|
|
@ -262,10 +264,14 @@ class Browser(QMainWindow):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def add_card(self, deck_id: DeckId):
|
def add_card(self, deck_id: DeckId):
|
||||||
args: list[Any] = [deck_id]
|
add_cards = self.mw._open_new_or_legacy_dialog("AddCards")
|
||||||
if note_type_id := self.get_active_note_type_id():
|
if isinstance(add_cards, AddCards):
|
||||||
args.append(note_type_id)
|
add_cards.set_deck(deck_id)
|
||||||
self.mw._open_new_or_legacy_dialog("AddCards", *args)
|
if note_type_id := self.get_active_note_type_id():
|
||||||
|
add_cards.set_note_type(note_type_id)
|
||||||
|
else:
|
||||||
|
assert isinstance(add_cards, NewAddCards)
|
||||||
|
add_cards.load_new_note(deck_id, self.get_active_note_type_id())
|
||||||
|
|
||||||
# If in the Browser we open Preview and press Ctrl+W there,
|
# If in the Browser we open Preview and press Ctrl+W there,
|
||||||
# both Preview and Browser windows get closed by Qt out of the box.
|
# both Preview and Browser windows get closed by Qt out of the box.
|
||||||
|
|
|
||||||
|
|
@ -1287,7 +1287,11 @@ title="{}" {}>{}</button>""".format(
|
||||||
return aqt.dialogs.open(name, self, *args, **kwargs)
|
return aqt.dialogs.open(name, self, *args, **kwargs)
|
||||||
|
|
||||||
def onAddCard(self) -> None:
|
def onAddCard(self) -> None:
|
||||||
self._open_new_or_legacy_dialog("AddCards")
|
from aqt.addcards import NewAddCards
|
||||||
|
|
||||||
|
add_cards = self._open_new_or_legacy_dialog("AddCards")
|
||||||
|
if isinstance(add_cards, NewAddCards):
|
||||||
|
add_cards.load_new_note()
|
||||||
|
|
||||||
def onBrowse(self) -> None:
|
def onBrowse(self) -> None:
|
||||||
aqt.dialogs.open("Browser", self, card=self.reviewer.card)
|
aqt.dialogs.open("Browser", self, card=self.reviewer.card)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue