search: Replace getResultMeta() with getResultMetas()
Save some function calls by fetching all search results we want to display for a provider at once, rather than one result at a time. https://bugzilla.gnome.org/show_bug.cgi?id=663125
This commit is contained in:
parent
0fbdd0b67f
commit
53d9ea7a2c
@ -312,13 +312,18 @@ const AppSearchProvider = new Lang.Class({
|
|||||||
this._appSys = Shell.AppSystem.get_default();
|
this._appSys = Shell.AppSystem.get_default();
|
||||||
},
|
},
|
||||||
|
|
||||||
getResultMeta: function(app) {
|
getResultMetas: function(apps) {
|
||||||
return { 'id': app,
|
let metas = [];
|
||||||
'name': app.get_name(),
|
for (let i = 0; i < apps.length; i++) {
|
||||||
'createIcon': function(size) {
|
let app = apps[i];
|
||||||
return app.create_icon_texture(size);
|
metas.push({ 'id': app,
|
||||||
}
|
'name': app.get_name(),
|
||||||
};
|
'createIcon': function(size) {
|
||||||
|
return app.create_icon_texture(size);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return metas;
|
||||||
},
|
},
|
||||||
|
|
||||||
getInitialResultSet: function(terms) {
|
getInitialResultSet: function(terms) {
|
||||||
@ -369,13 +374,18 @@ const SettingsSearchProvider = new Lang.Class({
|
|||||||
this._gnomecc = this._appSys.lookup_app('gnome-control-center.desktop');
|
this._gnomecc = this._appSys.lookup_app('gnome-control-center.desktop');
|
||||||
},
|
},
|
||||||
|
|
||||||
getResultMeta: function(pref) {
|
getResultMetas: function(prefs) {
|
||||||
return { 'id': pref,
|
let metas = [];
|
||||||
'name': pref.get_name(),
|
for (let i = 0; i < prefs.length; i++) {
|
||||||
'createIcon': function(size) {
|
let pref = prefs[i];
|
||||||
return pref.create_icon_texture(size);
|
metas.push({ 'id': pref,
|
||||||
}
|
'name': pref.get_name(),
|
||||||
};
|
'createIcon': function(size) {
|
||||||
|
return pref.create_icon_texture(size);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return metas;
|
||||||
},
|
},
|
||||||
|
|
||||||
getInitialResultSet: function(terms) {
|
getInitialResultSet: function(terms) {
|
||||||
|
@ -149,14 +149,18 @@ const ContactSearchProvider = new Lang.Class({
|
|||||||
this._contactSys = Shell.ContactSystem.get_default();
|
this._contactSys = Shell.ContactSystem.get_default();
|
||||||
},
|
},
|
||||||
|
|
||||||
getResultMeta: function(id) {
|
getResultMetas: function(ids) {
|
||||||
let contact = new Contact(id);
|
let metas = [];
|
||||||
return { 'id': id,
|
for (let i = 0; i < ids.length; i++) {
|
||||||
'name': contact.alias,
|
let contact = new Contact(ids[i]);
|
||||||
'createIcon': function(size) {
|
metas.push({ 'id': ids[i],
|
||||||
return contact.createIcon(size);
|
'name': contact.alias,
|
||||||
}
|
'createIcon': function(size) {
|
||||||
};
|
return contact.createIcon(size);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return metas;
|
||||||
},
|
},
|
||||||
|
|
||||||
getInitialResultSet: function(terms) {
|
getInitialResultSet: function(terms) {
|
||||||
|
@ -14,16 +14,21 @@ const DocSearchProvider = new Lang.Class({
|
|||||||
this._docManager = DocInfo.getDocManager();
|
this._docManager = DocInfo.getDocManager();
|
||||||
},
|
},
|
||||||
|
|
||||||
getResultMeta: function(resultId) {
|
getResultMetas: function(resultIds) {
|
||||||
let docInfo = this._docManager.lookupByUri(resultId);
|
let metas = [];
|
||||||
if (!docInfo)
|
for (let i = 0; i < resultIds.length; i++) {
|
||||||
return null;
|
let docInfo = this._docManager.lookupByUri(resultIds[i]);
|
||||||
return { 'id': resultId,
|
if (!docInfo)
|
||||||
'name': docInfo.name,
|
metas.push(null);
|
||||||
'createIcon': function(size) {
|
else
|
||||||
return docInfo.createIcon(size);
|
metas.push({ 'id': resultIds[i],
|
||||||
}
|
'name': docInfo.name,
|
||||||
};
|
'createIcon': function(size) {
|
||||||
|
return docInfo.createIcon(size);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return metas;
|
||||||
},
|
},
|
||||||
|
|
||||||
activateResult: function(id, params) {
|
activateResult: function(id, params) {
|
||||||
|
@ -367,16 +367,21 @@ const PlaceSearchProvider = new Lang.Class({
|
|||||||
this.parent(_("PLACES & DEVICES"));
|
this.parent(_("PLACES & DEVICES"));
|
||||||
},
|
},
|
||||||
|
|
||||||
getResultMeta: function(resultId) {
|
getResultMetas: function(resultIds) {
|
||||||
let placeInfo = Main.placesManager.lookupPlaceById(resultId);
|
let metas = [];
|
||||||
if (!placeInfo)
|
for (let i = 0; i < resultIds.length; i++) {
|
||||||
return null;
|
let placeInfo = Main.placesManager.lookupPlaceById(resultIds[i]);
|
||||||
return { 'id': resultId,
|
if (!placeInfo)
|
||||||
'name': placeInfo.name,
|
metas.push(null);
|
||||||
'createIcon': function(size) {
|
else
|
||||||
return placeInfo.iconFactory(size);
|
metas.push({ 'id': resultIds[i],
|
||||||
}
|
'name': placeInfo.name,
|
||||||
};
|
'createIcon': function(size) {
|
||||||
|
return placeInfo.iconFactory(size);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return metas;
|
||||||
},
|
},
|
||||||
|
|
||||||
activateResult: function(id, params) {
|
activateResult: function(id, params) {
|
||||||
|
@ -190,14 +190,14 @@ const SearchProvider = new Lang.Class({
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getResultMeta:
|
* getResultMetas:
|
||||||
* @id: Result identifier string
|
* @ids: Result identifier strings
|
||||||
*
|
*
|
||||||
* Return an object with 'id', 'name', (both strings) and 'createIcon'
|
* Return an array of objects with 'id', 'name', (both strings) and
|
||||||
* (function(size) returning a Clutter.Texture) properties which describe
|
* 'createIcon' (function(size) returning a Clutter.Texture) properties
|
||||||
* the given search result.
|
* with the same number of members as @ids
|
||||||
*/
|
*/
|
||||||
getResultMeta: function(id) {
|
getResultMetas: function(ids) {
|
||||||
throw new Error('Not implemented');
|
throw new Error('Not implemented');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -126,10 +126,13 @@ const GridSearchResults = new Lang.Class({
|
|||||||
let canDisplay = this._grid.childrenInRow(this._width) * MAX_SEARCH_RESULTS_ROWS
|
let canDisplay = this._grid.childrenInRow(this._width) * MAX_SEARCH_RESULTS_ROWS
|
||||||
- this._grid.visibleItemsCount();
|
- this._grid.visibleItemsCount();
|
||||||
|
|
||||||
for (let i = Math.min(this._notDisplayedResult.length, canDisplay); i > 0; i--) {
|
let numResults = Math.min(this._notDisplayedResult.length, canDisplay);
|
||||||
let result = this._notDisplayedResult.shift();
|
if (numResults == 0)
|
||||||
let meta = this.provider.getResultMeta(result);
|
return;
|
||||||
let display = new SearchResult(this.provider, meta, this._terms);
|
let results = this._notDisplayedResult.splice(0, numResults);
|
||||||
|
let metas = this.provider.getResultMetas(results);
|
||||||
|
for (let i = 0; i < metas.length; i++) {
|
||||||
|
let display = new SearchResult(this.provider, metas[i], this._terms);
|
||||||
this._grid.addItem(display.actor);
|
this._grid.addItem(display.actor);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -168,22 +168,23 @@ const WandaSearchProvider = new Lang.Class({
|
|||||||
this.parent(_("Your favorite Easter Egg"));
|
this.parent(_("Your favorite Easter Egg"));
|
||||||
},
|
},
|
||||||
|
|
||||||
getResultMeta: function(fish) {
|
getResultMetas: function(fish) {
|
||||||
return { 'id': fish,
|
return [{ 'id': fish[0], // there may be many fish in the sea, but
|
||||||
'name': capitalize(fish),
|
// only one which speaks the truth!
|
||||||
'createIcon': function(iconSize) {
|
'name': capitalize(fish[0]),
|
||||||
// for DND only (maybe could be improved)
|
'createIcon': function(iconSize) {
|
||||||
// DON'T use St.Icon here, it crashes the shell
|
// for DND only (maybe could be improved)
|
||||||
// (dnd.js code assumes it can query the actor size
|
// DON'T use St.Icon here, it crashes the shell
|
||||||
// without parenting it, while StWidget accesses
|
// (dnd.js code assumes it can query the actor size
|
||||||
// StThemeNode in get_preferred_width/height, which
|
// without parenting it, while StWidget accesses
|
||||||
// triggers an assertion failure)
|
// StThemeNode in get_preferred_width/height, which
|
||||||
return St.TextureCache.get_default().load_icon_name(null,
|
// triggers an assertion failure)
|
||||||
'face-smile',
|
return St.TextureCache.get_default().load_icon_name(null,
|
||||||
St.IconType.FULLCOLOR,
|
'face-smile',
|
||||||
iconSize);
|
St.IconType.FULLCOLOR,
|
||||||
}
|
iconSize);
|
||||||
};
|
}
|
||||||
|
}];
|
||||||
},
|
},
|
||||||
|
|
||||||
getInitialResultSet: function(terms) {
|
getInitialResultSet: function(terms) {
|
||||||
|
Loading…
Reference in New Issue
Block a user