mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Allow using Esc key to close modal dialogs
This commit is contained in:
parent
47ddd8165c
commit
5a66e094e3
@ -41,12 +41,13 @@ class Modal:
|
|||||||
class ModalContainer:
|
class ModalContainer:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
div = E.div(id='modal-container',
|
div = E.div(id='modal-container', tabindex='0',
|
||||||
E.div( # popup
|
E.div( # popup
|
||||||
E.div(), # content area
|
E.div(), # content area
|
||||||
E.a(svgicon('close'), title=_('Close'))
|
E.a(svgicon('close'), title=_('Close'))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
div.addEventListener('keydown', self.onkeydown.bind(self), {'passive': False})
|
||||||
document.body.appendChild(div)
|
document.body.appendChild(div)
|
||||||
|
|
||||||
# Container style
|
# Container style
|
||||||
@ -89,6 +90,7 @@ class ModalContainer:
|
|||||||
self.modals.push(Modal(create_func, on_close, show_close))
|
self.modals.push(Modal(create_func, on_close, show_close))
|
||||||
modal_id = self.modals[-1].id
|
modal_id = self.modals[-1].id
|
||||||
self.update()
|
self.update()
|
||||||
|
self.modal_container.focus()
|
||||||
return modal_id
|
return modal_id
|
||||||
|
|
||||||
def hide_modal(self, modal_id):
|
def hide_modal(self, modal_id):
|
||||||
@ -135,6 +137,10 @@ class ModalContainer:
|
|||||||
while self.current_modal is not None:
|
while self.current_modal is not None:
|
||||||
self.close_current_modal()
|
self.close_current_modal()
|
||||||
|
|
||||||
|
def onkeydown(self, event):
|
||||||
|
if (event.key is 'Escape' or event.key is 'Esc') and not event.altKey and not event.ctrlKey and not event.metaKey and not event.shiftKey:
|
||||||
|
self.close_current_modal(event)
|
||||||
|
|
||||||
|
|
||||||
def create_simple_dialog_markup(title, msg, details, icon, prefix, parent):
|
def create_simple_dialog_markup(title, msg, details, icon, prefix, parent):
|
||||||
details = details or ''
|
details = details or ''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user