Move the logic for selecting a note type to models.py
This commit is contained in:
parent
918bba6365
commit
426ea1aba9
@ -1230,6 +1230,7 @@ QTableView {{ gridline-color: {grid} }}
|
||||
":/icons/notetype.svg",
|
||||
self._note_filter(m.name),
|
||||
item_type=SidebarItemType.NOTETYPE,
|
||||
id=m.id,
|
||||
)
|
||||
root.addChild(item)
|
||||
|
||||
|
@ -28,10 +28,17 @@ from aqt.utils import (
|
||||
|
||||
|
||||
class Models(QDialog):
|
||||
def __init__(self, mw: AnkiQt, parent=None, fromMain=False):
|
||||
def __init__(
|
||||
self,
|
||||
mw: AnkiQt,
|
||||
parent=None,
|
||||
fromMain=False,
|
||||
selected_notetype_id: Optional[int] = None,
|
||||
):
|
||||
self.mw = mw
|
||||
parent = parent or mw
|
||||
self.fromMain = fromMain
|
||||
self.selected_notetype_id = selected_notetype_id
|
||||
QDialog.__init__(self, parent, Qt.Window)
|
||||
self.col = mw.col.weakref()
|
||||
assert self.col
|
||||
@ -51,6 +58,15 @@ class Models(QDialog):
|
||||
# Models
|
||||
##########################################################################
|
||||
|
||||
def maybe_select_provided_notetype(self):
|
||||
if not self.selected_notetype_id:
|
||||
self.form.modelsList.setCurrentRow(0)
|
||||
return
|
||||
for i, m in enumerate(self.models):
|
||||
if m.id == self.selected_notetype_id:
|
||||
self.form.modelsList.setCurrentRow(i)
|
||||
break
|
||||
|
||||
def setupModels(self) -> None:
|
||||
self.model = None
|
||||
f = self.form
|
||||
@ -80,8 +96,7 @@ class Models(QDialog):
|
||||
|
||||
def on_done(fut) -> None:
|
||||
self.updateModelsList(fut.result())
|
||||
f.modelsList.setCurrentRow(0)
|
||||
gui_hooks.models_dialog_will_show(self)
|
||||
self.maybe_select_provided_notetype()
|
||||
|
||||
self.mw.taskman.with_progress(self.col.models.all_use_counts, on_done, self)
|
||||
maybeHideClose(box)
|
||||
|
@ -8,7 +8,6 @@ from enum import Enum
|
||||
|
||||
import aqt
|
||||
from anki.errors import DeckRenameError
|
||||
from aqt import gui_hooks
|
||||
from aqt.main import ResetReason
|
||||
from aqt.models import Models
|
||||
from aqt.qt import *
|
||||
@ -197,12 +196,6 @@ class NewSidebarTreeView(SidebarTreeViewBase):
|
||||
self.browser.renameFilter(item.name)
|
||||
|
||||
def manage_notetype(self, item: "aqt.browser.SidebarItem") -> None:
|
||||
def select(dialog: QDialog):
|
||||
for i, m in enumerate(dialog.models):
|
||||
if m.name == item.name:
|
||||
dialog.form.modelsList.setCurrentRow(i)
|
||||
break
|
||||
|
||||
gui_hooks.models_dialog_will_show.append(select)
|
||||
Models(self.mw, parent=self.browser, fromMain=True)
|
||||
gui_hooks.models_dialog_will_show.remove(select)
|
||||
Models(
|
||||
self.mw, parent=self.browser, fromMain=True, selected_notetype_id=item.id
|
||||
)
|
||||
|
@ -742,11 +742,6 @@ gui_hooks.webview_did_inject_style_into_page.append(mytest)
|
||||
),
|
||||
# Model
|
||||
###################
|
||||
Hook(
|
||||
name="models_dialog_will_show",
|
||||
args=["dialog: QDialog"],
|
||||
doc="""Allows changing the models dialog before it is shown.""",
|
||||
),
|
||||
Hook(
|
||||
name="models_advanced_will_show",
|
||||
args=["advanced: QDialog"],
|
||||
|
Loading…
Reference in New Issue
Block a user