diff --git a/src/calibre/gui2/tag_browser/model.py b/src/calibre/gui2/tag_browser/model.py index 746c91bb56..b7afa288cd 100644 --- a/src/calibre/gui2/tag_browser/model.py +++ b/src/calibre/gui2/tag_browser/model.py @@ -855,6 +855,9 @@ class TagsModel(QAbstractItemModel): # {{{ 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): if self.db.data.get_base_restriction() or self.db.data.get_search_restriction(): return self.db.search('', return_matches=True, sort_results=False) @@ -1043,7 +1046,7 @@ class TagsModel(QAbstractItemModel): # {{{ item.tag.name = val self.search_item_renamed.emit() # Does a refresh 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}, restrict_to_book_ids=restrict_to_book_ids) self.tag_item_renamed.emit() diff --git a/src/calibre/gui2/tag_browser/ui.py b/src/calibre/gui2/tag_browser/ui.py index b2a0006955..5dafbb6953 100644 --- a/src/calibre/gui2/tag_browser/ui.py +++ b/src/calibre/gui2/tag_browser/ui.py @@ -223,31 +223,32 @@ class TagBrowserMixin(object): # {{{ if (category in ['tags', 'series', 'publisher'] or db.new_api.field_metadata.is_custom_field(category)): 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: - m.delete_item_from_all_user_categories(orig_name[item], category) - for old_id in to_rename and not restrict_to_book_ids: + for item in to_delete: + m.delete_item_from_all_user_categories(orig_name[item], category) + for old_id in to_rename: m.rename_item_in_all_user_categories(orig_name[old_id], category, unicode(to_rename[old_id])) 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, - restrict_to_book_ids=restrict_to_book_ids) + restrict_to_book_ids=None) # Clean up the library view self.do_tag_item_renamed() 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. ''' + 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, title=_('Delete item'), - msg='

'+ - _('%s will be deleted from all books. Are you sure?') %orig_name, + msg='

'+ msg, skip_dialog_name='tag_item_delete', skip_dialog_msg=_('Show this confirmation again')): return @@ -264,7 +265,6 @@ class TagBrowserMixin(object): # {{{ delete_func = partial(db.delete_custom_item_using_id, label=cc_label) m = self.tags_view.model() 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) if not restrict_to_book_ids: m.delete_item_from_all_user_categories(orig_name, category) diff --git a/src/calibre/gui2/tag_browser/view.py b/src/calibre/gui2/tag_browser/view.py index 21186b6226..d51fddff0a 100644 --- a/src/calibre/gui2/tag_browser/view.py +++ b/src/calibre/gui2/tag_browser/view.py @@ -297,7 +297,8 @@ class TagsView(QTreeView): # {{{ self.clear() 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: return try: @@ -328,7 +329,14 @@ class TagsView(QTreeView): # {{{ self.recount() 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) return if action == 'delete_item': @@ -441,15 +449,26 @@ class TagsView(QTreeView): # {{{ # the possibility of renaming that item. if tag.is_editable: # 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, - _('Rename %s')%display_name(tag), - partial(self.context_menu_handler, action='edit_item', - index=index)) + _('Rename %s')%display_name(tag), + partial(self.context_menu_handler, action='edit_item_no_vl', + index=index)) if key in ('tags', 'series', 'publisher') or \ 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, _('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)) if key == 'authors': 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: self.context_menu.addAction(self.rename_icon, _('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)) self.context_menu.addAction(self.delete_icon, _('Delete search %s')%display_name(tag), @@ -512,7 +531,7 @@ class TagsView(QTreeView): # {{{ if item.can_be_edited: self.context_menu.addAction(self.rename_icon, _('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)) self.context_menu.addAction(self.user_category_icon, _('Add sub-category to %s')%item.py_name,