From eb7f51de50b4f5336c39cf7d3b341b7fb30edbe4 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 9 Apr 2021 14:18:25 +0530 Subject: [PATCH] Fix #1923094 [[Enhancement - Viewer] Open path folder](https://bugs.launchpad.net/calibre/+bug/1923094) --- src/calibre/gui2/viewer/web_view.py | 6 ++++++ src/pyj/read_book/overlay.pyj | 11 ++++++++++- src/pyj/viewer-main.pyj | 2 ++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/viewer/web_view.py b/src/calibre/gui2/viewer/web_view.py index 9b62f84326..bf09f9e3a1 100644 --- a/src/calibre/gui2/viewer/web_view.py +++ b/src/calibre/gui2/viewer/web_view.py @@ -274,6 +274,7 @@ class ViewerBridge(Bridge): speak_simple_text = from_js(object) tts = from_js(object, object) edit_book = from_js(object, object, object) + show_book_folder = from_js() create_view = to_js() start_book_load = to_js() @@ -535,6 +536,7 @@ class WebView(RestartingWebEngineView): self.bridge.close_prep_finished.connect(self.close_prep_finished) self.bridge.highlights_changed.connect(self.highlights_changed) self.bridge.edit_book.connect(self.edit_book) + self.bridge.show_book_folder.connect(self.show_book_folder) self.bridge.open_url.connect(safe_open_url) self.bridge.speak_simple_text.connect(self.tts.speak_simple_text) self.bridge.tts.connect(self.tts.action) @@ -736,3 +738,7 @@ class WebView(RestartingWebEngineView): def tts_settings_changed(self, ui_settings): self.execute_when_ready('tts_event', 'configured', ui_settings) + + def show_book_folder(self): + path = os.path.dirname(os.path.abspath(set_book_path.pathtoebook)) + safe_open_url(QUrl.fromLocalFile(path)) diff --git a/src/pyj/read_book/overlay.pyj b/src/pyj/read_book/overlay.pyj index e30559b494..d38488f426 100644 --- a/src/pyj/read_book/overlay.pyj +++ b/src/pyj/read_book/overlay.pyj @@ -787,7 +787,16 @@ class Overlay: if pathtoebook: container.lastChild.appendChild(E.div( style='margin-top: 1ex; padding-top: 1ex; border-top: solid 1px', - _('Path: {}').format(pathtoebook))) + _('Path:'), ' ', + E.a( + href='javascript: void(0)', + class_='blue-link', title=_('Click to open the folder the book is in'), + onclick=def(): + ui_operations.show_book_folder() + , + pathtoebook) + ) + ) book = self.view.book key = book.key or v'[null, 0]' diff --git a/src/pyj/viewer-main.pyj b/src/pyj/viewer-main.pyj index f3a9965ad3..d91e757ce6 100644 --- a/src/pyj/viewer-main.pyj +++ b/src/pyj/viewer-main.pyj @@ -421,6 +421,8 @@ if window is window.top: to_python.tts(action, data or v'{}') ui_operations.edit_book = def (spine_name, frac, selected_text): to_python.edit_book(spine_name, frac, selected_text or '') + ui_operations.show_book_folder = def(): + to_python.show_book_folder() document.body.appendChild(E.div(id='view')) window.onerror = onerror