mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix for Bug #1909738: Strangeness with hierarchical searches
Because it is useful I decided to continue to permit hierarchy for saved searches even though behavior will be a bit strange. The following behaviors exist and will not be changed. - Renames will not rename all items in the the hierarchy. - Intermediate nodes that aren't 'real' searches will not offer the rename option. - Drag & drop is disabled. In addition I changed the behavior of "Add search" in "Manage saved searches". It used to act like a rename if the target name already exists, throwing away the old search expression. It now refuses.
This commit is contained in:
parent
1eb424dcb7
commit
4131efa270
@ -153,20 +153,13 @@ class SavedSearchEditor(Dialog):
|
||||
self.slist.addItem(name)
|
||||
|
||||
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:
|
||||
return
|
||||
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.slist.insertItem(0, name)
|
||||
self.slist.setCurrentRow(0)
|
||||
self.current_index_changed(self.slist.currentItem())
|
||||
self.populate_search_list()
|
||||
self.select_search(name)
|
||||
|
||||
def del_search(self):
|
||||
n = self.current_search_name
|
||||
@ -184,7 +177,9 @@ class SavedSearchEditor(Dialog):
|
||||
n = self.current_search_name
|
||||
if not n:
|
||||
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.sname.setText(n)
|
||||
d.search.setText(self.searches[n])
|
||||
@ -196,10 +191,17 @@ class SavedSearchEditor(Dialog):
|
||||
self.searches[name] = expression
|
||||
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):
|
||||
q = self.current_search_name
|
||||
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):
|
||||
items = self.slist.findItems(name, Qt.MatchFlag.MatchFixedString | Qt.MatchFlag.MatchCaseSensitive)
|
||||
|
@ -1372,10 +1372,12 @@ class TagsModel(QAbstractItemModel): # {{{
|
||||
if index.isValid():
|
||||
node = self.data(index, Qt.ItemDataRole.UserRole)
|
||||
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
|
||||
fm = self.db.metadata_for_field(node.tag.category)
|
||||
if node.tag.category in \
|
||||
fm = self.db.metadata_for_field(category)
|
||||
if category in \
|
||||
('tags', 'series', 'authors', 'rating', 'publisher', 'languages') or \
|
||||
(fm['is_custom'] and
|
||||
fm['datatype'] in ['text', 'rating', 'series', 'enumeration']):
|
||||
|
@ -685,7 +685,9 @@ class TagsView(QTreeView): # {{{
|
||||
if tag:
|
||||
# If the user right-clicked on an editable item, then offer
|
||||
# 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
|
||||
if fm['datatype'] != 'enumeration':
|
||||
if self.model().get_in_vl():
|
||||
|
Loading…
x
Reference in New Issue
Block a user