mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Add additional context menu items for edit/delete when a VL is in effect
This commit is contained in:
parent
7e1bfa006a
commit
42dab3af46
@ -855,6 +855,9 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
self.drag_drop_finished.emit(ids)
|
self.drag_drop_finished.emit(ids)
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
def get_in_vl(self):
|
||||||
|
return self.db.data.get_base_restriction() or self.db.data.get_search_restriction()
|
||||||
|
|
||||||
def get_book_ids_to_use(self):
|
def get_book_ids_to_use(self):
|
||||||
if self.db.data.get_base_restriction() or self.db.data.get_search_restriction():
|
if self.db.data.get_base_restriction() or self.db.data.get_search_restriction():
|
||||||
return self.db.search('', return_matches=True, sort_results=False)
|
return self.db.search('', return_matches=True, sort_results=False)
|
||||||
@ -1043,7 +1046,7 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
item.tag.name = val
|
item.tag.name = val
|
||||||
self.search_item_renamed.emit() # Does a refresh
|
self.search_item_renamed.emit() # Does a refresh
|
||||||
else:
|
else:
|
||||||
restrict_to_book_ids=self.get_book_ids_to_use()
|
restrict_to_book_ids=self.get_book_ids_to_use() if item.use_vl else None
|
||||||
self.db.new_api.rename_items(key, {item.tag.id: val},
|
self.db.new_api.rename_items(key, {item.tag.id: val},
|
||||||
restrict_to_book_ids=restrict_to_book_ids)
|
restrict_to_book_ids=restrict_to_book_ids)
|
||||||
self.tag_item_renamed.emit()
|
self.tag_item_renamed.emit()
|
||||||
|
@ -223,31 +223,32 @@ class TagBrowserMixin(object): # {{{
|
|||||||
if (category in ['tags', 'series', 'publisher'] or
|
if (category in ['tags', 'series', 'publisher'] or
|
||||||
db.new_api.field_metadata.is_custom_field(category)):
|
db.new_api.field_metadata.is_custom_field(category)):
|
||||||
m = self.tags_view.model()
|
m = self.tags_view.model()
|
||||||
restrict_to_book_ids = m.get_book_ids_to_use()
|
|
||||||
if not restrict_to_book_ids:
|
|
||||||
for item in to_delete:
|
for item in to_delete:
|
||||||
m.delete_item_from_all_user_categories(orig_name[item], category)
|
m.delete_item_from_all_user_categories(orig_name[item], category)
|
||||||
for old_id in to_rename and not restrict_to_book_ids:
|
for old_id in to_rename:
|
||||||
m.rename_item_in_all_user_categories(orig_name[old_id],
|
m.rename_item_in_all_user_categories(orig_name[old_id],
|
||||||
category, unicode(to_rename[old_id]))
|
category, unicode(to_rename[old_id]))
|
||||||
|
|
||||||
db.new_api.remove_items(category, to_delete,
|
db.new_api.remove_items(category, to_delete,
|
||||||
restrict_to_book_ids=restrict_to_book_ids)
|
restrict_to_book_ids=None)
|
||||||
db.new_api.rename_items(category, to_rename, change_index=False,
|
db.new_api.rename_items(category, to_rename, change_index=False,
|
||||||
restrict_to_book_ids=restrict_to_book_ids)
|
restrict_to_book_ids=None)
|
||||||
|
|
||||||
# Clean up the library view
|
# Clean up the library view
|
||||||
self.do_tag_item_renamed()
|
self.do_tag_item_renamed()
|
||||||
self.tags_view.recount()
|
self.tags_view.recount()
|
||||||
|
|
||||||
def do_tag_item_delete(self, category, item_id, orig_name):
|
def do_tag_item_delete(self, category, item_id, orig_name, restrict_to_book_ids=None):
|
||||||
'''
|
'''
|
||||||
Delete an item from some category.
|
Delete an item from some category.
|
||||||
'''
|
'''
|
||||||
|
if restrict_to_book_ids:
|
||||||
|
msg = _('%s will be deleted from books in the virtual library. Are you sure?')%orig_name
|
||||||
|
else:
|
||||||
|
msg = _('%s will be deleted from all books. Are you sure?')%orig_name,
|
||||||
if not question_dialog(self.tags_view,
|
if not question_dialog(self.tags_view,
|
||||||
title=_('Delete item'),
|
title=_('Delete item'),
|
||||||
msg='<p>'+
|
msg='<p>'+ msg,
|
||||||
_('%s will be deleted from all books. Are you sure?') %orig_name,
|
|
||||||
skip_dialog_name='tag_item_delete',
|
skip_dialog_name='tag_item_delete',
|
||||||
skip_dialog_msg=_('Show this confirmation again')):
|
skip_dialog_msg=_('Show this confirmation again')):
|
||||||
return
|
return
|
||||||
@ -264,7 +265,6 @@ class TagBrowserMixin(object): # {{{
|
|||||||
delete_func = partial(db.delete_custom_item_using_id, label=cc_label)
|
delete_func = partial(db.delete_custom_item_using_id, label=cc_label)
|
||||||
m = self.tags_view.model()
|
m = self.tags_view.model()
|
||||||
if delete_func:
|
if delete_func:
|
||||||
restrict_to_book_ids=m.get_book_ids_to_use()
|
|
||||||
delete_func(item_id, restrict_to_book_ids=restrict_to_book_ids)
|
delete_func(item_id, restrict_to_book_ids=restrict_to_book_ids)
|
||||||
if not restrict_to_book_ids:
|
if not restrict_to_book_ids:
|
||||||
m.delete_item_from_all_user_categories(orig_name, category)
|
m.delete_item_from_all_user_categories(orig_name, category)
|
||||||
|
@ -297,7 +297,8 @@ class TagsView(QTreeView): # {{{
|
|||||||
self.clear()
|
self.clear()
|
||||||
|
|
||||||
def context_menu_handler(self, action=None, category=None,
|
def context_menu_handler(self, action=None, category=None,
|
||||||
key=None, index=None, search_state=None):
|
key=None, index=None, search_state=None,
|
||||||
|
use_vl=None):
|
||||||
if not action:
|
if not action:
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
@ -328,7 +329,14 @@ class TagsView(QTreeView): # {{{
|
|||||||
self.recount()
|
self.recount()
|
||||||
return
|
return
|
||||||
|
|
||||||
if action == 'edit_item':
|
if action == 'edit_item_no_vl':
|
||||||
|
item = self.model().get_node(index)
|
||||||
|
item.use_vl = False
|
||||||
|
self.edit(index)
|
||||||
|
return
|
||||||
|
if action == 'edit_item_in_vl':
|
||||||
|
item = self.model().get_node(index)
|
||||||
|
item.use_vl = True
|
||||||
self.edit(index)
|
self.edit(index)
|
||||||
return
|
return
|
||||||
if action == 'delete_item':
|
if action == 'delete_item':
|
||||||
@ -441,15 +449,26 @@ class TagsView(QTreeView): # {{{
|
|||||||
# the possibility of renaming that item.
|
# the possibility of renaming that item.
|
||||||
if tag.is_editable:
|
if tag.is_editable:
|
||||||
# Add the 'rename' items
|
# Add the 'rename' items
|
||||||
|
if self.model().get_in_vl():
|
||||||
|
self.context_menu.addAction(self.rename_icon,
|
||||||
|
_('Rename %s in virtual library')%display_name(tag),
|
||||||
|
partial(self.context_menu_handler, action='edit_item_in_vl',
|
||||||
|
index=index))
|
||||||
self.context_menu.addAction(self.rename_icon,
|
self.context_menu.addAction(self.rename_icon,
|
||||||
_('Rename %s')%display_name(tag),
|
_('Rename %s')%display_name(tag),
|
||||||
partial(self.context_menu_handler, action='edit_item',
|
partial(self.context_menu_handler, action='edit_item_no_vl',
|
||||||
index=index))
|
index=index))
|
||||||
if key in ('tags', 'series', 'publisher') or \
|
if key in ('tags', 'series', 'publisher') or \
|
||||||
self._model.db.field_metadata.is_custom_field(key):
|
self._model.db.field_metadata.is_custom_field(key):
|
||||||
|
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_item_in_vl',
|
||||||
|
key=key, index=tag))
|
||||||
|
|
||||||
self.context_menu.addAction(self.delete_icon,
|
self.context_menu.addAction(self.delete_icon,
|
||||||
_('Delete %s')%display_name(tag),
|
_('Delete %s')%display_name(tag),
|
||||||
partial(self.context_menu_handler, action='delete_item',
|
partial(self.context_menu_handler, action='delete_item_no_vl',
|
||||||
key=key, index=tag))
|
key=key, index=tag))
|
||||||
if key == 'authors':
|
if key == 'authors':
|
||||||
self.context_menu.addAction(_('Edit sort for %s')%display_name(tag),
|
self.context_menu.addAction(_('Edit sort for %s')%display_name(tag),
|
||||||
@ -482,7 +501,7 @@ class TagsView(QTreeView): # {{{
|
|||||||
elif key == 'search' and tag.is_searchable:
|
elif key == 'search' and tag.is_searchable:
|
||||||
self.context_menu.addAction(self.rename_icon,
|
self.context_menu.addAction(self.rename_icon,
|
||||||
_('Rename %s')%display_name(tag),
|
_('Rename %s')%display_name(tag),
|
||||||
partial(self.context_menu_handler, action='edit_item',
|
partial(self.context_menu_handler, action='edit_item_no_vl',
|
||||||
index=index))
|
index=index))
|
||||||
self.context_menu.addAction(self.delete_icon,
|
self.context_menu.addAction(self.delete_icon,
|
||||||
_('Delete search %s')%display_name(tag),
|
_('Delete search %s')%display_name(tag),
|
||||||
@ -512,7 +531,7 @@ class TagsView(QTreeView): # {{{
|
|||||||
if item.can_be_edited:
|
if item.can_be_edited:
|
||||||
self.context_menu.addAction(self.rename_icon,
|
self.context_menu.addAction(self.rename_icon,
|
||||||
_('Rename %s')%item.py_name,
|
_('Rename %s')%item.py_name,
|
||||||
partial(self.context_menu_handler, action='edit_item',
|
partial(self.context_menu_handler, action='edit_item_no_vl',
|
||||||
index=index))
|
index=index))
|
||||||
self.context_menu.addAction(self.user_category_icon,
|
self.context_menu.addAction(self.user_category_icon,
|
||||||
_('Add sub-category to %s')%item.py_name,
|
_('Add sub-category to %s')%item.py_name,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user