Allow adding a search in book button to the selection bar

Also have the keyboard shortcuts to run a search work when the selection
bar is visible.
This commit is contained in:
Kovid Goyal 2020-08-05 20:02:29 +05:30
parent ef35803ddb
commit d69efedb2f
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
6 changed files with 23 additions and 15 deletions

View File

@ -0,0 +1 @@
<svg width="1792" height="1792" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M704 320v768q0 26-19 45t-45 19v576q0 26-19 45t-45 19h-512q-26 0-45-19t-19-45v-512l249-873q7-23 31-23h424zm320 0v704h-256v-704h256zm768 896v512q0 26-19 45t-45 19h-512q-26 0-45-19t-19-45v-576q-26 0-45-19t-19-45v-768h424q24 0 31 23zm-1056-1184v224h-352v-224q0-14 9-23t23-9h288q14 0 23 9t9 23zm672 0v224h-352v-224q0-14 9-23t23-9h288q14 0 23 9t9 23z"/></svg>

After

Width:  |  Height:  |  Size: 453 B

View File

@ -290,8 +290,11 @@ class EbookViewer(MainWindow):
def toggle_toc(self):
self.toc_dock.setVisible(not self.toc_dock.isVisible())
def show_search(self):
self.web_view.get_current_cfi(self.show_search_with_current_selection)
def show_search(self, text):
self.search_dock.setVisible(True)
self.search_dock.activateWindow()
self.search_dock.raise_()
self.search_widget.focus_input(text)
def search_results_count_changed(self, num=-1):
if num < 0:
@ -304,12 +307,6 @@ class EbookViewer(MainWindow):
tt = _('Search :: {} matches').format(num)
self.search_dock.setWindowTitle(tt)
def show_search_with_current_selection(self, pos_data):
self.search_dock.setVisible(True)
self.search_dock.activateWindow()
self.search_dock.raise_()
self.search_widget.focus_input(pos_data.get('selected_text'))
def start_search(self, search_query):
name = self.web_view.current_content_file
if name:

View File

@ -241,7 +241,7 @@ class ViewerBridge(Bridge):
new_bookmark = from_js()
toggle_inspector = from_js()
toggle_lookup = from_js(object)
show_search = from_js()
show_search = from_js(object)
search_result_not_found = from_js(object)
find_next = from_js(object)
quit = from_js()
@ -431,7 +431,7 @@ class WebView(RestartingWebEngineView):
cfi_changed = pyqtSignal(object)
reload_book = pyqtSignal()
toggle_toc = pyqtSignal()
show_search = pyqtSignal()
show_search = pyqtSignal(object)
search_result_not_found = pyqtSignal(object)
find_next = pyqtSignal(object)
toggle_bookmarks = pyqtSignal()

View File

@ -168,7 +168,8 @@ def all_actions():
'lookup': a('library', _('Lookup/search selected word'), 'lookup'),
'quick_highlight': a('highlight', _('Quick highlight in current color'), 'quick_highlight'),
'highlight': a('highlight', _('Highlight selection'), 'create_highlight'),
'search_net': a('search', _('Search for selection on the net'), 'internet_search'),
'search': a('search', _('Search for selection in the book'), 'book_search'),
'search_net': a('binoculars', _('Search for selection on the net'), 'internet_search'),
'remove_highlight': a('trash', _('Remove this highlight'), 'remove_highlight', True),
'clear': a('close', _('Clear selection'), 'clear_selection'),
}
@ -475,6 +476,8 @@ class SelectionBar:
self.clear_selection()
elif sc_name in ('up', 'down', 'pageup', 'pagedown', 'left', 'right'):
self.send_message('trigger-shortcut', name=sc_name)
elif sc_name is 'start_search':
self.book_search()
# }}}
# drag scroll {{{
@ -699,6 +702,10 @@ class SelectionBar:
else:
self.view.overlay.show_word_actions(self.view.currently_showing.selection.text)
def book_search(self):
self.view.show_search()
self.clear_selection()
def internet_search(self):
text = self.view.currently_showing.selection.text
if text:

View File

@ -655,10 +655,13 @@ class View:
def show_search(self):
self.hide_overlays()
text = self.currently_showing.selection.text
if runtime.is_standalone_viewer:
ui_operations.show_search()
ui_operations.show_search(text or '')
else:
self.search_overlay.show()
if text:
self.search_overlay.set_text(text)
self.search_overlay.show(text)
def show_content_popup(self):
self.hide_overlays()

View File

@ -329,8 +329,8 @@ if window is window.top:
to_python.toggle_inspector()
ui_operations.content_file_changed = def(name):
to_python.content_file_changed(name)
ui_operations.show_search = def():
to_python.show_search()
ui_operations.show_search = def(text):
to_python.show_search(text)
ui_operations.find_next = def(previous):
to_python.find_next(previous)
ui_operations.reset_interface = def():