This commit is contained in:
Kovid Goyal 2023-05-21 21:42:40 +05:30
commit 58bdba4cc9
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 30 additions and 15 deletions

View File

@ -284,11 +284,19 @@ class TagCategories(QDialog, Ui_TagCategories):
'or after periods.')).exec() 'or after periods.')).exec()
return False return False
for c in sorted(self.user_categories.keys(), key=primary_sort_key): for c in sorted(self.user_categories.keys(), key=primary_sort_key):
if strcmp(c, cat_name) == 0 or \ if strcmp(c, cat_name) == 0:
(icu_lower(cat_name).startswith(icu_lower(c) + '.') and
not cat_name.startswith(c + '.')):
error_dialog(self, _('Name already used'), 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 return False
if cat_name not in self.user_categories: if cat_name not in self.user_categories:
self.user_categories[cat_name] = set() self.user_categories[cat_name] = set()
@ -316,7 +324,10 @@ class TagCategories(QDialog, Ui_TagCategories):
for c in self.user_categories: for c in self.user_categories:
if strcmp(c, cat_name) == 0: if strcmp(c, cat_name) == 0:
error_dialog(self, _('Name already used'), 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 return
# The order below is important because of signals # The order below is important because of signals
self.user_categories[cat_name] = self.user_categories[self.current_cat_name] self.user_categories[cat_name] = self.user_categories[self.current_cat_name]

View File

@ -647,16 +647,11 @@ class TagListEditor(QDialog, Ui_TagListEditor):
self.table.blockSignals(False) self.table.blockSignals(False)
def selection_changed(self): def selection_changed(self):
col0 = tuple(item for item in self.table.selectedItems() if item.column() == 0) if self.table.currentIndex().isValid():
col3 = tuple(item for item in self.table.selectedItems() if item.column() == 3) col = self.table.currentIndex().column()
if col0 and col3:
error_dialog(self, _('Cannot select in multiple columns'),
'<p>'+_('Selection of items in multiple columns is not supported. '
'The selection will be cleared')+'<br>',
show=True)
sm = self.table.selectionModel()
self.table.blockSignals(True) 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) self.table.blockSignals(False)
def check_for_deleted_items(self, show_error=False): def check_for_deleted_items(self, show_error=False):

View File

@ -722,7 +722,16 @@ class TagsView(QTreeView): # {{{
added_show_hidden_categories = True added_show_hidden_categories = True
m = self.context_menu.addMenu(_('Show category')) m = self.context_menu.addMenu(_('Show category'))
m.setIcon(QIcon.ic('plus.png')) 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'])): key=lambda x: sort_key(self.db.field_metadata[x]['name'])):
ac = m.addAction(self.db.field_metadata[col]['name'], ac = m.addAction(self.db.field_metadata[col]['name'],
partial(self.context_menu_handler, action='show', category=col)) partial(self.context_menu_handler, action='show', category=col))