Make selection bar configurable

This commit is contained in:
Kovid Goyal 2020-07-28 13:41:55 +05:30
parent 4fb62e9565
commit 6746d0bc11
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 22 additions and 5 deletions

View File

@ -11,6 +11,21 @@ from dom import clear, svgicon
from read_book.globals import runtime, ui_operations from read_book.globals import runtime, ui_operations
def all_actions():
def a(icon, text, func):
return {'icon': icon, 'text': text, 'function_name': func}
if not all_actions.ans:
all_actions.ans = {
'copy': a('copy', _('Copy to clipboard'), 'copy_to_clipboard'),
'lookup': a('library', _('Lookup/search selected word'), 'lookup'),
'highlight': a('highlight', _('Highlight selection'), 'create_highlight'),
'search_net': a('search', _('Search for selection on the net'), 'internet_search'),
'clear': a('close', _('Clear selection'), 'clear_selection'),
}
return all_actions.ans
class SelectionBar: class SelectionBar:
def __init__(self, view): def __init__(self, view):
@ -46,11 +61,12 @@ class SelectionBar:
ans.style.marginLeft = ans.style.marginRight = '0.5rem' ans.style.marginLeft = ans.style.marginRight = '0.5rem'
return ans return ans
bar.appendChild(cb('copy', _('Copy to clipboard'), self.copy_to_clipboard)) actions = all_actions()
bar.appendChild(cb('library', _('Lookup/search selected word'), self.lookup)) sd = get_session_data()
bar.appendChild(cb('highlight', _('Highlight selection'), self.create_highlight)) for acname in sd.get('selection_bar_actions'):
bar.appendChild(cb('search', _('Search for selection on the net'), self.internet_search)) ac = actions[acname]
bar.appendChild(cb('close', _('Clear the selection'), self.clear_selection)) if ac:
bar.appendChild(cb(ac.icon, ac.text, self[ac.function_name]))
self.show_notes(bar_container, notes) self.show_notes(bar_container, notes)
return bar_container return bar_container

View File

@ -66,6 +66,7 @@ defaults = {
'custom_highlight_colors': v'[]', 'custom_highlight_colors': v'[]',
'show_selection_bar': True, 'show_selection_bar': True,
'net_search_url': 'https://google.com/search?q={q}', 'net_search_url': 'https://google.com/search?q={q}',
'selection_bar_actions': v"['copy', 'lookup', 'highlight', 'search_net', 'clear']",
} }
is_local_setting = { is_local_setting = {