Implement going to references in Go to...

This commit is contained in:
Kovid Goyal 2019-12-09 17:16:17 +05:30
parent e6044fae91
commit 0fbc3cece6
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 20 additions and 1 deletions

View File

@ -86,17 +86,30 @@ def create_location_overlay(current_position_data, overlay, container):
error_dialog(_('No such location'), _(
'No location {} found').format(cfi))
def goto_ref(ref):
if ui_operations.goto_reference(ref):
overlay.hide()
else:
error_dialog(_('No such reference'), _(
'No reference {} found').format(ref))
if current_position_data.book_length > 0:
container.appendChild(
E.div(style='margin: 1rem', _('Current position: {}').format(
format_pos(current_position_data.progress_frac, current_position_data.book_length))))
container.appendChild(
E.div(style='margin: 1rem', _(
'Type the position, location or reference below. For a reference type ref: followed by the reference:')))
def goto_pos():
src = document.querySelector(f'#{container_id} [name=newpos]').value
if not src:
return
if src.indexOf('epubcfi(') is 0:
return goto_cfi(src)
if src.indexOf('ref:') is 0:
return goto_ref(src[len('ref:'):])
try:
ui_operations.goto_book_position(float(src))
except:

View File

@ -646,7 +646,7 @@ class Overlay:
def show_ask_for_location(self):
self.hide_current_panel()
self.panels.push(SimpleOverlay(
self, create_location_overlay.bind(None, self.view.current_position_data), _('Go to location or position…')))
self, create_location_overlay.bind(None, self.view.current_position_data), _('Go to location, position or reference…')))
self.show_current_panel()
def show_search(self):

View File

@ -68,6 +68,7 @@ class ReadUI:
ui_operations.goto_cfi = self.goto_cfi.bind(self)
ui_operations.goto_frac = self.goto_frac.bind(self)
ui_operations.goto_book_position = self.goto_book_position.bind(self)
ui_operations.goto_book_position = self.goto_reference.bind(self)
ui_operations.delete_book = self.delete_book.bind(self)
ui_operations.focus_iframe = self.focus_iframe.bind(self)
ui_operations.toggle_toc = self.toggle_toc.bind(self)
@ -170,6 +171,9 @@ class ReadUI:
def goto_book_position(self, bpos):
return self.view.goto_book_position(bpos)
def goto_reference(self, ref):
return self.view.goto_reference(ref)
def delete_book(self, book, proceed):
self.db.delete_book(book, proceed)

View File

@ -327,6 +327,8 @@ if window is window.top:
return view.goto_frac(frac)
ui_operations.goto_book_position = def(bpos):
return view.goto_book_position(bpos)
ui_operations.goto_reference = def(ref):
return view.goto_reference(ref)
ui_operations.toggle_toc = def():
to_python.toggle_toc()
ui_operations.toggle_bookmarks = def():