mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Allow creating a shortcut in preferences->Shortcuts->Edit metadata to paste metadata ignoring the value of the exclude_fields tweak. Fixes #1953739 [[Enhancement] Paste metadata - Override 'exclude_fields_on_paste' setting](https://bugs.launchpad.net/calibre/+bug/1953739)
This commit is contained in:
parent
988b7d97f2
commit
9ed24d754b
@ -582,6 +582,8 @@ show_saved_search_box = False
|
||||
# Edit metadata->Copy metadata/Paste metadata actions. For example,
|
||||
# exclude_fields_on_paste = ['cover', 'timestamp', '#mycolumn']
|
||||
# to prevent pasting of the cover, Date and custom column, mycolumn.
|
||||
# You can also add a shortcut in Preferences->Shortcut->Edit metadata
|
||||
# to paste metadata ignoring this tweak.
|
||||
exclude_fields_on_paste = []
|
||||
|
||||
#: Skip internet connected check
|
||||
|
@ -12,7 +12,8 @@ import shutil
|
||||
from functools import partial
|
||||
from io import BytesIO
|
||||
from qt.core import (
|
||||
QAction, QApplication, QDialog, QIcon, QMenu, QMimeData, QModelIndex, QTimer, QUrl
|
||||
QAction, QApplication, QDialog, QIcon, QMenu, QMimeData, QModelIndex, QTimer,
|
||||
QUrl
|
||||
)
|
||||
|
||||
from calibre.db.errors import NoSuchFormat
|
||||
@ -96,7 +97,11 @@ class EditMetadataAction(InterfaceAction):
|
||||
self.merge_menu = mb
|
||||
md.addSeparator()
|
||||
self.action_copy = cm('copy', _('Copy metadata'), icon='edit-copy.png', triggered=self.copy_metadata)
|
||||
self.action_paset = cm('paste', _('Paste metadata'), icon='edit-paste.png', triggered=self.paste_metadata)
|
||||
self.action_paste = cm('paste', _('Paste metadata'), icon='edit-paste.png', triggered=self.paste_metadata)
|
||||
self.action_paste_ignore_excluded = ac = cm(
|
||||
'paste_include_excluded_fields', _('Paste metadata including excluded fields'), icon='edit-paste.png',
|
||||
triggered=self.paste_metadata_including_excluded_fields)
|
||||
ac.setVisible(False)
|
||||
self.action_merge = cm('merge', _('Merge book records'), icon='merge_books.png',
|
||||
shortcut=_('M'), triggered=self.merge_books)
|
||||
self.action_merge.setMenu(mb)
|
||||
@ -182,6 +187,12 @@ class EditMetadataAction(InterfaceAction):
|
||||
c.setMimeData(md)
|
||||
|
||||
def paste_metadata(self):
|
||||
self.do_paste()
|
||||
|
||||
def paste_metadata_including_excluded_fields(self):
|
||||
self.do_paste(ignore_excluded_fields=True)
|
||||
|
||||
def do_paste(self, ignore_excluded_fields=False):
|
||||
rows = self.gui.library_view.selectionModel().selectedRows()
|
||||
if not rows or len(rows) == 0:
|
||||
return error_dialog(self.gui, _('Cannot paste metadata'),
|
||||
@ -199,7 +210,10 @@ class EditMetadataAction(InterfaceAction):
|
||||
data = bytes(md.data('application/calibre-book-metadata'))
|
||||
mi = OPF(BytesIO(data), populate_spine=False, read_toc=False, try_to_guess_cover=False).to_book_metadata()
|
||||
mi.application_id = mi.uuid_id = None
|
||||
exclude = set(tweaks['exclude_fields_on_paste'])
|
||||
if ignore_excluded_fields:
|
||||
exclude = set()
|
||||
else:
|
||||
exclude = set(tweaks['exclude_fields_on_paste'])
|
||||
paste_cover = 'cover' not in exclude
|
||||
cover = md.imageData() if paste_cover else None
|
||||
exclude.discard('cover')
|
||||
|
Loading…
x
Reference in New Issue
Block a user