[gnome-maps] Unify favoritesPopover/placeEntry filter code



commit 0f881a169a0953dad02a692af6de42dff9ec1a93
Author: Damián Nohales <damiannohales gmail com>
Date:   Mon Dec 22 11:00:51 2014 -0300

    Unify favoritesPopover/placeEntry filter code
    
    The code is moved to a method in Place class.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=741767

 src/favoritesPopover.js |    6 +-----
 src/place.js            |   18 ++++++++++++++++++
 src/placeEntry.js       |   20 ++++----------------
 3 files changed, 23 insertions(+), 21 deletions(-)
---
diff --git a/src/favoritesPopover.js b/src/favoritesPopover.js
index bbfd201..b7b09bc 100644
--- a/src/favoritesPopover.js
+++ b/src/favoritesPopover.js
@@ -88,11 +88,7 @@ const FavoritesPopover = new Lang.Class({
         }).bind(this));
 
         this._list.set_filter_func((function(row) {
-            let text = this._entry.text.toLowerCase();
-            let title = row.title.toLowerCase();
-            let length = text.length;
-
-            return (text === title.substring(0, text.length));
+            return row.place.match(this._entry.text);
         }).bind(this));
 
         this._updateList();
diff --git a/src/place.js b/src/place.js
index 76bf071..025faa0 100644
--- a/src/place.js
+++ b/src/place.js
@@ -23,6 +23,7 @@
 const _ = imports.gettext.gettext;
 
 const Geocode = imports.gi.GeocodeGlib;
+const GLib = imports.gi.GLib;
 const Lang = imports.lang;
 
 const Place = new Lang.Class({
@@ -176,6 +177,23 @@ const Place = new Lang.Class({
                  wiki: this.wiki,
                  wheelchair: this.wheelchair,
                  openingHours: this.openingHours };
+    },
+
+    match: function(searchString) {
+        let name = this.name;
+
+        searchString = GLib.utf8_normalize(searchString, -1, GLib.NormalizeMode.ALL);
+        if (searchString === null)
+            return false;
+
+        if (searchString.length === 0)
+            return true;
+
+        name = GLib.utf8_normalize(name, -1, GLib.NormalizeMode.ALL);
+        if (name === null)
+            return false;
+
+        return name.toLowerCase().search(searchString.toLowerCase()) !== -1;
     }
 });
 
diff --git a/src/placeEntry.js b/src/placeEntry.js
index 42e8d93..185b6d6 100644
--- a/src/placeEntry.js
+++ b/src/placeEntry.js
@@ -161,24 +161,12 @@ const PlaceEntry = new Lang.Class({
     },
 
     _completionVisibleFunc: function(model, iter) {
-        let name = model.get_value(iter, PlaceStore.Columns.NAME);
-        let key = this.text;
+        let place = model.get_value(iter, PlaceStore.Columns.PLACE);
 
-        if (key.length === 0)
-            return true;
-
-        if (name === null)
-            return false;
-
-        key = GLib.utf8_normalize(key, -1, GLib.NormalizeMode.ALL);
-        if (key === null)
+        if (place !== null)
+            return place.match(this.text);
+        else
             return false;
-
-        name = GLib.utf8_normalize(name, -1, GLib.NormalizeMode.ALL);
-        if (name === null)
-            return false;
-
-        return name.toLowerCase().search(key.toLowerCase()) !== -1;
     },
 
     _validateCoordinates: function(lat, lon) {


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