[gnome-shell] SearchDisplay: handle certain result IDs specially



commit 002afda50328362c780ff8cd6e0c0cefec2b1771
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Wed May 29 22:48:30 2013 +0200

    SearchDisplay: handle certain result IDs specially
    
    Allow the prefix 'special:' applied to result IDs to mark results
    that should be always shown, even when they would overflow the
    maximum results cap. This will be used by epiphany for the special
    "Search the Web" result.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=707055

 js/ui/appDisplay.js    |    4 ++++
 js/ui/remoteSearch.js  |   10 ++++++++++
 js/ui/searchDisplay.js |    2 +-
 js/ui/wanda.js         |    4 ++++
 4 files changed, 19 insertions(+), 1 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index 52d7b70..f9c5859 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -877,6 +877,10 @@ const AppSearchProvider = new Lang.Class({
         callback(metas);
     },
 
+    filterResults: function(results, maxNumber) {
+        return results.slice(0, maxNumber);
+    },
+
     getInitialResultSet: function(terms) {
         this.searchSystem.setResults(this, this._appSys.initial_search(terms));
     },
diff --git a/js/ui/remoteSearch.js b/js/ui/remoteSearch.js
index b1f485e..f48a37f 100644
--- a/js/ui/remoteSearch.js
+++ b/js/ui/remoteSearch.js
@@ -207,6 +207,16 @@ const RemoteSearchProvider = new Lang.Class({
                              icon_size: size });
     },
 
+    filterResults: function(results, maxNumber) {
+        if (results.length <= maxNumber)
+            return results;
+
+        let regularResults = results.filter(function(r) { return !r.startsWith('special:'); });
+        let specialResults = results.filter(function(r) { return r.startsWith('special:'); });
+
+        return regularResults.slice(0, maxNumber).concat(specialResults.slice(0, maxNumber));
+    },
+
     _getResultsFinished: function(results, error) {
         if (error)
             return;
diff --git a/js/ui/searchDisplay.js b/js/ui/searchDisplay.js
index 69c79a1..8ae97ab 100644
--- a/js/ui/searchDisplay.js
+++ b/js/ui/searchDisplay.js
@@ -230,7 +230,7 @@ const SearchResultsBase = new Lang.Class({
             callback();
         } else {
             let maxResults = this._getMaxDisplayedResults();
-            let results = providerResults.slice(0, maxResults);
+            let results = this.provider.filterResults(providerResults, maxResults);
             let hasMoreResults = results.length < providerResults.length;
 
             this.provider.getResultMetas(results, Lang.bind(this, function(metas) {
diff --git a/js/ui/wanda.js b/js/ui/wanda.js
index 731a631..6ed2387 100644
--- a/js/ui/wanda.js
+++ b/js/ui/wanda.js
@@ -132,6 +132,10 @@ const WandaSearchProvider = new Lang.Class({
                   }]);
     },
 
+    filterResults: function(results) {
+        return results;
+    },
+
     getInitialResultSet: function(terms) {
         if (terms.join(' ') == MAGIC_FISH_KEY) {
             this.searchSystem.setResults(this, [ FISH_NAME ]);


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