mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
Add NOTETYPE_FIELD sidebar items
This commit is contained in:
parent
6f201bdfe4
commit
aacf20531e
4 changed files with 33 additions and 5 deletions
|
@ -25,6 +25,7 @@ class SidebarItemType(Enum):
|
||||||
NOTETYPE_ROOT = auto()
|
NOTETYPE_ROOT = auto()
|
||||||
NOTETYPE = auto()
|
NOTETYPE = auto()
|
||||||
NOTETYPE_TEMPLATE = auto()
|
NOTETYPE_TEMPLATE = auto()
|
||||||
|
NOTETYPE_FIELD = auto()
|
||||||
TAG_ROOT = auto()
|
TAG_ROOT = auto()
|
||||||
TAG_NONE = auto()
|
TAG_NONE = auto()
|
||||||
TAG = auto()
|
TAG = auto()
|
||||||
|
@ -144,7 +145,10 @@ class SidebarItem:
|
||||||
SidebarItemType.CARD_STATE,
|
SidebarItemType.CARD_STATE,
|
||||||
):
|
):
|
||||||
return self.name == other.name
|
return self.name == other.name
|
||||||
elif self.item_type == SidebarItemType.NOTETYPE_TEMPLATE:
|
elif self.item_type in [
|
||||||
|
SidebarItemType.NOTETYPE_TEMPLATE,
|
||||||
|
SidebarItemType.NOTETYPE_FIELD,
|
||||||
|
]:
|
||||||
return (
|
return (
|
||||||
other.id == self.id
|
other.id == self.id
|
||||||
and other._parent_item.id == self._parent_item.id
|
and other._parent_item.id == self._parent_item.id
|
||||||
|
|
|
@ -25,6 +25,7 @@ from aqt.browser.sidebar.model import SidebarModel
|
||||||
from aqt.browser.sidebar.searchbar import SidebarSearchBar
|
from aqt.browser.sidebar.searchbar import SidebarSearchBar
|
||||||
from aqt.browser.sidebar.toolbar import SidebarTool, SidebarToolbar
|
from aqt.browser.sidebar.toolbar import SidebarTool, SidebarToolbar
|
||||||
from aqt.clayout import CardLayout
|
from aqt.clayout import CardLayout
|
||||||
|
from aqt.fields import FieldDialog
|
||||||
from aqt.flags import load_flags
|
from aqt.flags import load_flags
|
||||||
from aqt.models import Models
|
from aqt.models import Models
|
||||||
from aqt.operations import CollectionOp, QueryOp
|
from aqt.operations import CollectionOp, QueryOp
|
||||||
|
@ -805,7 +806,7 @@ class SidebarTreeView(QTreeView):
|
||||||
notetype_icon = ":/icons/newspaper-variant-outline.svg"
|
notetype_icon = ":/icons/newspaper-variant-outline.svg"
|
||||||
notetype_multiple_icon = ":/icons/newspaper-variant-multiple-outline.svg"
|
notetype_multiple_icon = ":/icons/newspaper-variant-multiple-outline.svg"
|
||||||
template_icon = ":/icons/card-bulleted-outline.svg"
|
template_icon = ":/icons/card-bulleted-outline.svg"
|
||||||
# field_icon = ":/icons/form-textbox.svg"
|
field_icon = ":/icons/form-textbox.svg"
|
||||||
|
|
||||||
root = self._section_root(
|
root = self._section_root(
|
||||||
root=root,
|
root=root,
|
||||||
|
@ -838,6 +839,19 @@ class SidebarTreeView(QTreeView):
|
||||||
)
|
)
|
||||||
item.add_child(child)
|
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,
|
||||||
|
name_prefix=f"{nt['name']}::",
|
||||||
|
id=fld["ord"],
|
||||||
|
)
|
||||||
|
item.add_child(child)
|
||||||
|
|
||||||
root.add_child(item)
|
root.add_child(item)
|
||||||
|
|
||||||
# Context menu
|
# Context menu
|
||||||
|
@ -867,6 +881,8 @@ class SidebarTreeView(QTreeView):
|
||||||
)
|
)
|
||||||
elif item.item_type == SidebarItemType.NOTETYPE_TEMPLATE:
|
elif item.item_type == SidebarItemType.NOTETYPE_TEMPLATE:
|
||||||
menu.addAction(tr.notetypes_cards(), lambda: self.manage_template(item))
|
menu.addAction(tr.notetypes_cards(), lambda: self.manage_template(item))
|
||||||
|
elif item.item_type == SidebarItemType.NOTETYPE_FIELD:
|
||||||
|
menu.addAction(tr.notetypes_fields(), lambda: self.manage_fields(item))
|
||||||
elif item.item_type == SidebarItemType.SAVED_SEARCH_ROOT:
|
elif item.item_type == SidebarItemType.SAVED_SEARCH_ROOT:
|
||||||
menu.addAction(
|
menu.addAction(
|
||||||
tr.browsing_sidebar_save_current_search(), self.save_current_search
|
tr.browsing_sidebar_save_current_search(), self.save_current_search
|
||||||
|
@ -1108,6 +1124,10 @@ class SidebarTreeView(QTreeView):
|
||||||
note = Note(self.col, self.col.models.get(NotetypeId(item._parent_item.id)))
|
note = Note(self.col, self.col.models.get(NotetypeId(item._parent_item.id)))
|
||||||
CardLayout(self.mw, note, ord=item.id, parent=self, fill_empty=True)
|
CardLayout(self.mw, note, ord=item.id, parent=self, fill_empty=True)
|
||||||
|
|
||||||
|
def manage_fields(self, item: SidebarItem) -> None:
|
||||||
|
notetype = self.mw.col.models.get(NotetypeId(item._parent_item.id))
|
||||||
|
FieldDialog(self.mw, notetype, parent=self, open_at=item.id)
|
||||||
|
|
||||||
# Helpers
|
# Helpers
|
||||||
####################################
|
####################################
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,11 @@ from aqt.utils import (
|
||||||
|
|
||||||
class FieldDialog(QDialog):
|
class FieldDialog(QDialog):
|
||||||
def __init__(
|
def __init__(
|
||||||
self, mw: AnkiQt, nt: NotetypeDict, parent: Optional[QWidget] = None
|
self,
|
||||||
|
mw: AnkiQt,
|
||||||
|
nt: NotetypeDict,
|
||||||
|
parent: Optional[QWidget] = None,
|
||||||
|
open_at=0,
|
||||||
) -> None:
|
) -> None:
|
||||||
QDialog.__init__(self, parent or mw)
|
QDialog.__init__(self, parent or mw)
|
||||||
self.mw = mw
|
self.mw = mw
|
||||||
|
@ -47,7 +51,7 @@ class FieldDialog(QDialog):
|
||||||
self.setupSignals()
|
self.setupSignals()
|
||||||
self.form.fieldList.setDragDropMode(QAbstractItemView.InternalMove)
|
self.form.fieldList.setDragDropMode(QAbstractItemView.InternalMove)
|
||||||
self.form.fieldList.dropEvent = self.onDrop # type: ignore[assignment]
|
self.form.fieldList.dropEvent = self.onDrop # type: ignore[assignment]
|
||||||
self.form.fieldList.setCurrentRow(0)
|
self.form.fieldList.setCurrentRow(open_at)
|
||||||
self.exec_()
|
self.exec_()
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
|
@ -42,7 +42,7 @@ impl TryFrom<pb::SearchNode> for Node {
|
||||||
}),
|
}),
|
||||||
Filter::FieldName(s) => Node::Search(SearchNode::SingleField {
|
Filter::FieldName(s) => Node::Search(SearchNode::SingleField {
|
||||||
field: escape_anki_wildcards_for_search_node(&s),
|
field: escape_anki_wildcards_for_search_node(&s),
|
||||||
text: "*".to_string(),
|
text: "_*".to_string(),
|
||||||
is_re: false,
|
is_re: false,
|
||||||
}),
|
}),
|
||||||
Filter::Rated(rated) => Node::Search(SearchNode::Rated {
|
Filter::Rated(rated) => Node::Search(SearchNode::Rated {
|
||||||
|
|
Loading…
Reference in a new issue