From cce013fe753056c1850ff87aa05326d3e682e964 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 24 Mar 2020 10:27:52 +0530 Subject: [PATCH] Add a shortcut [Ctrl+Alt+p] to switch to the previously opened library. Fixes #1866742 [Feature request: Shortcut for quick switch library](https://bugs.launchpad.net/calibre/+bug/1866742) --- src/calibre/gui2/actions/choose_library.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/calibre/gui2/actions/choose_library.py b/src/calibre/gui2/actions/choose_library.py index 098c5d2b64..29c0e26e37 100644 --- a/src/calibre/gui2/actions/choose_library.py +++ b/src/calibre/gui2/actions/choose_library.py @@ -281,6 +281,14 @@ class ChooseLibraryAction(InterfaceAction): self.view_state_map = {} self.restore_view_state.connect(self._restore_view_state, type=Qt.QueuedConnection) + ac = self.create_action(spec=(_('Switch to previous library'), 'lt.png', + None, None), + attr='action_previous_library') + ac.triggered.connect(self.switch_to_previous_library, type=Qt.QueuedConnection) + self.gui.keyboard.register_shortcut( + self.unique_name + '-' + 'action_previous_library', + ac.text(), action=ac, group=self.action_spec[0], default_keys=('Ctrl+Alt+p',)) + self.gui.addAction(ac) @property def preserve_state_on_switch(self): @@ -345,6 +353,15 @@ class ChooseLibraryAction(InterfaceAction): def initialization_complete(self): self.library_changed(self.gui.library_view.model().db) + def switch_to_previous_library(self): + db = self.gui.library_view.model().db + locations = list(self.stats.locations(db)) + for name, loc in locations: + is_prev_lib = name == self.prev_lname + if is_prev_lib: + self.switch_requested(loc) + break + def build_menus(self): if os.environ.get('CALIBRE_OVERRIDE_DATABASE_PATH', None): return