mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #1992273 [[Enhancement] Remove format from book by right-clicking on the format in the Tag browser](https://bugs.launchpad.net/calibre/+bug/1992273)
This commit is contained in:
parent
69eb9ee126
commit
f4d63adc07
@ -173,6 +173,12 @@ class DeleteAction(InterfaceAction):
|
|||||||
return set()
|
return set()
|
||||||
return set(map(self.gui.library_view.model().id, rows))
|
return set(map(self.gui.library_view.model().id, rows))
|
||||||
|
|
||||||
|
def _remove_formats_from_ids(self, fmts, ids):
|
||||||
|
self.gui.library_view.model().db.new_api.remove_formats({bid: fmts for bid in ids})
|
||||||
|
self.gui.library_view.model().refresh_ids(ids)
|
||||||
|
self.gui.library_view.model().current_changed(self.gui.library_view.currentIndex(),
|
||||||
|
self.gui.library_view.currentIndex())
|
||||||
|
|
||||||
def remove_format_by_id(self, book_id, fmt):
|
def remove_format_by_id(self, book_id, fmt):
|
||||||
title = self.gui.current_db.title(book_id, index_is_id=True)
|
title = self.gui.current_db.title(book_id, index_is_id=True)
|
||||||
if not confirm('<p>'+(_(
|
if not confirm('<p>'+(_(
|
||||||
@ -180,13 +186,28 @@ class DeleteAction(InterfaceAction):
|
|||||||
'%(title)s. Are you sure?')%dict(fmt=fmt, title=title)) +
|
'%(title)s. Are you sure?')%dict(fmt=fmt, title=title)) +
|
||||||
'</p>', 'library_delete_specific_format', self.gui):
|
'</p>', 'library_delete_specific_format', self.gui):
|
||||||
return
|
return
|
||||||
|
self._remove_format_from_ids((fmt,), (book_id,))
|
||||||
|
|
||||||
self.gui.library_view.model().db.remove_format(book_id, fmt,
|
def remove_format_from_selected_books(self, fmt):
|
||||||
index_is_id=True, notify=False)
|
ids = self._get_selected_ids()
|
||||||
self.gui.library_view.model().refresh_ids([book_id])
|
if not ids:
|
||||||
self.gui.library_view.model().current_changed(self.gui.library_view.currentIndex(),
|
return
|
||||||
self.gui.library_view.currentIndex())
|
db = self.gui.current_db.new_api
|
||||||
self.gui.tags_view.recount_with_position_based_index()
|
fmt = fmt.upper()
|
||||||
|
for bid in ids:
|
||||||
|
if fmt in db.formats(bid):
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
return error_dialog(self.gui, _('Format not found'), _('The {} format is not present in the selected books.').format(fmt), show=True)
|
||||||
|
if not confirm(
|
||||||
|
'<p>'+ ngettext(
|
||||||
|
_('The {fmt} format will be <b>permanently deleted</b> from {title}.'),
|
||||||
|
_('The {fmt} format will be <b>permanently deleted</b> from all {num} selected books.'),
|
||||||
|
len(ids)).format(fmt=fmt.upper(), num=len(ids), title=self.gui.current_db.title(next(iter(ids)), index_is_id=True)
|
||||||
|
) + ' ' + _('Are you sure?'), 'library_delete_specific_format_from_selected', self.gui
|
||||||
|
):
|
||||||
|
return
|
||||||
|
self._remove_formats_from_ids((fmt,), ids)
|
||||||
|
|
||||||
def restore_format(self, book_id, original_fmt):
|
def restore_format(self, book_id, original_fmt):
|
||||||
self.gui.current_db.restore_original_format(book_id, original_fmt)
|
self.gui.current_db.restore_original_format(book_id, original_fmt)
|
||||||
|
@ -507,6 +507,7 @@ class TagsView(QTreeView): # {{{
|
|||||||
is_first_letter=False, ignore_vl=False):
|
is_first_letter=False, ignore_vl=False):
|
||||||
if not action:
|
if not action:
|
||||||
return
|
return
|
||||||
|
from calibre.gui2.ui import get_gui
|
||||||
try:
|
try:
|
||||||
if action == 'set_icon':
|
if action == 'set_icon':
|
||||||
try:
|
try:
|
||||||
@ -585,7 +586,6 @@ class TagsView(QTreeView): # {{{
|
|||||||
self._toggle(index, set_to=search_state)
|
self._toggle(index, set_to=search_state)
|
||||||
return
|
return
|
||||||
if action == "raw_search":
|
if action == "raw_search":
|
||||||
from calibre.gui2.ui import get_gui
|
|
||||||
get_gui().get_saved_search_text(search_name='search:' + key)
|
get_gui().get_saved_search_text(search_name='search:' + key)
|
||||||
return
|
return
|
||||||
if action == 'add_to_category':
|
if action == 'add_to_category':
|
||||||
@ -638,6 +638,10 @@ class TagsView(QTreeView): # {{{
|
|||||||
if action == 'edit_author_link':
|
if action == 'edit_author_link':
|
||||||
self.author_sort_edit.emit(self, index, False, True, False)
|
self.author_sort_edit.emit(self, index, False, True, False)
|
||||||
return
|
return
|
||||||
|
if action == 'remove_format':
|
||||||
|
gui = get_gui()
|
||||||
|
gui.iactions['Remove Books'].remove_format_from_selected_books(key)
|
||||||
|
return
|
||||||
|
|
||||||
reset_filter_categories = True
|
reset_filter_categories = True
|
||||||
if action == 'hide':
|
if action == 'hide':
|
||||||
@ -973,6 +977,9 @@ class TagsView(QTreeView): # {{{
|
|||||||
self.context_menu.addAction(_('Manage Saved searches'),
|
self.context_menu.addAction(_('Manage Saved searches'),
|
||||||
partial(self.context_menu_handler, action='manage_searches',
|
partial(self.context_menu_handler, action='manage_searches',
|
||||||
category=tag.name if tag else None))
|
category=tag.name if tag else None))
|
||||||
|
elif key == 'formats':
|
||||||
|
self.context_menu.addAction(_('Remove the {} format from selected books').format(tag.name), partial(
|
||||||
|
self.context_menu_handler, action='remove_format', key=tag.name))
|
||||||
|
|
||||||
# Hide/Show/Restore categories
|
# Hide/Show/Restore categories
|
||||||
self.context_menu.addSeparator()
|
self.context_menu.addSeparator()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user