[gnome-shell/gbsneto/icon-grid-dnd: 15/18] folderIcon: Move app icon loading to FolderView



commit e8fab4d6125f6d7df72287cc97611600aabd5aae
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sat Jun 29 12:58:26 2019 -0300

    folderIcon: Move app icon loading to FolderView
    
    Future patches will diff the old and new icons of views, in order to
    animate them when necessary (e.g. adding an app icon to a folder, or
    from a folder back to the app grid). In order to do that, all views
    must be streamlined in how they load app icons.
    
    Currently, FrequentView and AllView are already following the behavior
    expected by BaseAppView, but FolderView isn't. Its icons are loaded by
    FolderIcon, and FolderView doesn't implement BaseView._loadApps(),
    which makes it impossible to diff old and new apps.
    
    Move the app icon loading routine from FolderIcon to FolderView, by
    implementing the _loadApps() method.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/603

 js/ui/appDisplay.js | 76 ++++++++++++++++++++++++++++-------------------------
 1 file changed, 40 insertions(+), 36 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index ed7c00357..d985631b0 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -1093,11 +1093,12 @@ var AppSearchProvider = class AppSearchProvider {
 };
 
 var FolderView = class FolderView extends BaseAppView {
-    constructor(folderIcon) {
+    constructor(folderIcon, folder) {
         super(null, null);
         // If it not expand, the parent doesn't take into account its preferred_width when allocating
         // the second time it allocates, so we apply the "Standard hack for ClutterBinLayout"
         this._grid.x_expand = true;
+        this._folder = folder;
         this._folderIcon = folderIcon;
         this._grid._delegate = this;
 
@@ -1110,6 +1111,9 @@ var FolderView = class FolderView extends BaseAppView {
         let action = new Clutter.PanAction({ interpolate: true });
         action.connect('pan', this._onPan.bind(this));
         this.actor.add_action(action);
+
+        this._folder.connect('changed', this._redisplay.bind(this));
+        this._redisplay();
     }
 
     _childFocused(actor) {
@@ -1212,6 +1216,40 @@ var FolderView = class FolderView extends BaseAppView {
         return true;
     }
 
+    _loadApps() {
+        let excludedApps = this._folder.get_strv('excluded-apps');
+        let appSys = Shell.AppSystem.get_default();
+        let addAppId = appId => {
+            if (excludedApps.indexOf(appId) >= 0)
+                return;
+
+            let app = appSys.lookup_app(appId);
+            if (!app)
+                return;
+
+            if (!app.get_app_info().should_show())
+                return;
+
+            let icon = new AppIcon(app, this);
+            this.addItem(icon);
+        };
+
+        let folderApps = this._folder.get_strv('apps');
+        folderApps.forEach(addAppId);
+
+        let folderCategories = this._folder.get_strv('categories');
+        let appInfos = this._folderIcon._parentView.getAppInfos();
+        appInfos.forEach(appInfo => {
+            let appCategories = _getCategories(appInfo);
+            if (!_listsIntersect(folderCategories, appCategories))
+                return;
+
+            addAppId(appInfo.get_id());
+        });
+
+        this.loadGrid();
+    }
+
     get folderIcon() {
         return this._folderIcon;
     }
@@ -1240,7 +1278,7 @@ var FolderIcon = class FolderIcon {
         this.actor.set_child(this.icon);
         this.actor.label_actor = this.icon.label;
 
-        this.view = new FolderView(this);
+        this.view = new FolderView(this, this._folder);
 
         Main.overview.connect('item-drag-begin',
                               this._onDragBegin.bind(this));
@@ -1322,41 +1360,7 @@ var FolderIcon = class FolderIcon {
 
     _redisplay() {
         this._updateName();
-
-        this.view.removeAll();
-
-        let excludedApps = this._folder.get_strv('excluded-apps');
-        let appSys = Shell.AppSystem.get_default();
-        let addAppId = appId => {
-            if (excludedApps.indexOf(appId) >= 0)
-                return;
-
-            let app = appSys.lookup_app(appId);
-            if (!app)
-                return;
-
-            if (!app.get_app_info().should_show())
-                return;
-
-            let icon = new AppIcon(app, this.view);
-            this.view.addItem(icon);
-        };
-
-        let folderApps = this._folder.get_strv('apps');
-        folderApps.forEach(addAppId);
-
-        let folderCategories = this._folder.get_strv('categories');
-        let appInfos = this._parentView.getAppInfos();
-        appInfos.forEach(appInfo => {
-            let appCategories = _getCategories(appInfo);
-            if (!_listsIntersect(folderCategories, appCategories))
-                return;
-
-            addAppId(appInfo.get_id());
-        });
-
         this.actor.visible = this.view.getAllItems().length > 0;
-        this.view.loadGrid();
         this.icon.update();
         this.emit('apps-changed');
     }


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