From 625fcca0ae040e8c37adc8f7e8798792466f5ecf Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Sun, 21 May 2023 08:17:05 +0100 Subject: [PATCH 1/3] Bug #2020002: improve error message --- src/calibre/gui2/dialogs/tag_categories.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/calibre/gui2/dialogs/tag_categories.py b/src/calibre/gui2/dialogs/tag_categories.py index 13172b73c7..5e27c37364 100644 --- a/src/calibre/gui2/dialogs/tag_categories.py +++ b/src/calibre/gui2/dialogs/tag_categories.py @@ -284,11 +284,19 @@ class TagCategories(QDialog, Ui_TagCategories): 'or after periods.')).exec() return False for c in sorted(self.user_categories.keys(), key=primary_sort_key): - if strcmp(c, cat_name) == 0 or \ - (icu_lower(cat_name).startswith(icu_lower(c) + '.') and - not cat_name.startswith(c + '.')): + if strcmp(c, cat_name) == 0: error_dialog(self, _('Name already used'), - _('That name is already used, perhaps with different case.')).exec() + _('The user category name is already used, perhaps with different case.'), + det_msg=_('Existing category: {existing}\nNew category: {new}').format(existing=c, new=cat_name), + show=True) + return False + if icu_lower(cat_name).startswith(icu_lower(c) + '.') and not cat_name.startswith(c + '.'): + error_dialog(self, _('Name already used'), + _('The hierarchical prefix of the new category is already used, ' + 'perhaps with different case.'), + det_msg=_('Existing prefix: {prefix}\n' + 'New category: {new}').format(prefix=c, new=cat_name), + show=True) return False if cat_name not in self.user_categories: self.user_categories[cat_name] = set() @@ -316,7 +324,10 @@ class TagCategories(QDialog, Ui_TagCategories): for c in self.user_categories: if strcmp(c, cat_name) == 0: error_dialog(self, _('Name already used'), - _('That name is already used, perhaps with different case.')).exec() + _('The user category name is already used, perhaps with different case.'), + det_msg=_('Existing category: {existing}\n' + 'New category: {new}').format(existing=c, new=cat_name), + show=True) return # The order below is important because of signals self.user_categories[cat_name] = self.user_categories[self.current_cat_name] From b82b2fde9752de8a318a875bac3386515b88542c Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Sun, 21 May 2023 08:40:02 +0100 Subject: [PATCH 2/3] Enhancement #2019513: category editor: allow selections only in the current column instead of reporting an error. --- src/calibre/gui2/dialogs/tag_list_editor.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/calibre/gui2/dialogs/tag_list_editor.py b/src/calibre/gui2/dialogs/tag_list_editor.py index 0c78e25cab..e5d2fb5a17 100644 --- a/src/calibre/gui2/dialogs/tag_list_editor.py +++ b/src/calibre/gui2/dialogs/tag_list_editor.py @@ -647,16 +647,11 @@ class TagListEditor(QDialog, Ui_TagListEditor): self.table.blockSignals(False) def selection_changed(self): - col0 = tuple(item for item in self.table.selectedItems() if item.column() == 0) - col3 = tuple(item for item in self.table.selectedItems() if item.column() == 3) - if col0 and col3: - error_dialog(self, _('Cannot select in multiple columns'), - '

'+_('Selection of items in multiple columns is not supported. ' - 'The selection will be cleared')+'
', - show=True) - sm = self.table.selectionModel() + if self.table.currentIndex().isValid(): + col = self.table.currentIndex().column() self.table.blockSignals(True) - sm.clear() + for itm in (item for item in self.table.selectedItems() if item.column() != col): + itm.setSelected(False) self.table.blockSignals(False) def check_for_deleted_items(self, show_error=False): From 1e78b9fe7c295c43376425e574a4b3644cc25820 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Sun, 21 May 2023 09:28:29 +0100 Subject: [PATCH 3/3] Bug #2019457: Tag browser - transient right click error. The search category can disappear from field_metadata. Perhaps other dynamic categories can as well. The implication is that dynamic categories are being removed, but how that would happen is a mystery. I suspect a plugin is operating on the "real" field_metadata instead of a copy, thereby changing the dict used by the rest of calibre. As it can happen, to avoid key errors check that a category exists before offering to unhide it. --- src/calibre/gui2/tag_browser/view.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/tag_browser/view.py b/src/calibre/gui2/tag_browser/view.py index 7e21e755f3..dad222f99a 100644 --- a/src/calibre/gui2/tag_browser/view.py +++ b/src/calibre/gui2/tag_browser/view.py @@ -722,7 +722,16 @@ class TagsView(QTreeView): # {{{ added_show_hidden_categories = True m = self.context_menu.addMenu(_('Show category')) m.setIcon(QIcon.ic('plus.png')) - for col in sorted(self.hidden_categories, + # The search category can disappear from field_metadata. Perhaps + # other dynamic categories can as well. The implication is that + # dynamic categories are being removed, but how that would + # happen is a mystery. I suspect a plugin is operating on the + # "real" field_metadata instead of a copy, thereby changing the + # dict used by the rest of calibre. + # + # As it can happen, to avoid key errors check that a category + # exists before offering to unhide it. + for col in sorted((c for c in self.hidden_categories if c in self.db.field_metadata), key=lambda x: sort_key(self.db.field_metadata[x]['name'])): ac = m.addAction(self.db.field_metadata[col]['name'], partial(self.context_menu_handler, action='show', category=col))