From 0110102ea2111557674391300ce4542b7d986901 Mon Sep 17 00:00:00 2001 From: abdo Date: Fri, 22 Jan 2021 17:49:20 +0300 Subject: [PATCH] Render card templates as trees in the sidebar Reusing the note type icon and not caring about saving collapse state for now. --- qt/aqt/browser.py | 19 +++++++++++++++---- qt/aqt/sidebar.py | 1 + 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index d6acff4b6..757fe138f 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -1224,14 +1224,25 @@ QTableView {{ gridline-color: {grid} }} def _modelTree(self, root) -> None: assert self.col - for m in self.col.models.all_names_and_ids(): + + for nt in sorted(self.col.models.all(), key=lambda nt: nt["name"].lower()): item = SidebarItem( - m.name, + nt["name"], ":/icons/notetype.svg", - self._note_filter(m.name), + self._note_filter(nt["name"]), item_type=SidebarItemType.NOTETYPE, - id=m.id, + id=nt["id"], ) + + for c, tmpl in enumerate(nt["tmpls"]): + child = SidebarItem( + tmpl["name"], + ":/icons/notetype.svg", + self._template_filter(nt["name"], c), + item_type=SidebarItemType.TEMPLATE, + ) + item.addChild(child) + root.addChild(item) # Filter tree diff --git a/qt/aqt/sidebar.py b/qt/aqt/sidebar.py index e3658ecd7..a07d54f2b 100644 --- a/qt/aqt/sidebar.py +++ b/qt/aqt/sidebar.py @@ -23,6 +23,7 @@ class SidebarItemType(Enum): NOTETYPE = 5 TAG = 6 CUSTOM = 7 + TEMPLATE = 8 class SidebarTreeViewBase(QTreeView):