remote-search: apply sort-order from GSettings
Sort providers according to the GSettings state, and make sure to reload them as soon as the sort order changes. https://bugzilla.gnome.org/show_bug.cgi?id=687491
This commit is contained in:
parent
38c8569d16
commit
cf363171aa
@ -116,6 +116,46 @@ function remoteProvidersDirLoaded(loadState) {
|
|||||||
if (loadState.numLoading > 0)
|
if (loadState.numLoading > 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
let searchSettings = new Gio.Settings({ schema: Search.SEARCH_PROVIDERS_SCHEMA });
|
||||||
|
let sortOrder = searchSettings.get_strv('sort-order');
|
||||||
|
let numSorted = sortOrder.length;
|
||||||
|
|
||||||
|
loadState.loadedProviders.sort(
|
||||||
|
function(providerA, providerB) {
|
||||||
|
let idxA, idxB;
|
||||||
|
let appIdA, appIdB;
|
||||||
|
|
||||||
|
appIdA = providerA.appInfo.get_id();
|
||||||
|
appIdB = providerB.appInfo.get_id();
|
||||||
|
|
||||||
|
idxA = sortOrder.indexOf(appIdA);
|
||||||
|
idxB = sortOrder.indexOf(appIdB);
|
||||||
|
|
||||||
|
// if no provider is found in the order, use alphabetical order
|
||||||
|
if ((idxA == -1) && (idxB == -1))
|
||||||
|
return GLib.utf8_collate(providerA.title, providerB.title);
|
||||||
|
|
||||||
|
if (numSorted > 1) {
|
||||||
|
// if providerA is the last, it goes after everything
|
||||||
|
if ((idxA + 1) == numSorted)
|
||||||
|
return 1;
|
||||||
|
// if providerB is the last, it goes after everything
|
||||||
|
else if ((idxB + 1) == numSorted)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if providerA isn't found, it's sorted after providerB
|
||||||
|
if (idxA == -1)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
// if providerB isn't found, it's sorted after providerA
|
||||||
|
if (idxB == -1)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
// finally, if both providers are found, return their order in the list
|
||||||
|
return (idxA - idxB);
|
||||||
|
});
|
||||||
|
|
||||||
loadState.loadedProviders.forEach(
|
loadState.loadedProviders.forEach(
|
||||||
function(provider) {
|
function(provider) {
|
||||||
loadState.addProviderCallback(provider);
|
loadState.addProviderCallback(provider);
|
||||||
|
@ -96,6 +96,7 @@ const ViewSelector = new Lang.Class({
|
|||||||
|
|
||||||
this._searchSettings = new Gio.Settings({ schema: Search.SEARCH_PROVIDERS_SCHEMA });
|
this._searchSettings = new Gio.Settings({ schema: Search.SEARCH_PROVIDERS_SCHEMA });
|
||||||
this._searchSettings.connect('changed::disabled', Lang.bind(this, this._reloadRemoteProviders));
|
this._searchSettings.connect('changed::disabled', Lang.bind(this, this._reloadRemoteProviders));
|
||||||
|
this._searchSettings.connect('changed::sort-order', Lang.bind(this, this._reloadRemoteProviders));
|
||||||
|
|
||||||
// Default search providers
|
// Default search providers
|
||||||
// Wanda comes obviously first
|
// Wanda comes obviously first
|
||||||
|
Loading…
Reference in New Issue
Block a user