From 58f77a19ed1ed66d9a1a08e7f83711dc5853e7b0 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Wed, 2 May 2012 15:45:37 -0400 Subject: [PATCH] search: Port all search providers over to the async API https://bugzilla.gnome.org/show_bug.cgi?id=675328 --- js/ui/appDisplay.js | 26 ++++++++++++----------- js/ui/contactDisplay.js | 13 ++++++------ js/ui/placeDisplay.js | 15 +++++++------- js/ui/wanda.js | 46 +++++++++++++++++++++-------------------- 4 files changed, 53 insertions(+), 47 deletions(-) diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js index 5b2c75f45..ada59597d 100644 --- a/js/ui/appDisplay.js +++ b/js/ui/appDisplay.js @@ -313,10 +313,11 @@ const AppSearchProvider = new Lang.Class({ _init: function() { this.parent(_("APPLICATIONS")); + this.async = true; this._appSys = Shell.AppSystem.get_default(); }, - getResultMetas: function(apps) { + getResultMetasAsync: function(apps, callback) { let metas = []; for (let i = 0; i < apps.length; i++) { let app = apps[i]; @@ -327,15 +328,15 @@ const AppSearchProvider = new Lang.Class({ } }); } - return metas; + callback(metas); }, - getInitialResultSet: function(terms) { - return this._appSys.initial_search(terms); + getInitialResultSetAsync: function(terms) { + this.searchSystem.pushResults(this, this._appSys.initial_search(terms)); }, - getSubsearchResultSet: function(previousResults, terms) { - return this._appSys.subsearch(previousResults, terms); + getSubsearchResultSetAsync: function(previousResults, terms) { + this.searchSystem.pushResults(this, this._appSys.subsearch(previousResults, terms)); }, activateResult: function(app, params) { @@ -374,11 +375,12 @@ const SettingsSearchProvider = new Lang.Class({ _init: function() { this.parent(_("SETTINGS")); + this.async = true; this._appSys = Shell.AppSystem.get_default(); this._gnomecc = this._appSys.lookup_app('gnome-control-center.desktop'); }, - getResultMetas: function(prefs) { + getResultMetasAsync: function(prefs, callback) { let metas = []; for (let i = 0; i < prefs.length; i++) { let pref = prefs[i]; @@ -389,15 +391,15 @@ const SettingsSearchProvider = new Lang.Class({ } }); } - return metas; + callback(metas); }, - getInitialResultSet: function(terms) { - return this._appSys.search_settings(terms); + getInitialResultSetAsync: function(terms) { + this.searchSystem.pushResults(this, this._appSys.search_settings(terms)); }, - getSubsearchResultSet: function(previousResults, terms) { - return this._appSys.search_settings(terms); + getSubsearchResultSetAsync: function(previousResults, terms) { + this.searchSystem.pushResults(this, this._appSys.search_settings(terms)); }, activateResult: function(pref, params) { diff --git a/js/ui/contactDisplay.js b/js/ui/contactDisplay.js index 20b4c10bc..5e0ae6092 100644 --- a/js/ui/contactDisplay.js +++ b/js/ui/contactDisplay.js @@ -151,10 +151,11 @@ const ContactSearchProvider = new Lang.Class({ _init: function() { this.parent(_("CONTACTS")); + this.async = true; this._contactSys = Shell.ContactSystem.get_default(); }, - getResultMetas: function(ids) { + getResultMetasAsync: function(ids, callback) { let metas = []; for (let i = 0; i < ids.length; i++) { let contact = new Contact(ids[i]); @@ -165,15 +166,15 @@ const ContactSearchProvider = new Lang.Class({ } }); } - return metas; + callback(metas); }, - getInitialResultSet: function(terms) { - return this._contactSys.initial_search(terms); + getInitialResultSetAsync: function(terms) { + this.searchSystem.pushResults(this, this._contactSys.initial_search(terms)); }, - getSubsearchResultSet: function(previousResults, terms) { - return this._contactSys.subsearch(previousResults, terms); + getSubsearchResultSetAsync: function(previousResults, terms) { + this.searchSystem.pushResults(this, this._contactSys.subsearch(previousResults, terms)); }, createResultActor: function(resultMeta, terms) { diff --git a/js/ui/placeDisplay.js b/js/ui/placeDisplay.js index ac8e4dbcb..7698eb152 100644 --- a/js/ui/placeDisplay.js +++ b/js/ui/placeDisplay.js @@ -365,10 +365,11 @@ const PlaceSearchProvider = new Lang.Class({ _init: function() { this.parent(_("PLACES & DEVICES")); + this.async = true; this.placesManager = new PlacesManager(); }, - getResultMetas: function(resultIds) { + getResultMetasAsync: function(resultIds, callback) { let metas = []; for (let i = 0; i < resultIds.length; i++) { let placeInfo = this.placesManager.lookupPlaceById(resultIds[i]); @@ -382,7 +383,7 @@ const PlaceSearchProvider = new Lang.Class({ } }); } - return metas; + callback(metas); }, activateResult: function(id, params) { @@ -413,18 +414,18 @@ const PlaceSearchProvider = new Lang.Class({ prefixResults.sort(Lang.bind(this, this._compareResultMeta)); substringResults.sort(Lang.bind(this, this._compareResultMeta)); - return prefixResults.concat(substringResults); + this.searchSystem.pushResults(this, prefixResults.concat(substringResults)); }, - getInitialResultSet: function(terms) { + getInitialResultSetAsync: function(terms) { let places = this.placesManager.getAllPlaces(); - return this._searchPlaces(places, terms); + this._searchPlaces(places, terms); }, - getSubsearchResultSet: function(previousResults, terms) { + getSubsearchResultSetAsync: function(previousResults, terms) { let places = previousResults.map(Lang.bind(this, function(id) { return this.placesManager.lookupPlaceById(id); })); - return this._searchPlaces(places, terms); + this._searchPlaces(places, terms); } }); diff --git a/js/ui/wanda.js b/js/ui/wanda.js index 6b63803e7..3c6a6dc2f 100644 --- a/js/ui/wanda.js +++ b/js/ui/wanda.js @@ -166,36 +166,38 @@ const WandaSearchProvider = new Lang.Class({ _init: function() { this.parent(_("Your favorite Easter Egg")); + this.async = true; }, - getResultMetas: function(fish) { - return [{ 'id': fish[0], // there may be many fish in the sea, but - // only one which speaks the truth! - 'name': capitalize(fish[0]), - 'createIcon': function(iconSize) { - // for DND only (maybe could be improved) - // DON'T use St.Icon here, it crashes the shell - // (dnd.js code assumes it can query the actor size - // without parenting it, while StWidget accesses - // StThemeNode in get_preferred_width/height, which - // triggers an assertion failure) - return St.TextureCache.get_default().load_icon_name(null, - 'face-smile', - St.IconType.FULLCOLOR, - iconSize); - } - }]; + getResultMetasAsync: function(fish, callback) { + callback([{ 'id': fish[0], // there may be many fish in the sea, but + // only one which speaks the truth! + 'name': capitalize(fish[0]), + 'createIcon': function(iconSize) { + // for DND only (maybe could be improved) + // DON'T use St.Icon here, it crashes the shell + // (dnd.js code assumes it can query the actor size + // without parenting it, while StWidget accesses + // StThemeNode in get_preferred_width/height, which + // triggers an assertion failure) + return St.TextureCache.get_default().load_icon_name(null, + 'face-smile', + St.IconType.FULLCOLOR, + iconSize); + } + }]); }, - getInitialResultSet: function(terms) { + getInitialResultSetAsync: function(terms) { if (terms.join(' ') == MAGIC_FISH_KEY) { - return [ FISH_NAME ]; + this.searchSystem.pushResults(this, [ FISH_NAME ]); + } else { + this.searchSystem.pushResults(this, []); } - return []; }, - getSubsearchResultSet: function(previousResults, terms) { - return this.getInitialResultSet(terms); + getSubsearchResultSetAsync: function(previousResults, terms) { + this.getInitialResultSetAsync(terms); }, activateResult: function(fish, params) {