mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Hook editor_web_view_did_init
I hope to use this in oder to had features to the web view. In particular, I expect the "spell checking" feature to use it hopefully. Because currently it's incompatible with other add-on dealing with the editor
This commit is contained in:
parent
e7452300a2
commit
89bb5fe79b
3 changed files with 29 additions and 0 deletions
|
@ -954,6 +954,7 @@ class EditorWebView(AnkiWebView):
|
||||||
self._markInternal = False
|
self._markInternal = False
|
||||||
clip = self.editor.mw.app.clipboard()
|
clip = self.editor.mw.app.clipboard()
|
||||||
clip.dataChanged.connect(self._onClipboardChange)
|
clip.dataChanged.connect(self._onClipboardChange)
|
||||||
|
gui_hooks.editor_web_view_did_init(self)
|
||||||
|
|
||||||
def _onClipboardChange(self):
|
def _onClipboardChange(self):
|
||||||
if self._markInternal:
|
if self._markInternal:
|
||||||
|
|
|
@ -1036,6 +1036,30 @@ class _EditorDidUpdateTagsHook:
|
||||||
editor_did_update_tags = _EditorDidUpdateTagsHook()
|
editor_did_update_tags = _EditorDidUpdateTagsHook()
|
||||||
|
|
||||||
|
|
||||||
|
class _EditorWebViewDidInitHook:
|
||||||
|
_hooks: List[Callable[["aqt.editor.EditorWebView"], None]] = []
|
||||||
|
|
||||||
|
def append(self, cb: Callable[["aqt.editor.EditorWebView"], None]) -> None:
|
||||||
|
"""(editor_web_view: aqt.editor.EditorWebView)"""
|
||||||
|
self._hooks.append(cb)
|
||||||
|
|
||||||
|
def remove(self, cb: Callable[["aqt.editor.EditorWebView"], None]) -> None:
|
||||||
|
if cb in self._hooks:
|
||||||
|
self._hooks.remove(cb)
|
||||||
|
|
||||||
|
def __call__(self, editor_web_view: aqt.editor.EditorWebView) -> None:
|
||||||
|
for hook in self._hooks:
|
||||||
|
try:
|
||||||
|
hook(editor_web_view)
|
||||||
|
except:
|
||||||
|
# if the hook fails, remove it
|
||||||
|
self._hooks.remove(hook)
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
editor_web_view_did_init = _EditorWebViewDidInitHook()
|
||||||
|
|
||||||
|
|
||||||
class _EditorWillShowContextMenuHook:
|
class _EditorWillShowContextMenuHook:
|
||||||
_hooks: List[Callable[["aqt.editor.EditorWebView", QMenu], None]] = []
|
_hooks: List[Callable[["aqt.editor.EditorWebView", QMenu], None]] = []
|
||||||
|
|
||||||
|
|
|
@ -460,6 +460,10 @@ def emptyNewCard():
|
||||||
return_type="str",
|
return_type="str",
|
||||||
legacy_hook="mungeEditingFontName",
|
legacy_hook="mungeEditingFontName",
|
||||||
),
|
),
|
||||||
|
Hook(
|
||||||
|
name="editor_web_view_did_init",
|
||||||
|
args=["editor_web_view: aqt.editor.EditorWebView"],
|
||||||
|
),
|
||||||
# Sound/video
|
# Sound/video
|
||||||
###################
|
###################
|
||||||
Hook(name="av_player_will_play", args=["tag: anki.sound.AVTag"]),
|
Hook(name="av_player_will_play", args=["tag: anki.sound.AVTag"]),
|
||||||
|
|
Loading…
Reference in a new issue