[gnome-shell/T27795: 51/138] Adapt AppSearchProvider to consider Endless's desktop grid



commit 7903db25bb625ff10eb527439f8e3e730e98a9e5
Author: Mario Sanchez Prada <mario endlessm com>
Date:   Sat May 27 03:02:07 2017 +0100

    Adapt AppSearchProvider to consider Endless's desktop grid
    
    We adapt this provided slightly so that search order properly put
    prioritized apps first, then apps that are on the desktop, and
    finally apps that are installed but not on the desktop.
    
    https://phabricator.endlessm.com/T4008
    https://phabricator.endlessm.com/T15929

 js/ui/appDisplay.js   | 21 +++++++++++++++++++++
 js/ui/remoteSearch.js | 20 +++++++++++++++++++-
 2 files changed, 40 insertions(+), 1 deletion(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index 6340b2a2d5..e8db9c59c3 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -10,6 +10,7 @@ const BoxPointer = imports.ui.boxpointer;
 const DND = imports.ui.dnd;
 const GrabHelper = imports.ui.grabHelper;
 const IconGrid = imports.ui.iconGrid;
+const IconGridLayout = imports.ui.iconGridLayout;
 const Main = imports.ui.main;
 const PageIndicators = imports.ui.pageIndicators;
 const PopupMenu = imports.ui.popupMenu;
@@ -48,6 +49,12 @@ const SwitcherooProxyInterface = loadInterfaceXML('net.hadess.SwitcherooControl'
 const SwitcherooProxy = Gio.DBusProxy.makeProxyWrapper(SwitcherooProxyInterface);
 let discreteGpuAvailable = false;
 
+// Endless-specific definitions below this point
+
+const EOS_LINK_PREFIX = 'eos-link-';
+
+const EOS_APP_CENTER_ID = 'org.gnome.Software.desktop';
+
 function _getCategories(info) {
     let categoriesStr = info.get_categories();
     if (!categoriesStr)
@@ -1192,6 +1199,13 @@ var AppSearchProvider = class AppSearchProvider {
         groups.forEach(group => {
             group = group.filter(appID => {
                 let app = Gio.DesktopAppInfo.new(appID);
+                let isLink = appID.startsWith(EOS_LINK_PREFIX);
+                let isOnDesktop = IconGridLayout.layout.hasIcon(appID);
+
+                // exclude links that are not part of the desktop grid
+                if (!(app && app.should_show() && !(isLink && !isOnDesktop)))
+                    return false;
+
                 return app && app.should_show();
             });
             results = results.concat(group.sort(
@@ -1201,6 +1215,13 @@ var AppSearchProvider = class AppSearchProvider {
 
         results = results.concat(this._systemActions.getMatchingActions(terms));
 
+        // resort to keep results on the desktop grid before the others
+        results = results.sort(function(a, b) {
+            let hasA = a === EOS_APP_CENTER_ID || IconGridLayout.layout.hasIcon(a);
+            let hasB = b === EOS_APP_CENTER_ID || IconGridLayout.layout.hasIcon(b);
+
+            return hasB - hasA;
+        });
         callback(results);
     }
 
diff --git a/js/ui/remoteSearch.js b/js/ui/remoteSearch.js
index b357aca74d..668ac7402e 100644
--- a/js/ui/remoteSearch.js
+++ b/js/ui/remoteSearch.js
@@ -4,8 +4,10 @@
 const { GdkPixbuf, Gio, GLib, Shell, St } = imports.gi;
 
 const FileUtils = imports.misc.fileUtils;
+const IconGridLayout = imports.ui.iconGridLayout;
 
 const KEY_FILE_GROUP = 'Shell Search Provider';
+const CONTROL_CENTER_DESKTOP_ID = 'gnome-control-center.desktop';
 
 const SearchProviderIface = `
 <node>
@@ -164,8 +166,24 @@ function loadRemoteSearchProviders(searchSettings, callback) {
         idxA = sortOrder.indexOf(appIdA);
         idxB = sortOrder.indexOf(appIdB);
 
-        // if no provider is found in the order, use alphabetical order
+        // none of the providers are in the list; check if they're on the desktop
         if ((idxA == -1) && (idxB == -1)) {
+            // We special case gnome-control-center, since we don't have it on
+            // the desktop but still want to see the results it provides
+            let hasA = (IconGridLayout.layout.hasIcon(appIdA) ||
+                        appIdA == CONTROL_CENTER_DESKTOP_ID);
+            let hasB = (IconGridLayout.layout.hasIcon(appIdB) ||
+                        appIdB == CONTROL_CENTER_DESKTOP_ID);
+
+            // if providerA is on the desktop, it's sorted before providerB
+            if (hasA && !hasB)
+                return -1;
+
+            // if providerB is on the desktop, it's sorted before providerA
+            if (hasB && !hasA)
+                return 1;
+
+            // fall back to alphabetical order
             let nameA = providerA.appInfo.get_name();
             let nameB = providerB.appInfo.get_name();
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]