Skip to content
This repository has been archived by the owner on Aug 23, 2021. It is now read-only.

Commit

Permalink
Add Search Function
Browse files Browse the repository at this point in the history
  • Loading branch information
aimproxy committed Jul 22, 2019
1 parent 8e4df13 commit edbdc33
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/Views/Sidebar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ using App.Windows;

namespace App.Views {
public class Sidebar : Gtk.ScrolledWindow {
Gtk.Box box;
Gtk.SearchEntry search_entry;
Gtk.ListBox listbox;
Gapi gapi;

Expand All @@ -48,10 +50,25 @@ namespace App.Views {
listbox = new Gtk.ListBox ();
listbox.activate_on_single_click = true;
listbox.selection_mode = Gtk.SelectionMode.SINGLE;
listbox.set_filter_func (filter_function);

search_entry = new Gtk.SearchEntry ();
search_entry.margin = 8;
search_entry.hexpand = true;
search_entry.placeholder_text = _("Search Friends");
search_entry.valign = Gtk.Align.CENTER;

box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
box.pack_start (search_entry, false, false);
box.pack_start (listbox, false, false);

this.hscrollbar_policy = Gtk.PolicyType.NEVER;
this.vexpand = true;
this.add (listbox);
this.add (box);

search_entry.search_changed.connect (() => {
listbox.invalidate_filter ();
});

try {
gapi.load_trending ();
Expand Down Expand Up @@ -79,6 +96,23 @@ namespace App.Views {

}

[CCode (instance_pos = -1)]
private bool filter_function (Gtk.ListBoxRow row) {
var font = ((FontListRow) row).font_family;

if (font == null) {
return false;
}

var search_term = search_entry.text.down ();

if (search_term in font.down ()) {
return true;
}

return false;
}

}

}

0 comments on commit edbdc33

Please sign in to comment.