mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Merge branch 'master' of https://github.com/cbhaley/calibre
Fixes #1923365 [Enhancement Request: Tag browser: Delete identifiers in context menu](https://bugs.launchpad.net/calibre/+bug/1923365)
This commit is contained in:
commit
263427884e
@ -6,7 +6,7 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import textwrap
|
||||
import copy, textwrap
|
||||
from functools import partial
|
||||
|
||||
from qt.core import (
|
||||
@ -87,6 +87,7 @@ class TagBrowserMixin(object): # {{{
|
||||
self.tags_view.restriction_error.connect(self.do_restriction_error,
|
||||
type=Qt.ConnectionType.QueuedConnection)
|
||||
self.tags_view.tag_item_delete.connect(self.do_tag_item_delete)
|
||||
self.tags_view.tag_identifier_delete.connect(self.delete_identifier)
|
||||
self.tags_view.apply_tag_to_selected.connect(self.apply_tag_to_selected)
|
||||
self.populate_tb_manage_menu(db)
|
||||
self.tags_view.model().user_categories_edited.connect(self.user_categories_edited,
|
||||
@ -380,6 +381,33 @@ class TagBrowserMixin(object): # {{{
|
||||
self.library_view.model().refresh_ids(set(changes), current_row=self.library_view.currentIndex().row())
|
||||
self.tags_view.recount_with_position_based_index()
|
||||
|
||||
def delete_identifier(self, name, in_vl):
|
||||
d = self.current_db.new_api
|
||||
changed = False
|
||||
books_to_use = self.tags_view.model().get_book_ids_to_use() if in_vl else d.all_book_ids()
|
||||
ids = d.all_field_for('identifiers', books_to_use)
|
||||
new_ids = {}
|
||||
for id_ in ids:
|
||||
for identifier_type in ids[id_]:
|
||||
if identifier_type == name:
|
||||
new_ids[id_] = copy.copy(ids[id_])
|
||||
new_ids[id_].pop(name)
|
||||
changed = True
|
||||
if changed:
|
||||
if in_vl:
|
||||
msg = _('The identifier %s will be deleted from books in the '
|
||||
'current virtual library. Are you sure?')%name
|
||||
else:
|
||||
msg= _('The identifier %s will be deleted from all books. Are you sure?')%name
|
||||
if not question_dialog(self,
|
||||
title=_('Delete identifier'),
|
||||
msg=msg,
|
||||
skip_dialog_name='tag_browser_delete_identifiers',
|
||||
skip_dialog_msg=_('Show this confirmation again')):
|
||||
return
|
||||
d.set_field('identifiers', new_ids)
|
||||
self.tags_view.recount_with_position_based_index()
|
||||
|
||||
def edit_enum_values(self, parent, db, key):
|
||||
from calibre.gui2.dialogs.enum_values_edit import EnumValuesEdit
|
||||
d = EnumValuesEdit(parent, db, key)
|
||||
|
@ -174,6 +174,7 @@ class TagsView(QTreeView): # {{{
|
||||
drag_drop_finished = pyqtSignal(object)
|
||||
restriction_error = pyqtSignal()
|
||||
tag_item_delete = pyqtSignal(object, object, object, object, object)
|
||||
tag_identifier_delete = pyqtSignal(object, object)
|
||||
apply_tag_to_selected = pyqtSignal(object, object, object)
|
||||
edit_enum_values = pyqtSignal(object, object, object)
|
||||
|
||||
@ -530,6 +531,12 @@ class TagsView(QTreeView): # {{{
|
||||
self.tag_item_delete.emit(key, id_, tag.original_name,
|
||||
None, children)
|
||||
return
|
||||
if action == 'delete_identifier':
|
||||
self.tag_identifier_delete.emit(index.tag.name, False)
|
||||
return
|
||||
if action == 'delete_identifier_in_vl':
|
||||
self.tag_identifier_delete.emit(index.tag.name, True)
|
||||
return
|
||||
if action == 'open_editor':
|
||||
self.tags_list_edit.emit(category, key, is_first_letter)
|
||||
return
|
||||
@ -766,6 +773,20 @@ class TagsView(QTreeView): # {{{
|
||||
_('Delete Saved search %s')%display_name(tag),
|
||||
partial(self.context_menu_handler,
|
||||
action='delete_search', key=tag.original_name))
|
||||
elif key == 'identifiers':
|
||||
if self.model().get_in_vl():
|
||||
self.context_menu.addAction(self.delete_icon,
|
||||
_('Delete %s in Virtual Library')%display_name(tag),
|
||||
partial(self.context_menu_handler,
|
||||
action='delete_identifier_in_vl',
|
||||
key=key, index=tag_item))
|
||||
else:
|
||||
self.context_menu.addAction(self.delete_icon,
|
||||
_('Delete %s')%display_name(tag),
|
||||
partial(self.context_menu_handler,
|
||||
action='delete_identifier',
|
||||
key=key, index=tag_item))
|
||||
|
||||
if key.startswith('@') and not item.is_gst:
|
||||
self.context_menu.addAction(self.user_category_icon,
|
||||
_('Remove %(item)s from category %(cat)s')%
|
||||
|
Loading…
x
Reference in New Issue
Block a user