From 0fbc3cece65eb5b1acc218dbc6a98d38d7c6f48a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 9 Dec 2019 17:16:17 +0530 Subject: [PATCH] Implement going to references in Go to... --- src/pyj/read_book/goto.pyj | 13 +++++++++++++ src/pyj/read_book/overlay.pyj | 2 +- src/pyj/read_book/ui.pyj | 4 ++++ src/pyj/viewer-main.pyj | 2 ++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/pyj/read_book/goto.pyj b/src/pyj/read_book/goto.pyj index 440d55d0ee..2bb6fdda63 100644 --- a/src/pyj/read_book/goto.pyj +++ b/src/pyj/read_book/goto.pyj @@ -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: diff --git a/src/pyj/read_book/overlay.pyj b/src/pyj/read_book/overlay.pyj index 1e179e23cd..4b1087ec7e 100644 --- a/src/pyj/read_book/overlay.pyj +++ b/src/pyj/read_book/overlay.pyj @@ -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): diff --git a/src/pyj/read_book/ui.pyj b/src/pyj/read_book/ui.pyj index 4996096301..ffb8981da3 100644 --- a/src/pyj/read_book/ui.pyj +++ b/src/pyj/read_book/ui.pyj @@ -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) diff --git a/src/pyj/viewer-main.pyj b/src/pyj/viewer-main.pyj index 86ab98f67c..ee50b60cda 100644 --- a/src/pyj/viewer-main.pyj +++ b/src/pyj/viewer-main.pyj @@ -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():