From 918bba6365ee5113f9dbcf9d61a761cfa3e324bb Mon Sep 17 00:00:00 2001 From: abdo Date: Wed, 20 Jan 2021 02:00:53 +0300 Subject: [PATCH] Add manage note types menu item to the sidebar --- qt/aqt/models.py | 3 ++- qt/aqt/sidebar.py | 14 ++++++++++++++ qt/tools/genhooks_gui.py | 5 +++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/qt/aqt/models.py b/qt/aqt/models.py index 572ec2e42..ffbcd0310 100644 --- a/qt/aqt/models.py +++ b/qt/aqt/models.py @@ -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: diff --git a/qt/aqt/sidebar.py b/qt/aqt/sidebar.py index 79c4baac2..1ffdd1c5c 100644 --- a/qt/aqt/sidebar.py +++ b/qt/aqt/sidebar.py @@ -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) diff --git a/qt/tools/genhooks_gui.py b/qt/tools/genhooks_gui.py index fdc3af8c8..e239fc429 100644 --- a/qt/tools/genhooks_gui.py +++ b/qt/tools/genhooks_gui.py @@ -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"],