[gnome-shell/gbsneto/icon-grid-dnd: 16/35] baseAppView: Only add and remove when necessary



commit f303676776770acc8fb3f3543ef3063ea782bed0
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Mon Jul 1 23:13:07 2019 -0300

    baseAppView: Only add and remove when necessary
    
    BaseAppView currently removes all icons, and readds them, every
    time the list of app icons needs to be redisplayed. In order to
    allow animating app icon positions in the future, however, we
    cannot destroy the actors of the app icons.
    
    Previous commits paved the way for us to do differential loading,
    i.e. add only the icons that were added, and remove only what was
    removed.
    
    Make the BaseAppView effectively implement differential loading.
    The BaseAppView.removeAll() method is removed, since we do not
    remove all icons anymore. BaseAppView._loadApps() now returns an
    array with the new apps, instead of putting them directly at the
    BaseAppView lists.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/603

 js/ui/appDisplay.js | 52 +++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 35 insertions(+), 17 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index ab70d73ed..2b7e21c24 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -116,15 +116,27 @@ class BaseAppView {
         // Nothing by default
     }
 
-    removeAll() {
-        this._grid.destroyAll();
-        this._items = {};
-        this._allItems = [];
-    }
-
     _redisplay() {
-        this.removeAll();
-        this._loadApps();
+        let oldApps = this._allItems.slice();
+        let oldAppIds = oldApps.map(icon => icon.id);
+
+        let newApps = this._loadApps();
+        let newAppIds = newApps.map(icon => icon.id);
+
+        let addedApps = newApps.filter(icon => !oldAppIds.includes(icon.id));
+        let removedApps = oldApps.filter(icon => !newAppIds.includes(icon.id));
+
+        // Remove old app icons
+        for (let icon of removedApps) {
+            this._grid.removeItem(icon);
+            this._allItems.splice(this._allItems.indexOf(icon), 1);
+            delete this._items[icon.id];
+        }
+
+        // Add new app icons
+        for (let app of addedApps)
+            this.addItem(app);
+
         this._loadGrid();
     }
 
@@ -340,11 +352,6 @@ var AllView = class AllView extends BaseAppView {
         this._nEventBlockerInhibits = 0;
     }
 
-    removeAll() {
-        this.folderIcons = [];
-        super.removeAll();
-    }
-
     _itemNameChanged(item) {
         // If an item's name changed, we can pluck it out of where it's
         // supposed to be and reinsert it where it's sorted.
@@ -386,6 +393,7 @@ var AllView = class AllView extends BaseAppView {
     }
 
     _loadApps() {
+        let newApps = [];
         this._appInfoList = Shell.AppSystem.get_default().get_installed().filter(appInfo => {
             try {
                 (appInfo.get_id()); // catch invalid file encodings
@@ -399,13 +407,15 @@ var AllView = class AllView extends BaseAppView {
 
         let appSys = Shell.AppSystem.get_default();
 
+        this.folderIcons = [];
+
         let folders = this._folderSettings.get_strv('folder-children');
         folders.forEach(id => {
             let path = this._folderSettings.path + 'folders/' + id + '/';
             let icon = new FolderIcon(id, path, this);
             icon.connect('name-changed', this._itemNameChanged.bind(this));
             icon.connect('apps-changed', this._refilterApps.bind(this));
-            this.addItem(icon);
+            newApps.push(icon);
             this.folderIcons.push(icon);
         });
 
@@ -422,8 +432,10 @@ var AllView = class AllView extends BaseAppView {
 
             let icon = new AppIcon(app, this,
                                    { isDraggable: favoritesWritable });
-            this.addItem(icon);
+            newApps.push(icon);
         });
+
+        return newApps;
     }
 
     _loadGrid() {
@@ -791,6 +803,7 @@ var FrequentView = class FrequentView extends BaseAppView {
     }
 
     _loadApps() {
+        let apps = [];
         let mostUsed = this._usage.get_most_used();
         let hasUsefulData = this.hasUsefulData();
         this._noFrequentAppsLabel.visible = !hasUsefulData;
@@ -810,8 +823,10 @@ var FrequentView = class FrequentView extends BaseAppView {
                 continue;
             let appIcon = new AppIcon(mostUsed[i], this,
                                       { isDraggable: favoritesWritable });
-            this.addItem(appIcon);
+            apps.push(appIcon);
         }
+
+        return apps;
     }
 
     // Called before allocation to calculate dynamic spacing
@@ -1228,6 +1243,7 @@ var FolderView = class FolderView extends BaseAppView {
     }
 
     _loadApps() {
+        let apps = [];
         let excludedApps = this._folder.get_strv('excluded-apps');
         let appSys = Shell.AppSystem.get_default();
         let addAppId = appId => {
@@ -1242,7 +1258,7 @@ var FolderView = class FolderView extends BaseAppView {
                 return;
 
             let icon = new AppIcon(app, this);
-            this.addItem(icon);
+            apps.push(icon);
         };
 
         let folderApps = this._folder.get_strv('apps');
@@ -1257,6 +1273,8 @@ var FolderView = class FolderView extends BaseAppView {
 
             addAppId(appInfo.get_id());
         });
+
+        return apps;
     }
 
     get folderIcon() {


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