diff --git a/src/calibre/gui2/dialogs/tag_list_editor.py b/src/calibre/gui2/dialogs/tag_list_editor.py index ae3aa5ede7..49be9c6619 100644 --- a/src/calibre/gui2/dialogs/tag_list_editor.py +++ b/src/calibre/gui2/dialogs/tag_list_editor.py @@ -91,7 +91,7 @@ class EditColumnDelegate(QItemDelegate): class TagListEditor(QDialog, Ui_TagListEditor): - def __init__(self, window, cat_name, tag_to_match, data, sorter): + def __init__(self, window, cat_name, tag_to_match, get_book_ids, sorter): QDialog.__init__(self, window) Ui_TagListEditor.__init__(self) self.setupUi(self) @@ -113,15 +113,9 @@ class TagListEditor(QDialog, Ui_TagListEditor): pass # initialization - self.to_rename = {} - self.to_delete = set([]) - self.all_tags = {} - self.original_names = {} - - for k,v,count in data: - self.all_tags[v] = {'key': k, 'count': count, 'cur_name': v, 'is_deleted': False} - self.original_names[k] = v - self.ordered_tags = sorted(self.all_tags.keys(), key=sorter) + self.ordered_tags = [] + self.sorter = sorter + self.get_book_ids = get_book_ids # Set up the column headings self.down_arrow_icon = QIcon(I('arrow-down.png')) @@ -140,7 +134,7 @@ class TagListEditor(QDialog, Ui_TagListEditor): self.table.setItemDelegate(EditColumnDelegate(self.table)) # Add the data - select_item = self.fill_in_table(self.ordered_tags, tag_to_match) + select_item = self.fill_in_table(None, tag_to_match) # Scroll to the selected item if there is one if select_item is not None: @@ -160,6 +154,8 @@ class TagListEditor(QDialog, Ui_TagListEditor): self.search_button.clicked.connect(self.all_matching_clicked) self.search_button.setDefault(True) + self.apply_vl_checkbox.clicked.connect(self.vl_box_changed) + self.table.setEditTriggers(QTableWidget.EditKeyPressed) try: @@ -171,7 +167,23 @@ class TagListEditor(QDialog, Ui_TagListEditor): except: pass + def vl_box_changed(self): + self.fill_in_table(None, None) + def fill_in_table(self, tags, tag_to_match): + self.to_rename = {} + self.to_delete = set([]) + self.all_tags = {} + self.original_names = {} + + data = self.get_book_ids(self.apply_vl_checkbox.isChecked()) + for k,v,count in data: + self.all_tags[v] = {'key': k, 'count': count, 'cur_name': v, 'is_deleted': False} + self.original_names[k] = v + self.ordered_tags = sorted(self.all_tags.keys(), key=self.sorter) + if tags is None: + tags = self.ordered_tags + select_item = None self.table.blockSignals(True) self.table.clear() @@ -220,7 +232,7 @@ class TagListEditor(QDialog, Ui_TagListEditor): self.all_tags[tag]['is_deleted'] = item.is_deleted search_for = icu_lower(unicode(self.search_box.text())) if len(search_for) == 0: - self.fill_in_table(self.ordered_tags, None) + self.fill_in_table(None, None) result = [] for k in self.ordered_tags: if search_for in icu_lower(unicode(self.all_tags[k]['cur_name'])): diff --git a/src/calibre/gui2/dialogs/tag_list_editor.ui b/src/calibre/gui2/dialogs/tag_list_editor.ui index c7dc4b030a..d38d2b9bb1 100644 --- a/src/calibre/gui2/dialogs/tag_list_editor.ui +++ b/src/calibre/gui2/dialogs/tag_list_editor.ui @@ -59,7 +59,19 @@ - + + + + <p>Show items in the Available items box only if they appear in the + current virtual library. Applied items not in the VL will be marked + "not on any book".</p> + + + &Show only available items in current virtual library + + + + @@ -132,7 +144,7 @@ - + true diff --git a/src/calibre/gui2/tag_browser/ui.py b/src/calibre/gui2/tag_browser/ui.py index e6db960949..d3de5410b3 100644 --- a/src/calibre/gui2/tag_browser/ui.py +++ b/src/calibre/gui2/tag_browser/ui.py @@ -237,13 +237,15 @@ class TagBrowserMixin(object): # {{{ ''' db = self.current_db - data = db.new_api.get_categories() - if category in data: - result = [(t.id, t.original_name, t.count) for t in data[category] if t.count > 0] - else: - result = None - if result is None: - return + + def get_book_ids(use_virtual_library): + book_ids = None if not use_virtual_library else self.tags_view.model().get_book_ids_to_use() + data = db.new_api.get_categories(book_ids=book_ids) + if category in data: + result = [(t.id, t.original_name, t.count) for t in data[category] if t.count > 0] + else: + result = None + return result if category == 'series': key = lambda x:sort_key(title_sort(x)) @@ -251,7 +253,7 @@ class TagBrowserMixin(object): # {{{ key = sort_key d = TagListEditor(self, cat_name=db.field_metadata[category]['name'], - tag_to_match=tag, data=result, sorter=key) + tag_to_match=tag, get_book_ids=get_book_ids, sorter=key) d.exec_() if d.result() == d.Accepted: to_rename = d.to_rename # dict of old id to new name