Add hook: overview_will_render_bottom (#1946)

This commit is contained in:
Mateus Etto 2022-07-05 07:28:47 +09:00 committed by GitHub
parent fe302a5d1b
commit fbbd3e678c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 2 deletions

View file

@ -75,7 +75,6 @@ Meredith Derecho <meredithderecho@gmail.com>
Daniel Wallgren <github.com/wallgrenen> Daniel Wallgren <github.com/wallgrenen>
Kerrick Staley <kerrick@kerrickstaley.com> Kerrick Staley <kerrick@kerrickstaley.com>
Maksim Abramchuk <maximabramchuck@gmail.com> Maksim Abramchuk <maximabramchuck@gmail.com>
Mateus Etto <mateus.etto@gmail.com>
Benjamin Kulnik <benjamin.kulnik@student.tuwien.ac.at> Benjamin Kulnik <benjamin.kulnik@student.tuwien.ac.at>
Shaun Ren <shaun.ren@linux.com> Shaun Ren <shaun.ren@linux.com>
Ryan Greenblatt <greenblattryan@gmail.com> Ryan Greenblatt <greenblattryan@gmail.com>
@ -105,6 +104,7 @@ wisherhxl <wisherhxl@gmail.com>
dobefore <1432338032@qq.com> dobefore <1432338032@qq.com>
Bart Louwers <bart.git@emeel.net> Bart Louwers <bart.git@emeel.net>
Sam Penny <github.com/sam1penny> Sam Penny <github.com/sam1penny>
Mateus Etto <mateus.etto@gmail.com>
******************** ********************

View file

@ -286,6 +286,12 @@ class Overview:
if self.mw.col.sched.have_buried(): if self.mw.col.sched.have_buried():
links.append(["U", "unbury", tr.studying_unbury()]) links.append(["U", "unbury", tr.studying_unbury()])
links.append(["", "description", tr.scheduling_description()]) links.append(["", "description", tr.scheduling_description()])
link_handler = gui_hooks.overview_will_render_bottom(
self._linkHandler,
links,
)
if not callable(link_handler):
link_handler = self._linkHandler
buf = "" buf = ""
for b in links: for b in links:
if b[0]: if b[0]:
@ -295,7 +301,9 @@ class Overview:
b b
) )
self.bottom.draw( self.bottom.draw(
buf=buf, link_handler=self._linkHandler, web_context=OverviewBottomBar(self) buf=buf,
link_handler=link_handler,
web_context=OverviewBottomBar(self),
) )
# Studying more # Studying more

View file

@ -65,6 +65,34 @@ hooks = [
content.table += "\n<div>my html</div>" content.table += "\n<div>my html</div>"
""", """,
), ),
Hook(
name="overview_will_render_bottom",
args=[
"link_handler: Callable[[str], bool]",
"links: list[list[str]]",
],
return_type="Callable[[str], bool]",
doc="""Allows adding buttons to the Overview bottom bar.
Append a list of strings to 'links' argument to add new buttons.
- The first value is the shortcut to appear in the tooltip.
- The second value is the url to be triggered.
- The third value is the text of the new button.
Extend the callable 'link_handler' to handle new urls. This callable
accepts one argument: the triggered url.
Make a check of the triggered url, call any functions related to
that trigger, and return the new link_handler.
Example:
links.append(['H', 'hello', 'Click me!'])
def custom_link_handler(url):
if url == 'hello':
print('Hello World!')
return link_handler(url=url)
return custom_link_handler
""",
),
Hook( Hook(
name="reviewer_did_show_question", name="reviewer_did_show_question",
args=["card: Card"], args=["card: Card"],