mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-05-09 02:53:38 +02:00
Add a button to selection bar to search net
This commit is contained in:
parent
de76fbbda2
commit
a6dd65bea4
6 changed files with 16 additions and 2 deletions
|
|
@ -268,6 +268,7 @@ class ViewerBridge(Bridge):
|
|||
scrollbar_context_menu = from_js(object, object, object)
|
||||
close_prep_finished = from_js(object)
|
||||
highlights_changed = from_js(object)
|
||||
open_url = from_js(object)
|
||||
|
||||
create_view = to_js()
|
||||
start_book_load = to_js()
|
||||
|
|
@ -511,6 +512,7 @@ def __init__(self, parent=None):
|
|||
self.bridge.scrollbar_context_menu.connect(self.scrollbar_context_menu)
|
||||
self.bridge.close_prep_finished.connect(self.close_prep_finished)
|
||||
self.bridge.highlights_changed.connect(self.highlights_changed)
|
||||
self.bridge.open_url.connect(safe_open_url)
|
||||
self.bridge.export_shortcut_map.connect(self.set_shortcut_map)
|
||||
self.shortcut_map = {}
|
||||
self.bridge.report_cfi.connect(self.call_callback)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
# TODO:
|
||||
# Custom colors for highlights
|
||||
# Google lookup for selections
|
||||
# Export all annots as plain text/JSON
|
||||
# Fix selection bar remaining open after removing highlight
|
||||
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ def cb(icon, tooltip, callback):
|
|||
bar.appendChild(cb('copy', _('Copy to clipboard'), self.copy_to_clipboard))
|
||||
bar.appendChild(cb('library', _('Lookup/search selected word'), self.lookup))
|
||||
bar.appendChild(cb('highlight', _('Highlight selection'), self.create_highlight))
|
||||
bar.appendChild(cb('search', _('Search for selection on the net'), self.internet_search))
|
||||
bar.appendChild(cb('close', _('Clear the selection'), self.clear_selection))
|
||||
self.show_notes(bar_container, notes)
|
||||
return bar_container
|
||||
|
|
@ -83,6 +84,13 @@ def lookup(self):
|
|||
else:
|
||||
self.view.overlay.show_word_actions(self.view.currently_showing.selection.text)
|
||||
|
||||
def internet_search(self):
|
||||
text = self.view.currently_showing.selection.text
|
||||
if text:
|
||||
q = encodeURIComponent(text)
|
||||
url = f'https://google.com/search?q={q}'
|
||||
ui_operations.open_url(url)
|
||||
|
||||
def clear_selection(self):
|
||||
self.view.on_handle_shortcut({'name': 'clear_selection'})
|
||||
|
||||
|
|
|
|||
|
|
@ -75,6 +75,8 @@ def __init__(self):
|
|||
ui_operations.toggle_full_screen = self.toggle_full_screen.bind(self)
|
||||
ui_operations.highlights_changed = self.highlights_changed.bind(self)
|
||||
ui_operations.annotations_synced = self.annotations_synced.bind(self)
|
||||
ui_operations.open_url = def(url):
|
||||
window.open(url, '_blank')
|
||||
|
||||
def on_resize(self):
|
||||
self.view.on_resize()
|
||||
|
|
|
|||
|
|
@ -9,12 +9,13 @@
|
|||
from book_list.item_list import create_item, create_item_list
|
||||
from dom import clear, ensure_id
|
||||
from modals import error_dialog
|
||||
from read_book.globals import ui_operations
|
||||
from widgets import create_button
|
||||
|
||||
|
||||
def lookup(close_panel_func, url):
|
||||
close_panel_func()
|
||||
window.open(url, '_blank')
|
||||
ui_operations.open_url(url)
|
||||
|
||||
|
||||
def toggle_custom_container(container_id, visible):
|
||||
|
|
|
|||
|
|
@ -345,6 +345,8 @@ def onerror(msg, script_url, line_number, column_number, error_object):
|
|||
sd.set('footer', defaults.footer)
|
||||
view.update_header_footer()
|
||||
to_python.reset_interface()
|
||||
ui_operations.open_url = def(url):
|
||||
to_python.open_url(url)
|
||||
ui_operations.quit = def():
|
||||
to_python.quit()
|
||||
ui_operations.toggle_lookup = def(force_show):
|
||||
|
|
|
|||
Loading…
Reference in a new issue