Add manage note types menu item to the sidebar

This commit is contained in:
abdo 2021-01-20 02:00:53 +03:00
parent bc2257da39
commit 918bba6365
3 changed files with 21 additions and 1 deletions

View File

@ -80,9 +80,10 @@ class Models(QDialog):
def on_done(fut) -> None:
self.updateModelsList(fut.result())
f.modelsList.setCurrentRow(0)
gui_hooks.models_dialog_will_show(self)
self.mw.taskman.with_progress(self.col.models.all_use_counts, on_done, self)
f.modelsList.setCurrentRow(0)
maybeHideClose(box)
def onRename(self) -> None:

View File

@ -8,7 +8,9 @@ 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 *
from aqt.utils import TR, getOnlyText, showInfo, showWarning, tr
@ -84,6 +86,7 @@ class NewSidebarTreeView(SidebarTreeViewBase):
(tr(TR.ACTIONS_RENAME), self.rename_filter),
(tr(TR.ACTIONS_DELETE), self.remove_filter),
),
SidebarItemType.NOTETYPE: ((tr(TR.ACTIONS_MANAGE), self.manage_notetype),),
}
def onContextMenu(self, point: QPoint) -> None:
@ -192,3 +195,14 @@ class NewSidebarTreeView(SidebarTreeViewBase):
def rename_filter(self, item: "aqt.browser.SidebarItem") -> None:
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)

View File

@ -742,6 +742,11 @@ 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"],