[gnome-maps/wip/mlundblad/maps-uri: 1/6] placeEntry: Expose updateResults method




commit a76fa35a9390d41541b6c711f0c57d5afa87512f
Author: Marcus Lundblad <ml update uu se>
Date:   Mon Oct 25 22:40:18 2021 +0200

    placeEntry: Expose updateResults method
    
    Remove leading underscore, marking the
    updateResults method as intented to be
    used from outside the instance.
    Also allow to specify whether to
    show mathcing contacts and recent
    routes in the results.

 src/placeEntry.js | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)
---
diff --git a/src/placeEntry.js b/src/placeEntry.js
index 732d3f0f..5bbfd348 100644
--- a/src/placeEntry.js
+++ b/src/placeEntry.js
@@ -137,7 +137,7 @@ var PlaceEntry = GObject.registerClass({
             let cachedResults = this._cache[this.text];
 
             if (cachedResults) {
-                this._updateResults(cachedResults);
+                this.updateResults(cachedResults, this.text, true);
             } else {
                 // if no previous search has been performed, show spinner
                 if (!this._previousSearch ||
@@ -279,7 +279,7 @@ var PlaceEntry = GObject.registerClass({
                 this.place = null;
                 this._popover.showError();
             } else {
-                this._updateResults(places);
+                this.updateResults(places, this.text, true);
 
                 // cache results for later
                 this._cache[this._previousSearch] = places;
@@ -291,7 +291,14 @@ var PlaceEntry = GObject.registerClass({
         });
     }
 
-    _updateResults(places) {
+    /**
+     * Update results popover
+     * places array of places from search result
+     * searchText original search string to highlight in results
+     * includeContactsAndRoute whether to include contacts and recent routes
+     *                         among results
+     */
+    updateResults(places, searchText, includeContactsAndRoutes) {
         if (!places) {
                 this.place = null;
                 this._popover.showNoResult();
@@ -301,13 +308,15 @@ var PlaceEntry = GObject.registerClass({
         let completedPlaces = [];
 
 
-        this._filter.refilter();
-        this._filter.foreach((model, path, iter) => {
-            let place = model.get_value(iter, PlaceStore.Columns.PLACE);
-            let type = model.get_value(iter, PlaceStore.Columns.TYPE);
+        if (includeContactsAndRoutes) {
+            this._filter.refilter();
+            this._filter.foreach((model, path, iter) => {
+                let place = model.get_value(iter, PlaceStore.Columns.PLACE);
+                let type = model.get_value(iter, PlaceStore.Columns.TYPE);
 
-            completedPlaces.push({ place: place, type: type });
-        });
+                completedPlaces.push({ place: place, type: type });
+            });
+        }
 
         let placeStore = Application.placeStore;
 
@@ -324,7 +333,7 @@ var PlaceEntry = GObject.registerClass({
             completedPlaces.push({ place: place, type: type });
         });
 
-        this._popover.updateResult(completedPlaces, this.text);
+        this._popover.updateResult(completedPlaces, searchText);
         this._popover.showResult();
     }
 });


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