mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Confirm when dropping files onto Book Details
When dropping files onto the Book Details panel, ask for confirmation before adding the files to the book. The confirmation can be disabled.
This commit is contained in:
parent
8f9528e517
commit
2f37913801
@ -14,6 +14,7 @@ from calibre import as_unicode
|
||||
from calibre.gui2 import (error_dialog, choose_files, choose_dir,
|
||||
warning_dialog, info_dialog)
|
||||
from calibre.gui2.dialogs.add_empty_book import AddEmptyBookDialog
|
||||
from calibre.gui2.dialogs.confirm_delete import confirm
|
||||
from calibre.gui2.dialogs.progress import ProgressDialog
|
||||
from calibre.gui2.widgets import IMAGE_EXTENSIONS
|
||||
from calibre.ebooks import BOOK_EXTENSIONS
|
||||
@ -119,7 +120,6 @@ class AddAction(InterfaceAction):
|
||||
if current_idx.isValid():
|
||||
view.model().current_changed(current_idx, current_idx)
|
||||
|
||||
|
||||
def add_recursive(self, single):
|
||||
root = choose_dir(self.gui, 'recursive book import root dir dialog',
|
||||
'Select root folder')
|
||||
@ -205,7 +205,6 @@ class AddAction(InterfaceAction):
|
||||
'authors']))
|
||||
return
|
||||
|
||||
|
||||
mi = MetaInformation(None)
|
||||
mi.isbn = x['isbn']
|
||||
if self.isbn_add_tags:
|
||||
@ -227,7 +226,8 @@ class AddAction(InterfaceAction):
|
||||
return
|
||||
db = self.gui.library_view.model().db
|
||||
current_idx = self.gui.library_view.currentIndex()
|
||||
if not current_idx.isValid(): return
|
||||
if not current_idx.isValid():
|
||||
return
|
||||
cid = db.id(current_idx.row())
|
||||
from calibre.gui2.dnd import DownloadDialog
|
||||
d = DownloadDialog(url, fname, self.gui)
|
||||
@ -235,7 +235,7 @@ class AddAction(InterfaceAction):
|
||||
if d.err is None:
|
||||
self.files_dropped_on_book(None, [d.fpath], cid=cid)
|
||||
|
||||
def files_dropped_on_book(self, event, paths, cid=None):
|
||||
def files_dropped_on_book(self, event, paths, cid=None, do_confirm=True):
|
||||
accept = False
|
||||
if self.gui.current_view() is not self.gui.library_view:
|
||||
return
|
||||
@ -243,8 +243,10 @@ class AddAction(InterfaceAction):
|
||||
cover_changed = False
|
||||
current_idx = self.gui.library_view.currentIndex()
|
||||
if cid is None:
|
||||
if not current_idx.isValid(): return
|
||||
if not current_idx.isValid():
|
||||
return
|
||||
cid = db.id(current_idx.row()) if cid is None else cid
|
||||
formats = []
|
||||
for path in paths:
|
||||
ext = os.path.splitext(path)[1].lower()
|
||||
if ext:
|
||||
@ -257,10 +259,18 @@ class AddAction(InterfaceAction):
|
||||
db.set_cover(cid, pmap)
|
||||
cover_changed = True
|
||||
elif ext in BOOK_EXTENSIONS:
|
||||
db.add_format_with_hooks(cid, ext, path, index_is_id=True)
|
||||
formats.append((ext, path))
|
||||
accept = True
|
||||
if accept and event is not None:
|
||||
event.accept()
|
||||
if do_confirm and formats:
|
||||
if not confirm(
|
||||
_('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),
|
||||
'confirm_drop_on_book', parent=self.gui):
|
||||
formats = []
|
||||
for ext, path in formats:
|
||||
db.add_format_with_hooks(cid, ext, path, index_is_id=True)
|
||||
if current_idx.isValid():
|
||||
self.gui.library_view.model().current_changed(current_idx, current_idx)
|
||||
if cover_changed:
|
||||
@ -277,10 +287,9 @@ class AddAction(InterfaceAction):
|
||||
to_device = allow_device and self.gui.stack.currentIndex() != 0
|
||||
self._add_books(books, to_device)
|
||||
if to_device:
|
||||
self.gui.status_bar.show_message(\
|
||||
self.gui.status_bar.show_message(
|
||||
_('Uploading books to device.'), 2000)
|
||||
|
||||
|
||||
def add_filesystem_book(self, paths, allow_device=True):
|
||||
self._add_filesystem_book(paths, allow_device=allow_device)
|
||||
|
||||
@ -453,3 +462,4 @@ class AddAction(InterfaceAction):
|
||||
self._adder.add(ok_paths)
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user