[gnome-shell/gbsneto/icon-grid-dnd: 16/18] appDisplay: Add moveItem()



commit b80ae74e509ac6a90507218a35e8e9387238301f
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Tue Jul 2 17:41:15 2019 -0300

    appDisplay: Add moveItem()
    
    This is a handy function to implement changing an icon's position
    in the grid.
    
    WIP: better commit message
    
    https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/603

 js/ui/appDisplay.js | 18 ++++++++++++++++++
 js/ui/iconGrid.js   |  9 +++++++++
 2 files changed, 27 insertions(+)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index 27dce54e3..1e02fd448 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -160,6 +160,24 @@ class BaseAppView {
         this.emit('view-loaded');
     }
 
+    moveItem(item, newPosition) {
+        let itemIndex = this._allItems.indexOf(item);
+
+        if (itemIndex == -1) {
+            log('Trying to move item %s that is not in this app view'.format(item.id));
+            return;
+        }
+
+        if (newPosition > itemIndex)
+            newPosition -= 1;
+
+        // Remove from the old position
+        this._allItems.splice(itemIndex, 1);
+        this._allItems.splice(newPosition, 0, item);
+
+        this._grid.moveItem(item, newPosition);
+    }
+
     _selectAppInternal(id) {
         if (this._items[id])
             this._items[id].actor.navigate_focus(null, St.DirectionType.TAB_FORWARD, false);
diff --git a/js/ui/iconGrid.js b/js/ui/iconGrid.js
index 767e12b1b..bfb9750e2 100644
--- a/js/ui/iconGrid.js
+++ b/js/ui/iconGrid.js
@@ -709,6 +709,15 @@ var IconGrid = GObject.registerClass({
             this.add_actor(item.actor);
     }
 
+    moveItem(item, newPosition) {
+        if (!this.contains(item.actor)) {
+            log('Cannot move item not contained by the IconGrid');
+            return;
+        }
+
+        this.set_child_at_index(item.actor, newPosition);
+    }
+
     removeItem(item) {
         this.remove_child(item.actor);
     }


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