mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Add a remove highlight action to the popup bar
Only visible if a highlight is selected
This commit is contained in:
parent
6746d0bc11
commit
393e47dcdb
@ -41,7 +41,7 @@ def create_selection_panel(container, apply_func, cancel_func):
|
|||||||
return E.div(style='margin-top:1ex', E.label(ans, '\xa0' + text))
|
return E.div(style='margin-top:1ex', E.label(ans, '\xa0' + text))
|
||||||
|
|
||||||
def url(name, text, title):
|
def url(name, text, title):
|
||||||
ans = E.input(type='url', name=name, value=sd.get(name), size='50', title=title or '')
|
ans = E.input(type='url', name=name, value=sd.get(name), size='50', title=title or '', style='margin-top: 1ex')
|
||||||
return E.div(style='margin-top:1ex', E.label(text, E.br(), ans))
|
return E.div(style='margin-top:1ex', E.label(text, E.br(), ans))
|
||||||
|
|
||||||
container.appendChild(cb(
|
container.appendChild(cb(
|
||||||
@ -50,6 +50,11 @@ def create_selection_panel(container, apply_func, cancel_func):
|
|||||||
'net_search_url', _('URL to query when searching the internet'),
|
'net_search_url', _('URL to query when searching the internet'),
|
||||||
_('The {q} in the URL is replaced by the selected text')))
|
_('The {q} in the URL is replaced by the selected text')))
|
||||||
|
|
||||||
|
container.appendChild(E.div(
|
||||||
|
style='margin-top: 2ex; border-top: solid 1px; padding-top: 1ex;',
|
||||||
|
_('Customize which actions are shown in the selection popup bar')
|
||||||
|
))
|
||||||
|
|
||||||
container.appendChild(create_button_box(restore_defaults, apply_func, cancel_func))
|
container.appendChild(create_button_box(restore_defaults, apply_func, cancel_func))
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,8 +12,8 @@ from read_book.globals import runtime, ui_operations
|
|||||||
|
|
||||||
|
|
||||||
def all_actions():
|
def all_actions():
|
||||||
def a(icon, text, func):
|
def a(icon, text, func, needs_highlight):
|
||||||
return {'icon': icon, 'text': text, 'function_name': func}
|
return {'icon': icon, 'text': text, 'function_name': func, 'needs_highlight': v'!!needs_highlight'}
|
||||||
|
|
||||||
if not all_actions.ans:
|
if not all_actions.ans:
|
||||||
all_actions.ans = {
|
all_actions.ans = {
|
||||||
@ -21,6 +21,7 @@ def all_actions():
|
|||||||
'lookup': a('library', _('Lookup/search selected word'), 'lookup'),
|
'lookup': a('library', _('Lookup/search selected word'), 'lookup'),
|
||||||
'highlight': a('highlight', _('Highlight selection'), 'create_highlight'),
|
'highlight': a('highlight', _('Highlight selection'), 'create_highlight'),
|
||||||
'search_net': a('search', _('Search for selection on the net'), 'internet_search'),
|
'search_net': a('search', _('Search for selection on the net'), 'internet_search'),
|
||||||
|
'remove_highlight': a('eraser', _('Remove this highlight'), 'remove_highlight', True),
|
||||||
'clear': a('close', _('Clear selection'), 'clear_selection'),
|
'clear': a('close', _('Clear selection'), 'clear_selection'),
|
||||||
}
|
}
|
||||||
return all_actions.ans
|
return all_actions.ans
|
||||||
@ -31,7 +32,8 @@ class SelectionBar:
|
|||||||
def __init__(self, view):
|
def __init__(self, view):
|
||||||
self.view = view
|
self.view = view
|
||||||
|
|
||||||
def build_bar(self, notes):
|
def build_bar(self, annot_id):
|
||||||
|
notes = self.view.annotations_manager.notes_for_highlight(annot_id)
|
||||||
c = self.container
|
c = self.container
|
||||||
max_width = 'min(50rem, 90vw)' if self.supports_css_min_max else '50rem'
|
max_width = 'min(50rem, 90vw)' if self.supports_css_min_max else '50rem'
|
||||||
bar_container = E.div(
|
bar_container = E.div(
|
||||||
@ -65,7 +67,7 @@ class SelectionBar:
|
|||||||
sd = get_session_data()
|
sd = get_session_data()
|
||||||
for acname in sd.get('selection_bar_actions'):
|
for acname in sd.get('selection_bar_actions'):
|
||||||
ac = actions[acname]
|
ac = actions[acname]
|
||||||
if ac:
|
if ac and (not ac.needs_highlight or v'!!annot_id'):
|
||||||
bar.appendChild(cb(ac.icon, ac.text, self[ac.function_name]))
|
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
|
||||||
@ -117,6 +119,11 @@ class SelectionBar:
|
|||||||
def create_highlight(self):
|
def create_highlight(self):
|
||||||
self.view.initiate_create_annotation(True)
|
self.view.initiate_create_annotation(True)
|
||||||
|
|
||||||
|
def remove_highlight(self):
|
||||||
|
annot_id = self.view.currently_showing.selection.annot_id
|
||||||
|
if annot_id:
|
||||||
|
self.view.create_annotation.remove_highlight(annot_id)
|
||||||
|
|
||||||
def show_notes(self, bar, notes):
|
def show_notes(self, bar, notes):
|
||||||
notes = (notes or "").strip()
|
notes = (notes or "").strip()
|
||||||
if not notes:
|
if not notes:
|
||||||
@ -167,7 +174,7 @@ class SelectionBar:
|
|||||||
def map_boundary(x):
|
def map_boundary(x):
|
||||||
return {'x': (x.x or 0) + margins.left, 'y': (x.y or 0) + margins.top, 'height': x.height or 0, 'onscreen': x.onscreen}
|
return {'x': (x.x or 0) + margins.left, 'y': (x.y or 0) + margins.top, 'height': x.height or 0, 'onscreen': x.onscreen}
|
||||||
|
|
||||||
bar = self.build_bar(self.view.annotations_manager.notes_for_highlight(cs.annot_id))
|
bar = self.build_bar(cs.annot_id)
|
||||||
start = map_boundary(cs.start)
|
start = map_boundary(cs.start)
|
||||||
end = map_boundary(cs.end)
|
end = map_boundary(cs.end)
|
||||||
self.show()
|
self.show()
|
||||||
|
@ -66,7 +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']",
|
'selection_bar_actions': v"['copy', 'lookup', 'highlight', 'remove_highlight', 'search_net', 'clear']",
|
||||||
}
|
}
|
||||||
|
|
||||||
is_local_setting = {
|
is_local_setting = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user