From 31c7ef41675adf2c41db5fa900b8abb0cdb2aadc Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 22 Nov 2020 10:03:29 +0530 Subject: [PATCH] When using calibre://show-book URLs and the book is not found, clear any Virtual library or search restriction and then show the book. Fixes #1905113 [Clear current VL when using calibre:// to show book (or add switch VL modifier)](https://bugs.launchpad.net/calibre/+bug/1905113) --- src/calibre/gui2/search_restriction_mixin.py | 4 ++-- src/calibre/gui2/ui.py | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/search_restriction_mixin.py b/src/calibre/gui2/search_restriction_mixin.py index ce805558d5..c9936a07d3 100644 --- a/src/calibre/gui2/search_restriction_mixin.py +++ b/src/calibre/gui2/search_restriction_mixin.py @@ -404,7 +404,7 @@ class SearchRestrictionMixin(object): current_lib = db.data.get_base_restriction_name() - if current_lib == '': + if not current_lib: a = m.addAction(self.checked, self.no_restriction) else: a = m.addAction(self.empty, self.no_restriction) @@ -576,7 +576,7 @@ class SearchRestrictionMixin(object): self.search_restriction.setCurrentIndex(index) self.apply_search_restriction(index) - def apply_named_search_restriction(self, name): + def apply_named_search_restriction(self, name=None): if not self.search_restriction_list_built: self.build_search_restriction_list() if not name: diff --git a/src/calibre/gui2/ui.py b/src/calibre/gui2/ui.py index f6b7330343..66038e8ade 100644 --- a/src/calibre/gui2/ui.py +++ b/src/calibre/gui2/ui.py @@ -671,7 +671,12 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{ return def doit(): - self.library_view.select_rows((book_id,)) + rows = self.library_view.select_rows((book_id,)) + db = self.current_db + if not rows and (db.data.get_base_restriction_name() or db.data.get_search_restriction_name()): + self.apply_virtual_library() + self.apply_named_search_restriction() + self.library_view.select_rows((book_id,)) self.perform_url_action(library_id, library_path, doit) elif action == 'view-book':