Fixes #1909738 [Strangeness with hierarchical searches](https://bugs.launchpad.net/calibre/+bug/1909738)
This commit is contained in:
Kovid Goyal 2020-12-31 19:07:57 +05:30
commit 2b3dfeeb31
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 22 additions and 16 deletions

View File

@ -153,20 +153,13 @@ class SavedSearchEditor(Dialog):
self.slist.addItem(name) self.slist.addItem(name)
def add_search(self): def add_search(self):
d = AddSavedSearch(parent=self, commit_changes=False) d = AddSavedSearch(parent=self, commit_changes=False, validate=self.validate_add)
if d.exec_() != QDialog.DialogCode.Accepted: if d.exec_() != QDialog.DialogCode.Accepted:
return return
name, expression = d.accepted_data name, expression = d.accepted_data
nmap = {icu_lower(n):n for n in self.searches}
if icu_lower(name) in nmap:
q = nmap[icu_lower(name)]
del self.searches[q]
self.select_search(q)
self.slist.takeItem(self.slist.currentRow())
self.searches[name] = expression self.searches[name] = expression
self.slist.insertItem(0, name) self.populate_search_list()
self.slist.setCurrentRow(0) self.select_search(name)
self.current_index_changed(self.slist.currentItem())
def del_search(self): def del_search(self):
n = self.current_search_name n = self.current_search_name
@ -184,7 +177,9 @@ class SavedSearchEditor(Dialog):
n = self.current_search_name n = self.current_search_name
if not n: if not n:
return return
d = AddSavedSearch(parent=self, commit_changes=False, label=_('Edit the name and/or expression below.'), validate=self.validate_edit) d = AddSavedSearch(parent=self, commit_changes=False,
label=_('Edit the name and/or expression below.'),
validate=self.validate_edit)
d.setWindowTitle(_('Edit saved search')) d.setWindowTitle(_('Edit saved search'))
d.sname.setText(n) d.sname.setText(n)
d.search.setText(self.searches[n]) d.search.setText(self.searches[n])
@ -196,10 +191,17 @@ class SavedSearchEditor(Dialog):
self.searches[name] = expression self.searches[name] = expression
self.current_index_changed(self.slist.currentItem()) self.current_index_changed(self.slist.currentItem())
def duplicate_msg(self, name):
return _('A saved search with the name {} already exists. Choose another name').format(name)
def validate_edit(self, name, expression): def validate_edit(self, name, expression):
q = self.current_search_name q = self.current_search_name
if icu_lower(name) in {icu_lower(n) for n in self.searches if n != q}: if icu_lower(name) in {icu_lower(n) for n in self.searches if n != q}:
return _('A saved search with the name {} already exists. Choose another name').format(name) return self.duplicate_msg(name)
def validate_add(self, name, expression):
if icu_lower(name) in {icu_lower(n) for n in self.searches}:
return self.duplicate_msg(name)
def select_search(self, name): def select_search(self, name):
items = self.slist.findItems(name, Qt.MatchFlag.MatchFixedString | Qt.MatchFlag.MatchCaseSensitive) items = self.slist.findItems(name, Qt.MatchFlag.MatchFixedString | Qt.MatchFlag.MatchCaseSensitive)

View File

@ -1372,10 +1372,12 @@ class TagsModel(QAbstractItemModel): # {{{
if index.isValid(): if index.isValid():
node = self.data(index, Qt.ItemDataRole.UserRole) node = self.data(index, Qt.ItemDataRole.UserRole)
if node.type == TagTreeItem.TAG: if node.type == TagTreeItem.TAG:
if node.tag.is_editable or node.tag.is_hierarchical: tag = node.tag
category = tag.category
if (tag.is_editable or tag.is_hierarchical) and category != 'search':
ans |= Qt.ItemFlag.ItemIsDragEnabled ans |= Qt.ItemFlag.ItemIsDragEnabled
fm = self.db.metadata_for_field(node.tag.category) fm = self.db.metadata_for_field(category)
if node.tag.category in \ if category in \
('tags', 'series', 'authors', 'rating', 'publisher', 'languages') or \ ('tags', 'series', 'authors', 'rating', 'publisher', 'languages') or \
(fm['is_custom'] and (fm['is_custom'] and
fm['datatype'] in ['text', 'rating', 'series', 'enumeration']): fm['datatype'] in ['text', 'rating', 'series', 'enumeration']):

View File

@ -685,7 +685,9 @@ class TagsView(QTreeView): # {{{
if tag: if tag:
# If the user right-clicked on an editable item, then offer # If the user right-clicked on an editable item, then offer
# the possibility of renaming that item. # the possibility of renaming that item.
if fm['datatype'] != 'composite' and (tag.is_editable or tag.is_hierarchical): if (fm['datatype'] != 'composite' and
(tag.is_editable or tag.is_hierarchical) and
key != 'search'):
# Add the 'rename' items to both interior and leaf nodes # Add the 'rename' items to both interior and leaf nodes
if fm['datatype'] != 'enumeration': if fm['datatype'] != 'enumeration':
if self.model().get_in_vl(): if self.model().get_in_vl():