Compare and save filters normalised

When checking whether the current search is a saved filter, compare the
searches normalised to allow the detection of equivalent expressions.
Invalid searches are accepted unaltered to allow the deletion of invalid
saved filters.
As for saving new filters, do so normalised, respectively, reject
invalid searches.
This commit is contained in:
RumovZ 2021-01-07 22:11:21 +01:00
parent 478a3bd0bc
commit d30062a8a5

View File

@ -1413,14 +1413,20 @@ QTableView {{ gridline-color: {grid} }}
return ml
def _onSaveFilter(self) -> None:
name = getOnlyText(tr(TR.BROWSING_PLEASE_GIVE_YOUR_FILTER_A_NAME))
if not name:
return
filt = self.form.searchEdit.lineEdit().text()
conf = self.col.get_config("savedFilters")
conf[name] = filt
self.col.set_config("savedFilters", conf)
self.maybeRefreshSidebar()
try:
filt = self.col.backend.normalize_search(
self.form.searchEdit.lineEdit().text()
)
except InvalidInput as e:
showWarning(str(e))
else:
name = getOnlyText(tr(TR.BROWSING_PLEASE_GIVE_YOUR_FILTER_A_NAME))
if not name:
return
conf = self.col.get_config("savedFilters")
conf[name] = filt
self.col.set_config("savedFilters", conf)
self.maybeRefreshSidebar()
def _onRemoveFilter(self):
name = self._currentFilterIsSaved()
@ -1433,7 +1439,15 @@ QTableView {{ gridline-color: {grid} }}
# returns name if found
def _currentFilterIsSaved(self):
filt = self.form.searchEdit.lineEdit().text()
try:
filt = self.col.backend.normalize_search(filt)
except InvalidInput:
pass
for k, v in self.col.get_config("savedFilters").items():
try:
v = self.col.backend.normalize_search(v)
except InvalidInput:
pass
if filt == v:
return k
return None