Added filter bookmarks by name as well as url.
This commit is contained in:
parent
ad763685e5
commit
cbc4ec6531
@ -121,3 +121,13 @@ class BaseCompletionModel(QStandardItemModel):
|
||||
Override QAbstractItemModel::sort.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def custom_filter(self, pattern, row, parent):
|
||||
"""Custom filter.
|
||||
|
||||
Args:
|
||||
pattern: The current filter pattern.
|
||||
row: The row to accept or reject in the filter.
|
||||
parent: The parent item QModelIndex.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
@ -137,12 +137,16 @@ class CompletionFilterModel(QSortFilterProxyModel):
|
||||
# No entries in parent model
|
||||
return False
|
||||
data = self.srcmodel.data(idx)
|
||||
# TODO more sophisticated filtering
|
||||
if not self.pattern:
|
||||
return True
|
||||
if not data:
|
||||
return False
|
||||
return self.pattern.casefold() in data.casefold()
|
||||
|
||||
pattern = self.pattern.casefold()
|
||||
try:
|
||||
return self.srcmodel.custom_filter(pattern, row, parent)
|
||||
except NotImplementedError:
|
||||
if not data:
|
||||
return False
|
||||
return pattern in data.casefold()
|
||||
|
||||
def intelligentLessThan(self, lindex, rindex):
|
||||
"""Custom sorting implementation.
|
||||
|
@ -98,6 +98,15 @@ class UrlCompletionModel(base.BaseCompletionModel):
|
||||
"""
|
||||
self.new_item(self._bookmark_cat, url, title)
|
||||
|
||||
def custom_filter(self, pattern, row, parent):
|
||||
"""Filter by url and title.
|
||||
"""
|
||||
index0 = self.index(row, 0, parent)
|
||||
index1 = self.index(row, 1, parent)
|
||||
url = self.data(index0)
|
||||
title = self.data(index1)
|
||||
return pattern in url.casefold() or pattern in title.casefold()
|
||||
|
||||
@config.change_filter('completion', 'timestamp-format')
|
||||
def reformat_timestamps(self):
|
||||
"""Reformat the timestamps if the config option was changed."""
|
||||
|
Loading…
Reference in New Issue
Block a user