public class PoetsPage : Gtk.Box {
private Gtk.StringFilter sfilter;
private Gtk.SearchEntry search_entry;
public PoetsPage () {
GLib.Object (orientation: Gtk.Orientation.VERTICAL, spacing: 0);
var db = new ConnectDB ();
db.load_all_poets ();
var scroll = new Gtk.ScrolledWindow();
scroll.set_vexpand(true);
//------------------------------------------
var single_selection = new Gtk.SingleSelection(MW.list_all_poets);
single_selection.set_autoselect(false);
//------------------------------------------
var factory = new Gtk.SignalListItemFactory ();
var gridview = new Gtk.GridView(single_selection, factory);
factory.setup.connect(this.factory_setup);
factory.bind.connect(this.factory_bind);
//------------------------------------------
scroll.set_child(gridview);
//-----------------------------------------;
search_entry = new Gtk.SearchEntry ();
sfilter = new Gtk.StringFilter (new Gtk.PropertyExpression (typeof (ItemPoets), null, "name")) ;
sfilter.set_match_mode (Gtk.StringFilterMatchMode.PREFIX);
sfilter.set_ignore_case(true);
search_entry.changed.connect(on_change_text_entry_search);
//-----------------------------------------
this.append (search_entry);
this.append (scroll);
}
private void on_change_text_entry_search () {
string text = search_entry.get_text ();
sfilter.set_search (text);
}
private void factory_setup (SignalListItemFactory f, Object litem) {
var listitem = litem as Gtk.ListItem;
var box = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
var image = new Gtk.Image ();
image.set_pixel_size (180);
box.append (image);
var label = new Gtk.Label ("");
label.set_justify(Gtk.Justification.CENTER);
label.set_wrap (true);
label.set_natural_wrap_mode(Gtk.NaturalWrapMode.WORD);
label.set_width_chars (20);
// label.set_ellipsize(Pango.EllipsizeMode.END);
label.set_size_request (250, -1);
box.append (label);
listitem.set_child (box);
}
private void factory_bind(SignalListItemFactory f, Object litem) {
var listitem = litem as Gtk.ListItem;
var item = listitem.get_item () as ItemPoets;
var box = listitem.get_child ();
var image = box.get_first_child () as Gtk.Image;
var label = box.get_last_child () as Gtk.Label;
var name = item.name;
label.set_label (name);
image.set_from_icon_name ("poet1");
}
}
Search does not work for me via filtering
I expected this method to do the job
sfilter.set_search (text);
Is there anyone who can help me and I would like to thank them very much