Bring back apt search suggestions

This commit is contained in:
Jesper 2024-06-12 12:40:00 +02:00
parent a31731f127
commit b0ab8320da

View File

@ -764,6 +764,7 @@ class pluginclass(object):
def fuzzy_application_search(self, search_text): def fuzzy_application_search(self, search_text):
shownList = [] shownList = []
showns = False # Are any app shown?
keywords = self.strip_case_and_accents(search_text).split() keywords = self.strip_case_and_accents(search_text).split()
labels = [app["button"].appName for app in self.applicationList] labels = [app["button"].appName for app in self.applicationList]
results = process.extract(search_text, labels, limit=len(labels)) results = process.extract(search_text, labels, limit=len(labels))
@ -779,6 +780,7 @@ class pluginclass(object):
app["button"].grab_focus() app["button"].grab_focus()
first_button = False first_button = False
shownList.append(app["button"]) shownList.append(app["button"])
showns = True
# Non-fuzzy results for appGenericName, appComment and appExec # Non-fuzzy results for appGenericName, appComment and appExec
# Again I should really make it a function or something # Again I should really make it a function or something
@ -793,10 +795,13 @@ class pluginclass(object):
app["button"].grab_focus() app["button"].grab_focus()
first_button = False first_button = False
shownList.append(app["button"]) shownList.append(app["button"])
showns = True
return showns
def exact_application_search(self, search_text): def exact_application_search(self, search_text):
shownList = [] shownList = []
showns = False # Are any app shown?
first_button = True first_button = True
keywords = self.strip_case_and_accents(search_text).split() keywords = self.strip_case_and_accents(search_text).split()
# I should probably make a function but whatever # I should probably make a function but whatever
@ -812,6 +817,7 @@ class pluginclass(object):
app["button"].grab_focus() app["button"].grab_focus()
first_button = False first_button = False
shownList.append(app["button"]) shownList.append(app["button"])
showns = True
# Add applications that match appGenericName, appComment or appExec # Add applications that match appGenericName, appComment or appExec
for app in self.applicationList: for app in self.applicationList:
@ -825,6 +831,8 @@ class pluginclass(object):
app["button"].grab_focus() app["button"].grab_focus()
first_button = False first_button = False
shownList.append(app["button"]) shownList.append(app["button"])
showns = True
return showns
def Filter(self, widget, category = None): def Filter(self, widget, category = None):
self.filterTimer = None self.filterTimer = None
@ -841,6 +849,7 @@ class pluginclass(object):
if self.lastActiveTab != 1: if self.lastActiveTab != 1:
self.changeTab(1, clear = False) self.changeTab(1, clear = False)
text = widget.get_text() text = widget.get_text()
showns = False # Are any app shown?
for item in self.applicationList: for item in self.applicationList:
self.applicationsBox.remove(item["button"]) self.applicationsBox.remove(item["button"])
@ -851,10 +860,15 @@ class pluginclass(object):
for item in self.sortedApplicationList: for item in self.sortedApplicationList:
self.applicationsBox.pack_start(item[1], False, False, 0) self.applicationsBox.pack_start(item[1], False, False, 0)
if self.enableFuzzySearch: if self.enableFuzzySearch:
self.fuzzy_application_search(text) showns = self.fuzzy_application_search(text)
else: else:
self.exact_application_search(text) showns = self.exact_application_search(text)
if not showns:
if len(text) >= 3:
self.add_search_suggestions(text)
if self.useAPT:
GLib.timeout_add(300, self.add_apt_filter_results, text)
for i in self.categoriesBox.get_children(): for i in self.categoriesBox.get_children():
i.released() i.released()
i.set_relief(Gtk.ReliefStyle.NONE) i.set_relief(Gtk.ReliefStyle.NONE)