mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Forgot to port a couple of functions for the top bar
This commit is contained in:
parent
af72200eca
commit
24e03df152
@ -86,24 +86,26 @@ def create_top_bar(container_id, **kw):
|
|||||||
create_markup(container_id)
|
create_markup(container_id)
|
||||||
set_left_data(container_id, **kw)
|
set_left_data(container_id, **kw)
|
||||||
|
|
||||||
def add_button(container_id, icon_name=None, action=None, tooltip=''):
|
def add_button(container_id, icon, action=None, tooltip=''):
|
||||||
if not icon_name:
|
if not icon:
|
||||||
return
|
raise ValueError('An icon must be specified')
|
||||||
bars = get_bars(container_id)
|
bars = get_bars(container_id)
|
||||||
for bar in bars:
|
for i, bar in enumerate(bars):
|
||||||
right = bar.firstChild.nextSibling
|
right = bar.firstChild.nextSibling
|
||||||
right.appendChild(E.a(
|
right.appendChild(E.a(
|
||||||
style="margin-left: " + SPACING,
|
style="margin-left: " + SPACING,
|
||||||
title=tooltip, svgicon(icon_name),
|
title=tooltip, svgicon(icon),
|
||||||
))
|
))
|
||||||
right.lastChild.setAttribute('id', ('top' if bar is self.bar else 'dummy') + '-bar-icon-' + icon_name)
|
right.lastChild.dataset.buttonIcon = icon
|
||||||
if bar is self.bar:
|
if i is 0:
|
||||||
if action is not None:
|
if action is not None:
|
||||||
right.lastChild.addEventListener('click', def(event): event.preventDefault(), action();)
|
right.lastChild.addEventListener('click', def(event):
|
||||||
|
event.preventDefault(), action()
|
||||||
|
)
|
||||||
|
|
||||||
def set_button_visibility(container_id, icon_name, visible):
|
def set_button_visibility(container_id, icon, visible):
|
||||||
for bar in get_bars(container_id):
|
for bar in get_bars(container_id):
|
||||||
right = bar.firstChild.nextSibling
|
right = bar.firstChild.nextSibling
|
||||||
elem = right.querySelector('#{}-bar-icon-{}'.format(('top' if bar is self.bar else 'dummy'), icon_name))
|
elem = right.querySelector(f'[data-button-icon="{icon}"]')
|
||||||
if elem:
|
if elem:
|
||||||
elem.style.display = 'inline-block' if visible else 'none'
|
elem.style.display = 'inline-block' if visible else 'none'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user