Show an error when no hints are found

This commit is contained in:
Kovid Goyal 2020-12-15 21:31:37 +05:30
parent 7f202f513d
commit be884acaf4
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -1,6 +1,11 @@
# vim:fileencoding=utf-8 # vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net> # License: GPL v3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
from __python__ import bound_methods, hash_literals from __python__ import bound_methods, hash_literals
from dom import clear
from elementmaker import E
from book_list.theme import get_color
from gettext import gettext as _
from read_book.shortcuts import shortcut_for_key_event from read_book.shortcuts import shortcut_for_key_event
@ -39,7 +44,9 @@ class Hints:
def show(self): def show(self):
if not self.is_visible: if not self.is_visible:
self.reset() self.reset()
self.container.style.display = 'block' c = self.container
c.style.display = 'block'
clear(c)
self.focus() self.focus()
self.send_message('show') self.send_message('show')
@ -84,6 +91,16 @@ class Hints:
if msg.type is 'shown': if msg.type is 'shown':
self.reset() self.reset()
self.hints_map = msg.hints_map self.hints_map = msg.hints_map
if not self.hints_map._length:
self.no_hints_found()
def no_hints_found(self):
c = self.container
c.appendChild(E.div(
_('No links found. Press Esc to close'),
style=f'position: absolute; margin: auto; top: 50%; left: 50%; background: {get_color("window-background")};' +
' padding: 1rem; border: solid 1px currentColor; border-radius: 4px; transform: translate(-50%, -50%);'
))
def is_visible(a): def is_visible(a):
@ -104,6 +121,7 @@ def hint_visible_links(link_attr):
a.dataset.calibreHintValue = h a.dataset.calibreHintValue = h
a.classList.add('calibre-hint-visible') a.classList.add('calibre-hint-visible')
hint_map[h] = {'type': 'link', 'data':JSON.parse(a.getAttribute(link_attr)), 'value': i} hint_map[h] = {'type': 'link', 'data':JSON.parse(a.getAttribute(link_attr)), 'value': i}
hint_map._length = i
return hint_map return hint_map