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



commit ec77f52786a6131bb466d230760a02da5c2c9a9e
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/645

 js/ui/appDisplay.js | 83 ++++++++++++++++++++++++++++-------------------------
 1 file changed, 44 insertions(+), 39 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index a027dc86b..0cc3d9faa 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -1020,11 +1020,13 @@ var AppSearchProvider = class AppSearchProvider {
 };
 
 var FolderView = class FolderView extends BaseAppView {
-    constructor() {
+    constructor(folder, parentView) {
         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._parentView = parentView;
 
         this.actor = new St.ScrollView({ overlay_scrollbars: true });
         this.actor.set_policy(St.PolicyType.NEVER, St.PolicyType.AUTOMATIC);
@@ -1035,6 +1037,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) {
@@ -1127,6 +1132,43 @@ var FolderView = class FolderView extends BaseAppView {
     setPaddingOffsets(offset) {
         this._offsetForEachSide = offset;
     }
+
+    _loadApps() {
+        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;
+
+            let app = appSys.lookup_app(appId);
+            if (!app)
+                return;
+
+            if (!app.get_app_info().should_show())
+                return;
+
+            let icon = new AppIcon(app);
+            this.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.loadGrid();
+    }
 };
 
 var FolderIcon = class FolderIcon {
@@ -1154,7 +1196,7 @@ var FolderIcon = class FolderIcon {
         this.actor.set_child(this.icon);
         this.actor.label_actor = this.icon.label;
 
-        this.view = new FolderView();
+        this.view = new FolderView(this._folder, parentView);
 
         this.actor.connect('clicked', this.open.bind(this));
         this.actor.connect('destroy', this.onDestroy.bind(this));
@@ -1201,44 +1243,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 (this.view.hasItem(appId))
-                return;
-
-            if (excludedApps.includes(appId))
-                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.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.emit('apps-changed');
     }
 


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