From 17009638c130ebe6f359d11f65d98ad77ee327be Mon Sep 17 00:00:00 2001 From: RumovZ Date: Fri, 25 Jun 2021 16:24:24 +0200 Subject: [PATCH] Add hook "browser_sidebar_will_show_context_menu" --- qt/aqt/browser/sidebar/tree.py | 1 + qt/tools/genhooks_gui.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/qt/aqt/browser/sidebar/tree.py b/qt/aqt/browser/sidebar/tree.py index beae6cb95..97ab95a23 100644 --- a/qt/aqt/browser/sidebar/tree.py +++ b/qt/aqt/browser/sidebar/tree.py @@ -829,6 +829,7 @@ class SidebarTreeView(QTreeView): self._maybe_add_rename_action(menu, item, index) self._maybe_add_search_actions(menu) self._maybe_add_tree_actions(menu) + gui_hooks.browser_sidebar_will_show_context_menu(self, menu, item, index) if menu.children(): menu.exec_(QCursor.pos()) diff --git a/qt/tools/genhooks_gui.py b/qt/tools/genhooks_gui.py index 81c1e7900..2fa4ed3a7 100644 --- a/qt/tools/genhooks_gui.py +++ b/qt/tools/genhooks_gui.py @@ -29,7 +29,7 @@ from anki.decks import DeckDict, DeckConfigDict from anki.hooks import runFilter, runHook from anki.models import NotetypeDict from anki.collection import OpChangesAfterUndo -from aqt.qt import QDialog, QEvent, QMenu, QWidget +from aqt.qt import QDialog, QEvent, QMenu, QModelIndex, QWidget from aqt.tagedit import TagEdit from aqt.undo import UndoActionsInfo """ @@ -354,6 +354,15 @@ hooks = [ args=["browser: aqt.browser.Browser", "menu: QMenu"], legacy_hook="browser.onContextMenu", ), + Hook( + name="browser_sidebar_will_show_context_menu", + args=[ + "sidebar: aqt.browser.SidebarTreeView", + "menu: QMenu", + "item: aqt.browser.SidebarItem", + "index: QModelIndex", + ], + ), Hook( name="browser_header_will_show_context_menu", args=["browser: aqt.browser.Browser", "menu: QMenu"],