Add editor_did_init_left_buttons gui_hook

This commit is contained in:
Henrik Giesel 2020-10-04 22:50:02 +02:00
parent bf29fb8e83
commit 4c255b0289
3 changed files with 33 additions and 0 deletions

View File

@ -137,6 +137,8 @@ class Editor:
),
]
gui_hooks.editor_did_init_left_buttons(lefttopbtns, self)
righttopbtns: List[str] = [
self._addButton("text_bold", "bold", _("Bold text (Ctrl+B)"), id="bold"),
self._addButton(

View File

@ -1401,6 +1401,33 @@ class _EditorDidInitButtonsHook:
editor_did_init_buttons = _EditorDidInitButtonsHook()
class _EditorDidInitLeftButtonsHook:
_hooks: List[Callable[[List[str], "aqt.editor.Editor"], None]] = []
def append(self, cb: Callable[[List[str], "aqt.editor.Editor"], None]) -> None:
"""(buttons: List[str], editor: aqt.editor.Editor)"""
self._hooks.append(cb)
def remove(self, cb: Callable[[List[str], "aqt.editor.Editor"], None]) -> None:
if cb in self._hooks:
self._hooks.remove(cb)
def count(self) -> int:
return len(self._hooks)
def __call__(self, buttons: List[str], editor: aqt.editor.Editor) -> None:
for hook in self._hooks:
try:
hook(buttons, editor)
except:
# if the hook fails, remove it
self._hooks.remove(hook)
raise
editor_did_init_left_buttons = _EditorDidInitLeftButtonsHook()
class _EditorDidInitShortcutsHook:
_hooks: List[Callable[[List[Tuple], "aqt.editor.Editor"], None]] = []

View File

@ -606,6 +606,10 @@ gui_hooks.webview_did_inject_style_into_page.append(mytest)
),
# Editing
###################
Hook(
name="editor_did_init_left_buttons",
args=["buttons: List[str]", "editor: aqt.editor.Editor"],
),
Hook(
name="editor_did_init_buttons",
args=["buttons: List[str]", "editor: aqt.editor.Editor"],