mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add some basic operations to the selection bar
This commit is contained in:
parent
626b2209d6
commit
1c38d64b1a
@ -146,6 +146,7 @@ class IframeBoss:
|
|||||||
'annotations': self.annotations_msg_received,
|
'annotations': self.annotations_msg_received,
|
||||||
'copy_selection': self.copy_selection,
|
'copy_selection': self.copy_selection,
|
||||||
'replace_highlights': self.replace_highlights,
|
'replace_highlights': self.replace_highlights,
|
||||||
|
'clear_selection': def(): window.getSelection().removeAllRanges();,
|
||||||
}
|
}
|
||||||
self.comm = IframeClient(handlers)
|
self.comm = IframeClient(handlers)
|
||||||
self.last_window_ypos = 0
|
self.last_window_ypos = 0
|
||||||
|
@ -94,7 +94,7 @@ class Prefs:
|
|||||||
ci(_('Keyboard shortcuts'), 'keyboard', _('Customize the keyboard shortcuts'))
|
ci(_('Keyboard shortcuts'), 'keyboard', _('Customize the keyboard shortcuts'))
|
||||||
if runtime.is_standalone_viewer:
|
if runtime.is_standalone_viewer:
|
||||||
ci(_('Fonts'), 'fonts', _('Font choices'))
|
ci(_('Fonts'), 'fonts', _('Font choices'))
|
||||||
ci(_('Miscellaneous'), 'misc', _('Window size, last read position, etc.'))
|
ci(_('Miscellaneous'), 'misc', _('Window size, last read position, toolbar, etc.'))
|
||||||
build_list(c, items)
|
build_list(c, items)
|
||||||
|
|
||||||
def display_fonts(self, container):
|
def display_fonts(self, container):
|
||||||
|
@ -3,8 +3,11 @@
|
|||||||
from __python__ import bound_methods, hash_literals
|
from __python__ import bound_methods, hash_literals
|
||||||
|
|
||||||
from elementmaker import E
|
from elementmaker import E
|
||||||
|
from gettext import gettext as _
|
||||||
|
|
||||||
from book_list.theme import get_color
|
from book_list.theme import get_color
|
||||||
|
from dom import svgicon
|
||||||
|
from read_book.globals import ui_operations
|
||||||
|
|
||||||
|
|
||||||
class SelectionBar:
|
class SelectionBar:
|
||||||
@ -13,11 +16,25 @@ class SelectionBar:
|
|||||||
self.view = view
|
self.view = view
|
||||||
c = self.container
|
c = self.container
|
||||||
bar = E.div(
|
bar = E.div(
|
||||||
style='position: absolute; left: 0; top: 0; height: 3ex; border: solid 1px currentColor; border-radius: 5px; overflow: hidden;'
|
style='position: absolute; height: 4ex; border: solid 1px currentColor; border-radius: 5px; overflow: hidden;'
|
||||||
'pointer-events: auto; min-width: 50px; padding: 5px; background-color: {}'.format(get_color("window-background"))
|
'display: flex; align-items: center; pointer-events: auto; padding: 5px; left: 0; top: 0;'
|
||||||
|
'background-color: {}'.format(get_color("window-background"))
|
||||||
)
|
)
|
||||||
c.appendChild(bar)
|
c.appendChild(bar)
|
||||||
|
|
||||||
|
def cb(icon, tooltip, callback):
|
||||||
|
ans = svgicon(icon, '3ex', '3ex', tooltip)
|
||||||
|
ans.addEventListener('click', callback)
|
||||||
|
ans.classList.add('simple-link')
|
||||||
|
ans.style.marginLeft = ans.style.marginRight = '0.5rem'
|
||||||
|
return ans
|
||||||
|
|
||||||
|
if ui_operations.copy_selection:
|
||||||
|
bar.appendChild(cb('copy', _('Copy to clipboard'), self.copy_to_clipboard))
|
||||||
|
if ui_operations.toggle_lookup:
|
||||||
|
bar.appendChild(cb('library', _('Lookup/search selected word'), self.lookup))
|
||||||
|
bar.appendChild(cb('close', _('Clear the selection'), self.clear_selection))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def container(self):
|
def container(self):
|
||||||
return document.getElementById('book-selection-bar-overlay')
|
return document.getElementById('book-selection-bar-overlay')
|
||||||
@ -36,6 +53,16 @@ class SelectionBar:
|
|||||||
def is_visible(self):
|
def is_visible(self):
|
||||||
return self.container.style.display is not 'none'
|
return self.container.style.display is not 'none'
|
||||||
|
|
||||||
|
def copy_to_clipboard(self):
|
||||||
|
if self.view.currently_showing.selected_text and ui_operations.copy_selection:
|
||||||
|
ui_operations.copy_selection(self.view.currently_showing.selected_text)
|
||||||
|
|
||||||
|
def lookup(self):
|
||||||
|
ui_operations.toggle_lookup(True)
|
||||||
|
|
||||||
|
def clear_selection(self):
|
||||||
|
self.view.on_handle_shortcut({'name': 'clear_selection'})
|
||||||
|
|
||||||
def update_position(self):
|
def update_position(self):
|
||||||
cs = self.view.currently_showing
|
cs = self.view.currently_showing
|
||||||
if not cs.has_selection:
|
if not cs.has_selection:
|
||||||
|
@ -490,6 +490,8 @@ class View:
|
|||||||
elif data.name is 'previous':
|
elif data.name is 'previous':
|
||||||
self.iframe_wrapper.send_message(
|
self.iframe_wrapper.send_message(
|
||||||
'next_screen', backwards=True, all_pages_on_screen=get_session_data().get('paged_margin_clicks_scroll_by_screen'))
|
'next_screen', backwards=True, all_pages_on_screen=get_session_data().get('paged_margin_clicks_scroll_by_screen'))
|
||||||
|
elif data.name is 'clear_selection':
|
||||||
|
self.iframe_wrapper.send_message('clear_selection')
|
||||||
elif data.name is 'print':
|
elif data.name is 'print':
|
||||||
ui_operations.print_book()
|
ui_operations.print_book()
|
||||||
elif data.name is 'preferences':
|
elif data.name is 'preferences':
|
||||||
|
@ -346,8 +346,8 @@ if window is window.top:
|
|||||||
to_python.reset_interface()
|
to_python.reset_interface()
|
||||||
ui_operations.quit = def():
|
ui_operations.quit = def():
|
||||||
to_python.quit()
|
to_python.quit()
|
||||||
ui_operations.toggle_lookup = def():
|
ui_operations.toggle_lookup = def(force_show):
|
||||||
to_python.toggle_lookup()
|
to_python.toggle_lookup(v'!!force_show')
|
||||||
ui_operations.selection_changed = def(selected_text):
|
ui_operations.selection_changed = def(selected_text):
|
||||||
to_python.selection_changed(selected_text)
|
to_python.selection_changed(selected_text)
|
||||||
ui_operations.update_current_toc_nodes = def(current_node_id, top_level_node_id):
|
ui_operations.update_current_toc_nodes = def(current_node_id, top_level_node_id):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user