[gnome-shell/gbsneto/icon-grid-dnd-fixes: 2/14] iconGrid: Add moveItem




commit 8c3c53220b83aed548ad6e42d9ccbc5b1fa64b53
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Wed Sep 23 16:52:09 2020 -0300

    iconGrid: Add moveItem
    
    This new public API moves items without removing and readding
    them, which allows us to avoid some tricky behavior.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1447

 js/ui/iconGrid.js | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
---
diff --git a/js/ui/iconGrid.js b/js/ui/iconGrid.js
index 12a4aed9bd..a6a42b615a 100644
--- a/js/ui/iconGrid.js
+++ b/js/ui/iconGrid.js
@@ -847,6 +847,22 @@ var IconGridLayout = GObject.registerClass({
         this.addItem(item);
     }
 
+    /**
+     * moveItem:
+     * @param {Clutter.Actor} item: item to move
+     * @param {int} newPage: new page of the item
+     * @param {int} newPosition: new page of the item
+     *
+     * Moves @item to the grid. @item must be part of the grid.
+     */
+    moveItem(item, newPage, newPosition) {
+        if (!this._items.has(item))
+            throw new Error(`Item ${item} is not part of the IconGridLayout`);
+
+        this._removeItemData(item);
+        this._addItemToPage(item, newPage, newPosition);
+    }
+
     /**
      * removeItem:
      * @param {Clutter.Actor} item: item to remove from the grid
@@ -1422,6 +1438,19 @@ var IconGrid = GObject.registerClass({
         this.layout_manager.appendItem(item);
     }
 
+    /**
+     * moveItem:
+     * @param {Clutter.Actor} item: item to move
+     * @param {int} newPage: new page of the item
+     * @param {int} newPosition: new page of the item
+     *
+     * Moves @item to the grid. @item must be part of the grid.
+     */
+    moveItem(item, newPage, newPosition) {
+        this.layout_manager.moveItem(item, newPage, newPosition);
+        this.queue_relayout();
+    }
+
     /**
      * removeItem:
      * @param {Clutter.Actor} item: item to remove from the grid


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