mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 01:06:35 -04:00
add context menu to SidebarTreeView
This commit is contained in:
parent
e7e19f8ac8
commit
9c2eb8bf00
1 changed files with 18 additions and 0 deletions
|
@ -589,6 +589,10 @@ class SidebarTreeView(QTreeView):
|
|||
self.expanded.connect(self.onExpansion)
|
||||
self.collapsed.connect(self.onCollapse)
|
||||
|
||||
self.setContextMenuPolicy(Qt.CustomContextMenu)
|
||||
self.customContextMenuRequested.connect(self.onContextMenu)
|
||||
self.context_menus = {SidebarItemType.DECK: ()}
|
||||
|
||||
def onClickCurrent(self) -> None:
|
||||
idx = self.currentIndex()
|
||||
if idx.isValid():
|
||||
|
@ -619,6 +623,19 @@ class SidebarTreeView(QTreeView):
|
|||
if item.onExpanded:
|
||||
item.onExpanded(expanded)
|
||||
|
||||
def onContextMenu(self, point: QPoint) -> None:
|
||||
idx: QModelIndex = self.indexAt(point)
|
||||
item: SidebarItem = idx.internalPointer()
|
||||
item_type: SidebarItemType = item.item_type
|
||||
if item_type not in self.context_menus:
|
||||
return
|
||||
|
||||
m = QMenu()
|
||||
for action in self.context_menus[item_type]:
|
||||
a = m.addAction(action[0])
|
||||
a.triggered.connect(action[1])
|
||||
m.exec_(QCursor.pos())
|
||||
|
||||
|
||||
# Browser window
|
||||
######################################################################
|
||||
|
@ -1204,6 +1221,7 @@ QTableView {{ gridline-color: {grid} }}
|
|||
m["name"],
|
||||
":/icons/notetype.svg",
|
||||
lambda m=m: self.setFilter("note", m["name"]), # type: ignore
|
||||
item_type=SidebarItemType.NOTETYPE,
|
||||
)
|
||||
root.addChild(item)
|
||||
|
||||
|
|
Loading…
Reference in a new issue