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
This commit is contained in:
Giovanni Campagna 2013-05-29 22:48:30 +02:00
parent cb7a2e8c6a
commit 002afda503
4 changed files with 19 additions and 1 deletions

View File

@ -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));
},

View File

@ -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;

View File

@ -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) {

View File

@ -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 ]);