[gnome-shell/gbsneto/icon-grid-part1: 2/4] allView, folderView: Only add icons once



commit 334857a8fbc8eaa2964d7ea6065816a602e95927
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Tue Jul 30 12:15:51 2019 -0300

    allView, folderView: Only add icons once
    
    FolderView and AllView currently check if the item is
    present in the BaseAppView._items map, in order to avoid
    adding the same icon multiple times.
    
    Now that BaseAppView._loadApps() has a different role --
    it returns a list with all app icons, and BaseAppView
    diffs with the current list of app icons -- checking the
    BaseAppView._items map is wrong.
    
    Make sure there are no duplicated items in the temporary
    array returned by all _loadApps() implementations. Remove
    the now unused BaseAppView.hasItem() method.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/645

 js/ui/appDisplay.js | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index d23f0b961..fb56f16c7 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -147,15 +147,8 @@ class BaseAppView {
         return this._allItems;
     }
 
-    hasItem(id) {
-        return this._items[id] !== undefined;
-    }
-
     addItem(icon) {
         let id = icon.id;
-        if (this.hasItem(id))
-            throw new Error(`icon with id ${id} already added to view`);
-
         this._allItems.push(icon);
         this._items[id] = icon;
     }
@@ -392,12 +385,13 @@ var AllView = class AllView extends BaseAppView {
 
         let folders = this._folderSettings.get_strv('folder-children');
         folders.forEach(id => {
-            if (this.hasItem(id))
-                return;
             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));
+            let icon = this._items[id];
+            if (!icon) {
+                icon = new FolderIcon(id, path, this);
+                icon.connect('name-changed', this._itemNameChanged.bind(this));
+                icon.connect('apps-changed', this._refilterApps.bind(this));
+            }
             newApps.push(icon);
             this.folderIcons.push(icon);
         });
@@ -1145,9 +1139,6 @@ var FolderView = class FolderView extends BaseAppView {
         let excludedApps = this._folder.get_strv('excluded-apps');
         let appSys = Shell.AppSystem.get_default();
         let addAppId = appId => {
-            if (this.hasItem(appId))
-                 return;
-
             if (excludedApps.includes(appId))
                 return;
 
@@ -1158,6 +1149,9 @@ var FolderView = class FolderView extends BaseAppView {
             if (!app.get_app_info().should_show())
                 return;
 
+            if (apps.some(appIcon => appIcon.id == appId))
+                return;
+
             let icon = new AppIcon(app);
             apps.push(icon);
         };


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