[gnome-shell] remote-search: apply sort-order from GSettings
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] remote-search: apply sort-order from GSettings
- Date: Mon, 19 Nov 2012 17:02:57 +0000 (UTC)
commit cf363171aad032faa75cdbb69210cb75f8795d37
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Thu Nov 1 15:57:18 2012 -0400
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
js/ui/remoteSearch.js | 40 ++++++++++++++++++++++++++++++++++++++++
js/ui/viewSelector.js | 1 +
2 files changed, 41 insertions(+), 0 deletions(-)
---
diff --git a/js/ui/remoteSearch.js b/js/ui/remoteSearch.js
index 45fbda5..c9b25c6 100644
--- a/js/ui/remoteSearch.js
+++ b/js/ui/remoteSearch.js
@@ -116,6 +116,46 @@ function remoteProvidersDirLoaded(loadState) {
if (loadState.numLoading > 0)
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(
function(provider) {
loadState.addProviderCallback(provider);
diff --git a/js/ui/viewSelector.js b/js/ui/viewSelector.js
index d2edfcb..bee5bd7 100644
--- a/js/ui/viewSelector.js
+++ b/js/ui/viewSelector.js
@@ -96,6 +96,7 @@ const ViewSelector = new Lang.Class({
this._searchSettings = new Gio.Settings({ schema: Search.SEARCH_PROVIDERS_SCHEMA });
this._searchSettings.connect('changed::disabled', Lang.bind(this, this._reloadRemoteProviders));
+ this._searchSettings.connect('changed::sort-order', Lang.bind(this, this._reloadRemoteProviders));
// Default search providers
// Wanda comes obviously first
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]