def _flags_tree(self, root: SidebarItem) -> None: icon = ":/icons/flag.svg" icon_outline = ":/icons/flag-outline.svg" root = self._section_root( root=root, name=tr.browsing_sidebar_flags(), icon=icon_outline, collapse_key=Config.Bool.COLLAPSE_FLAGS, type=SidebarItemType.FLAG_ROOT, ) root.search_node = SearchNode(flag=SearchNode.FLAG_ANY) for flag in self.mw.flags.all(): root.add_child( SidebarItem( name=flag.label, icon=flag.icon, search_node=flag.search_node, item_type=SidebarItemType.FLAG, id=flag.index, )) root.add_simple( tr.browsing_no_flag(), icon=icon_outline, type=SidebarItemType.FLAG, search_node=SearchNode(flag=SearchNode.FLAG_NONE), )
def _flags_tree(self, root: SidebarItem) -> None: icon = ColoredIcon(path=":/icons/flag.svg", color=colors.DISABLED) root = self._section_root( root=root, name=tr.browsing_sidebar_flags(), icon=icon, collapse_key=Config.Bool.COLLAPSE_FLAGS, type=SidebarItemType.FLAG_ROOT, ) root.search_node = SearchNode(flag=SearchNode.FLAG_ANY) for flag in load_flags(self.col): root.add_child( SidebarItem( name=flag.label, icon=flag.icon, search_node=flag.search_node, item_type=SidebarItemType.FLAG, id=flag.index, )) root.add_simple( tr.browsing_no_flag(), icon=icon, type=SidebarItemType.FLAG, search_node=SearchNode(flag=SearchNode.FLAG_NONE), )
def _deck_tree(self, root: SidebarItem) -> None: icon = "icons:book-outline.svg" icon_current = "icons:book-clock-outline.svg" icon_filtered = "icons:book-cog-outline.svg" def render( root: SidebarItem, nodes: Iterable[DeckTreeNode], head: str = "" ) -> None: def toggle_expand(node: DeckTreeNode) -> Callable[[bool], None]: return lambda expanded: set_deck_collapsed( parent=self, deck_id=DeckId(node.deck_id), collapsed=not expanded, scope=DeckCollapseScope.BROWSER, ).run_in_background( initiator=self, ) for node in nodes: item = SidebarItem( name=node.name, icon=icon_filtered if node.filtered else icon, search_node=SearchNode(deck=head + node.name), on_expanded=toggle_expand(node), expanded=not node.collapsed, item_type=SidebarItemType.DECK, id=node.deck_id, name_prefix=head, ) root.add_child(item) newhead = f"{head + node.name}::" render(item, node.children, newhead) tree = self.col.decks.deck_tree() root = self._section_root( root=root, name=tr.browsing_sidebar_decks(), icon=icon, collapse_key=Config.Bool.COLLAPSE_DECKS, type=SidebarItemType.DECK_ROOT, ) root.search_node = SearchNode(deck="_*") current = root.add_simple( name=tr.browsing_current_deck(), icon=icon_current, type=SidebarItemType.DECK_CURRENT, search_node=SearchNode(deck="current"), ) current.id = self.mw.col.decks.selected() render(root, tree.children)
def _notetype_tree(self, root: SidebarItem) -> None: notetype_icon = ":/icons/newspaper.svg" template_icon = ":/icons/iframe-braces-outline.svg" field_icon = ":/icons/form-textbox.svg" root = self._section_root( root=root, name=tr.browsing_sidebar_notetypes(), icon=notetype_icon, collapse_key=Config.Bool.COLLAPSE_NOTETYPES, type=SidebarItemType.NOTETYPE_ROOT, ) root.search_node = SearchNode(note="_*") for nt in sorted(self.col.models.all(), key=lambda nt: nt["name"].lower()): item = SidebarItem( nt["name"], notetype_icon, search_node=SearchNode(note=nt["name"]), item_type=SidebarItemType.NOTETYPE, id=nt["id"], ) for c, tmpl in enumerate(nt["tmpls"]): child = SidebarItem( tmpl["name"], template_icon, search_node=self.col.group_searches( SearchNode(note=nt["name"]), SearchNode(template=c)), item_type=SidebarItemType.NOTETYPE_TEMPLATE, name_prefix=f"{nt['name']}::", id=tmpl["ord"], ) item.add_child(child) for c, fld in enumerate(nt["flds"]): child = SidebarItem( fld["name"], field_icon, search_node=self.col.group_searches( SearchNode(note=nt["name"]), SearchNode(field_name=fld["name"])), item_type=SidebarItemType.NOTETYPE_FIELD, id=fld["ord"], ) item.add_child(child) root.add_child(item)
def _tag_tree(self, root: SidebarItem) -> None: icon = ":/icons/tag-outline.svg" icon_off = ":/icons/tag-off-outline.svg" def render(root: SidebarItem, nodes: Iterable[TagTreeNode], head: str = "") -> None: def toggle_expand(node: TagTreeNode) -> Callable[[bool], None]: full_name = head + node.name return lambda expanded: set_tag_collapsed( parent=self, tag=full_name, collapsed=not expanded ).run_in_background(initiator=self) for node in nodes: item = SidebarItem( name=node.name, icon=icon, search_node=SearchNode(tag=head + node.name), on_expanded=toggle_expand(node), expanded=not node.collapsed, item_type=SidebarItemType.TAG, name_prefix=head, ) root.add_child(item) newhead = f"{head + node.name}::" render(item, node.children, newhead) tree = self.col.tags.tree() root = self._section_root( root=root, name=tr.browsing_sidebar_tags(), icon=icon, collapse_key=Config.Bool.COLLAPSE_TAGS, type=SidebarItemType.TAG_ROOT, ) root.search_node = SearchNode(tag="_*") root.add_simple( name=tr.browsing_sidebar_untagged(), icon=icon_off, type=SidebarItemType.TAG_NONE, search_node=SearchNode(negated=SearchNode(tag="_*")), ) render(root, tree.children)
def _flags_tree(self, root: SidebarItem) -> None: icon = ColoredIcon(path=":/icons/flag.svg", color=colors.DISABLED) root = self._section_root( root=root, name=tr.browsing_sidebar_flags(), icon=icon, collapse_key=Config.Bool.COLLAPSE_FLAGS, type=SidebarItemType.FLAG_ROOT, ) root.search_node = SearchNode(flag=SearchNode.FLAG_ANY) type = SidebarItemType.FLAG root.add_simple( tr.actions_red_flag(), icon=icon.with_color(colors.FLAG1_FG), type=type, search_node=SearchNode(flag=SearchNode.FLAG_RED), ) root.add_simple( tr.actions_orange_flag(), icon=icon.with_color(colors.FLAG2_FG), type=type, search_node=SearchNode(flag=SearchNode.FLAG_ORANGE), ) root.add_simple( tr.actions_green_flag(), icon=icon.with_color(colors.FLAG3_FG), type=type, search_node=SearchNode(flag=SearchNode.FLAG_GREEN), ) root.add_simple( tr.actions_blue_flag(), icon=icon.with_color(colors.FLAG4_FG), type=type, search_node=SearchNode(flag=SearchNode.FLAG_BLUE), ) root.add_simple( tr.browsing_no_flag(), icon=icon.with_color(colors.DISABLED), type=type, search_node=SearchNode(flag=SearchNode.FLAG_NONE), )