hook browser_header_will_show_context_menu

This commit is contained in:
Arthur Milchior 2020-03-27 23:06:22 +01:00
parent beee1f10e0
commit 4bb49d404e
3 changed files with 29 additions and 0 deletions

View File

@ -970,6 +970,7 @@ QTableView {{ gridline-color: {grid} }}
a.setCheckable(True)
a.setChecked(type in self.model.activeCols)
a.toggled.connect(lambda b, t=type: self.toggleField(t))
gui_hooks.browser_header_will_show_context_menu(self, m)
m.exec_(gpos)
def toggleField(self, type):

View File

@ -385,6 +385,30 @@ class _BrowserDidSearchHook:
browser_did_search = _BrowserDidSearchHook()
class _BrowserHeaderWillShowContextMenuHook:
_hooks: List[Callable[["aqt.browser.Browser", QMenu], None]] = []
def append(self, cb: Callable[["aqt.browser.Browser", QMenu], None]) -> None:
"""(browser: aqt.browser.Browser, menu: QMenu)"""
self._hooks.append(cb)
def remove(self, cb: Callable[["aqt.browser.Browser", QMenu], None]) -> None:
if cb in self._hooks:
self._hooks.remove(cb)
def __call__(self, browser: aqt.browser.Browser, menu: QMenu) -> None:
for hook in self._hooks:
try:
hook(browser, menu)
except:
# if the hook fails, remove it
self._hooks.remove(hook)
raise
browser_header_will_show_context_menu = _BrowserHeaderWillShowContextMenuHook()
class _BrowserMenusDidInitHook:
_hooks: List[Callable[["aqt.browser.Browser"], None]] = []

View File

@ -185,6 +185,10 @@ hooks = [
args=["browser: aqt.browser.Browser", "menu: QMenu"],
legacy_hook="browser.onContextMenu",
),
Hook(
name="browser_header_will_show_context_menu",
args=["browser: aqt.browser.Browser", "menu: QMenu"],
),
Hook(
name="browser_did_change_row",
args=["browser: aqt.browser.Browser"],