[gnome-shell/gbsneto/custom-icon-positions: 57/72] appDisplay: Factor out item addition and removal methods



commit 1ca7f9ce0170c4c9c5c134bfa8cd8edb9fda33a1
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Tue May 26 10:58:17 2020 -0300

    appDisplay: Factor out item addition and removal methods
    
    It'll be useful later.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1284

 js/ui/appDisplay.js | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index 0999cbf75a..0f6bae9632 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -253,6 +253,27 @@ var BaseAppView = GObject.registerClass({
         });
     }
 
+    _addItem(item, page, position) {
+        let itemIndex = position;
+
+        for (let i = 0; i < page - 1; i++) {
+            const pageItems = this._grid.getItemsAtPage(i).filter(c => c.visible);
+            itemIndex += pageItems.length;
+        }
+
+        this._orderedItems.splice(itemIndex, 0, item);
+        this._items.set(item.id, item);
+        this._grid.addItem(item, position, page);
+    }
+
+    _removeItem(item) {
+        const iconIndex = this._orderedItems.indexOf(item);
+
+        this._orderedItems.splice(iconIndex, 1);
+        this._items.delete(item.id);
+        this._grid.removeItem(item);
+    }
+
     _redisplay() {
         let oldApps = this._orderedItems.slice();
         let oldAppIds = oldApps.map(icon => icon.id);
@@ -265,12 +286,8 @@ var BaseAppView = GObject.registerClass({
 
         // Remove old app icons
         removedApps.forEach(icon => {
-            let iconIndex = this._orderedItems.indexOf(icon);
-            let id = icon.id;
-
-            this._orderedItems.splice(iconIndex, 1);
+            this._removeItem(icon);
             icon.destroy();
-            this._items.delete(id);
         });
 
         // Add new app icons


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