[gnome-boxes] collection-filter: Add 'filter_func' prop



commit 0a7a1354ced3e6591d2acab0367ce7c9842a542a
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Mon Jun 29 08:01:49 2015 +0200

    collection-filter: Add 'filter_func' prop
    
    Add the 'filter_func' delegate allowing to customize a collection
    filter.
    
    This will be used to filter the visible elements of a collection with
    more precision and is needed to offer multiple ready-made searches.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=751710

 src/collection-view.vala |    3 +++
 src/collection.vala      |   19 +++++++++++++++++++
 2 files changed, 22 insertions(+), 0 deletions(-)
---
diff --git a/src/collection-view.vala b/src/collection-view.vala
index df34372..69be69c 100644
--- a/src/collection-view.vala
+++ b/src/collection-view.vala
@@ -61,6 +61,9 @@ private class Boxes.CollectionView: Gd.MainView, Boxes.UI {
         filter.notify["text"].connect (() => {
             model_filter.refilter ();
         });
+        filter.filter_func_changed.connect (() => {
+            model_filter.refilter ();
+        });
     }
 
     public void setup_ui (AppWindow window) {
diff --git a/src/collection.vala b/src/collection.vala
index a93ff24..b0351a0 100644
--- a/src/collection.vala
+++ b/src/collection.vala
@@ -56,6 +56,9 @@ private class Boxes.Collection: GLib.Object {
 }
 
 private class Boxes.CollectionFilter: GLib.Object {
+    // Need a signal cause delegate properties aren't real properties and hence are not notified.
+    public signal void filter_func_changed ();
+
     private string [] terms;
 
     private string _text;
@@ -69,16 +72,32 @@ private class Boxes.CollectionFilter: GLib.Object {
         }
     }
 
+    private unowned Boxes.CollectionFilterFunc _filter_func;
+    public unowned Boxes.CollectionFilterFunc filter_func {
+        get { return _filter_func; }
+        set {
+            _filter_func = value;
+            filter_func_changed ();
+        }
+        default = null;
+    }
+
     public bool filter (CollectionItem item) {
         var name = canonicalize_for_search (item.name);
         foreach (var term in terms) {
             if (! (term in name))
                 return false;
         }
+
+        if (filter_func != null)
+            return filter_func (item);
+
         return true;
     }
 }
 
+private delegate bool Boxes.CollectionFilterFunc (Boxes.CollectionItem item);
+
 private class Boxes.Category: GLib.Object {
     public enum Kind {
         USER,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]