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)

This commit is contained in:
Kovid Goyal 2020-03-24 10:27:52 +05:30
parent 299e1e4808
commit cce013fe75
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -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