mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Add editor_did_init_left_buttons gui_hook
This commit is contained in:
parent
bf29fb8e83
commit
4c255b0289
3 changed files with 33 additions and 0 deletions
|
@ -137,6 +137,8 @@ class Editor:
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
gui_hooks.editor_did_init_left_buttons(lefttopbtns, self)
|
||||||
|
|
||||||
righttopbtns: List[str] = [
|
righttopbtns: List[str] = [
|
||||||
self._addButton("text_bold", "bold", _("Bold text (Ctrl+B)"), id="bold"),
|
self._addButton("text_bold", "bold", _("Bold text (Ctrl+B)"), id="bold"),
|
||||||
self._addButton(
|
self._addButton(
|
||||||
|
|
|
@ -1401,6 +1401,33 @@ class _EditorDidInitButtonsHook:
|
||||||
editor_did_init_buttons = _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:
|
class _EditorDidInitShortcutsHook:
|
||||||
_hooks: List[Callable[[List[Tuple], "aqt.editor.Editor"], None]] = []
|
_hooks: List[Callable[[List[Tuple], "aqt.editor.Editor"], None]] = []
|
||||||
|
|
||||||
|
|
|
@ -606,6 +606,10 @@ gui_hooks.webview_did_inject_style_into_page.append(mytest)
|
||||||
),
|
),
|
||||||
# Editing
|
# Editing
|
||||||
###################
|
###################
|
||||||
|
Hook(
|
||||||
|
name="editor_did_init_left_buttons",
|
||||||
|
args=["buttons: List[str]", "editor: aqt.editor.Editor"],
|
||||||
|
),
|
||||||
Hook(
|
Hook(
|
||||||
name="editor_did_init_buttons",
|
name="editor_did_init_buttons",
|
||||||
args=["buttons: List[str]", "editor: aqt.editor.Editor"],
|
args=["buttons: List[str]", "editor: aqt.editor.Editor"],
|
||||||
|
|
Loading…
Reference in a new issue