Fix #1908192 [Enhancement: "Add as new book" button when dragging onto details pane](https://bugs.launchpad.net/calibre/+bug/1908192)

This commit is contained in:
Kovid Goyal 2020-12-23 14:22:44 +05:30
parent 46aa4f2b2e
commit a4907b5012
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 23 additions and 6 deletions

View File

@ -450,11 +450,16 @@ class AddAction(InterfaceAction):
accept = True accept = True
if accept and event is not None: if accept and event is not None:
event.accept() event.accept()
add_as_book = False
if do_confirm and formats: if do_confirm and formats:
if not confirm( ok, add_as_book = confirm(
_('You have dropped some files onto the book <b>%s</b>. This will' _('You have dropped some files onto the book <b>%s</b>. This will'
' add or replace the files for this book. Do you want to proceed?') % db.title(cid, index_is_id=True), ' add or replace the files for this book. Do you want to proceed?') % db.title(cid, index_is_id=True),
'confirm_drop_on_book', parent=self.gui): 'confirm_drop_on_book', parent=self.gui,
extra_button=ngettext('Add as new book', 'Add as new books', len(formats)))
if ok and add_as_book:
add_as_book = [path for ext, path in formats]
if not ok or add_as_book:
formats = [] formats = []
for ext, path in formats: for ext, path in formats:
db.add_format_with_hooks(cid, ext, path, index_is_id=True) db.add_format_with_hooks(cid, ext, path, index_is_id=True)
@ -462,6 +467,8 @@ class AddAction(InterfaceAction):
self.gui.library_view.model().current_changed(current_idx, current_idx) self.gui.library_view.model().current_changed(current_idx, current_idx)
if cover_changed: if cover_changed:
self.gui.refresh_cover_browser() self.gui.refresh_cover_browser()
if add_as_book:
self.files_dropped(add_as_book)
def __add_filesystem_book(self, paths, allow_device=True): def __add_filesystem_book(self, paths, allow_device=True):
if isinstance(paths, string_or_bytes): if isinstance(paths, string_or_bytes):

View File

@ -17,7 +17,7 @@ from calibre.gui2.dialogs.message_box import Icon
class Dialog(QDialog): class Dialog(QDialog):
def __init__(self, msg, name, parent, config_set=dynamic, icon='dialog_warning.png', def __init__(self, msg, name, parent, config_set=dynamic, icon='dialog_warning.png',
title=None, confirm_msg=None, show_cancel_button=True): title=None, confirm_msg=None, show_cancel_button=True, extra_button=None):
QDialog.__init__(self, parent) QDialog.__init__(self, parent)
self.setWindowTitle(title or _("Are you sure?")) self.setWindowTitle(title or _("Are you sure?"))
self.setWindowIcon(QIcon(I(icon))) self.setWindowIcon(QIcon(I(icon)))
@ -50,6 +50,10 @@ class Dialog(QDialog):
bb.setObjectName("buttonBox") bb.setObjectName("buttonBox")
bb.setFocus(Qt.FocusReason.OtherFocusReason) bb.setFocus(Qt.FocusReason.OtherFocusReason)
bb.accepted.connect(self.accept), bb.rejected.connect(self.reject) bb.accepted.connect(self.accept), bb.rejected.connect(self.reject)
self.extra_button_clicked = False
if extra_button:
b = bb.addButton(extra_button, QDialogButtonBox.ButtonRole.AcceptRole)
b.clicked.connect(self.on_extra_button_click)
l.addWidget(bb) l.addWidget(bb)
self.name = name self.name = name
@ -58,15 +62,21 @@ class Dialog(QDialog):
self.resize(self.sizeHint()) self.resize(self.sizeHint())
bb.button(standard_button).setFocus(Qt.FocusReason.OtherFocusReason) bb.button(standard_button).setFocus(Qt.FocusReason.OtherFocusReason)
def on_extra_button_click(self):
self.extra_button_clicked = True
def toggle(self, *args): def toggle(self, *args):
self.config_set[confirm_config_name(self.name)] = self.again.isChecked() self.config_set[confirm_config_name(self.name)] = self.again.isChecked()
def confirm(msg, name, parent=None, pixmap='dialog_warning.png', title=None, def confirm(msg, name, parent=None, pixmap='dialog_warning.png', title=None,
show_cancel_button=True, confirm_msg=None, config_set=None): show_cancel_button=True, confirm_msg=None, config_set=None, extra_button=None):
config_set = config_set or dynamic config_set = config_set or dynamic
if not config_set.get(confirm_config_name(name), True): if not config_set.get(confirm_config_name(name), True):
return True return True
d = Dialog(msg, name, parent, config_set=config_set, icon=pixmap, d = Dialog(msg, name, parent, config_set=config_set, icon=pixmap, extra_button=extra_button,
title=title, confirm_msg=confirm_msg, show_cancel_button=show_cancel_button) title=title, confirm_msg=confirm_msg, show_cancel_button=show_cancel_button)
return d.exec_() == QDialog.DialogCode.Accepted ret = d.exec_() == QDialog.DialogCode.Accepted
if extra_button:
ret = ret, d.extra_button_clicked
return ret