Edit metadata dialog: Fix keyboard shortcuts to edit prev/next raising an error when trying to go beyond the first/last book. Fixes #2086193 [moving through list while editing metadata](https://bugs.launchpad.net/calibre/+bug/2086193)

This commit is contained in:
Kovid Goyal 2024-11-01 09:27:45 +05:30
parent 7640525497
commit 3e96e1375f
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -11,6 +11,7 @@ from functools import partial
from qt.core import (
QAction,
QApplication,
QDialog,
QDialogButtonBox,
QFrame,
@ -124,14 +125,14 @@ class MetadataSingleDialogBase(QDialog):
self.next_button = QPushButton(QIcon.ic('forward.png'), _('Next'),
self)
self.next_action = ac = QAction(self)
ac.triggered.connect(self.next_clicked)
ac.triggered.connect(self.next_if_possible)
self.addAction(ac)
ac.setShortcut(QKeySequence('Alt+Right'))
self.next_button.clicked.connect(self.next_clicked)
self.prev_button = QPushButton(QIcon.ic('back.png'), _('Previous'), self)
self.prev_button.clicked.connect(self.prev_clicked)
self.prev_action = ac = QAction(self)
ac.triggered.connect(self.prev_clicked)
ac.triggered.connect(self.prev_if_possible)
ac.setShortcut(QKeySequence('Alt+Left'))
self.addAction(ac)
from calibre.gui2.actions.edit_metadata import DATA_FILES_ICON_NAME
@ -736,6 +737,18 @@ class MetadataSingleDialogBase(QDialog):
self.break_cycles()
return ret
def next_if_possible(self):
if self.next_button.isEnabled():
self.next_clicked()
else:
QApplication.beep()
def prev_if_possible(self):
if self.prev_button.isEnabled():
self.prev_clicked()
else:
QApplication.beep()
def next_clicked(self):
fw = self.focusWidget()
if not self.apply_changes():