Fix #1961465 [[Enhancement - Content server] ESC to close the Search for books page](https://bugs.launchpad.net/calibre/+bug/1961465)

This commit is contained in:
Kovid Goyal 2022-03-02 19:08:16 +05:30
parent 4ebed6bbc1
commit 66f427eef4
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 18 additions and 0 deletions

View File

@ -227,6 +227,12 @@ def reset_to_defaults():
def prefs_panel_handler(title_func, get_prefs_data, on_close=None, icon='close'):
def onkeydown(container_id, close_action, ev):
if ev.key is 'Escape':
ev.preventDefault(), ev.stopPropagation()
close_action()
def close_action():
if on_close is not None:
on_close()
@ -234,8 +240,11 @@ def prefs_panel_handler(title_func, get_prefs_data, on_close=None, icon='close')
def init_prefs_panel(container_id):
container = document.getElementById(container_id)
container.addEventListener('keydown', onkeydown.bind(None, container_id, close_action), {'passive': False, 'capture': True})
container.setAttribute('tabindex', '0')
create_top_bar(container, title=title_func(), action=close_action, icon=icon)
container.appendChild(E.div())
create_prefs_widget(container.lastChild, get_prefs_data())
container.focus()
return init_prefs_panel

View File

@ -513,12 +513,21 @@ def tb_config_panel_handler():
# }}}
def onkeydown(container_id, close_action, ev):
if ev.key is 'Escape':
ev.preventDefault(), ev.stopPropagation()
close_action()
def init(container_id):
if not library_data.sortable_fields:
show_panel('book_list', replace=True)
return
container = document.getElementById(container_id)
container.setAttribute('tabindex', '0')
container.addEventListener('keydown', onkeydown.bind(None, container_id, back), {'passive': False, 'capture': True})
create_top_bar(container, title=_('Search for books'), action=back, icon='close')
add_button(container, icon='cogs', action=show_panel.bind(None, 'book_list^search^prefs'), tooltip=_('Configure Tag browser'))
container.appendChild(E.div(class_=CLASS_NAME))
create_search_panel(container.lastChild)
container.focus()