[gnome-shell/eos3.8: 108/255] Introduce custom app icon positions



commit 6f5c8ad16d79ddf9ee9dff1ac11b29eaeafe9d80
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Tue Oct 1 20:48:47 2019 -0300

    Introduce custom app icon positions
    
    This change allows dragging and dropping icon around
    the app grid, including inside folders.
    
    https://phabricator.endlessm.com/T17661
    https://phabricator.endlessm.com/T18012

 js/ui/appDisplay.js | 107 +++++++++++++++++++++++++++++++++++++---------------
 js/ui/iconGrid.js   |   4 +-
 2 files changed, 79 insertions(+), 32 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index 640fba53a0..e4039b2889 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -158,6 +158,7 @@ var BaseAppView = GObject.registerClass({
             this._grid = new IconGrid.PaginatedIconGrid(gridParams);
         else
             this._grid = new IconGrid.IconGrid(gridParams);
+        this._grid._delegate = this;
 
         this._grid.connect('child-focused', (grid, actor) => {
             this._childFocused(actor);
@@ -326,6 +327,54 @@ var BaseAppView = GObject.registerClass({
         throw new GObject.NotImplementedError('adaptToSize in %s'.format(this.constructor.name));
     }
 
+    _canAccept(source) {
+        if (!(source instanceof AppIcon))
+            return false;
+
+        return true;
+    }
+
+    handleDragOver(source, _actor, x, y) {
+        if (!this._canAccept(source)) {
+            this._grid.removeNudges();
+            return DND.DragMotionResult.NO_DROP;
+        }
+
+        // Ask grid can we drop here
+        let [index, dragLocation] = this.canDropAt(x, y);
+
+        let onIcon = dragLocation == IconGrid.DragLocation.ON_ICON;
+        let sourceIndex = this._orderedItems.filter(c => c.visible).indexOf(source);
+        let onItself = sourceIndex !== -1
+            && (sourceIndex === index || sourceIndex === index - 1);
+        let isNewPosition = dragLocation !== this._lastDragLocation
+            || (!onIcon && index !== this._lastIndex);
+
+        if (isNewPosition || onItself)
+            this._grid.removeNudges();
+
+        if (!onItself)
+            this._grid.nudgeItemsAtIndex(index, dragLocation);
+
+        this._lastDragLocation = dragLocation;
+        this._lastIndex = index;
+
+        return DND.DragMotionResult.CONTINUE;
+    }
+
+    acceptDrop(source, _actor, x, y) {
+        this._grid.removeNudges();
+
+        if (!this._canAccept(source))
+            return false;
+
+        let [index] = this.canDropAt(x, y);
+
+        this.moveItem(source, index);
+
+        return true;
+    }
+
     get gridActor() {
         return this._grid;
     }
@@ -368,7 +417,6 @@ class AppDisplay extends BaseAppView {
             reactive: true,
         });
         this.add_actor(this._scrollView);
-        this._grid._delegate = this;
 
         this._scrollView.set_policy(St.PolicyType.NEVER,
                                     St.PolicyType.EXTERNAL);
@@ -826,8 +874,10 @@ class AppDisplay extends BaseAppView {
         let gridBottom = gridY + gridHeight;
 
         // Already animating
-        if (this._adjustment.get_transition('value') !== null)
+        if (this._adjustment.get_transition('value') !== null) {
+            this._grid.removeNudges();
             return;
+        }
 
         // Within the grid boundaries
         if (dragEvent.y > gridY && dragEvent.y < gridBottom) {
@@ -835,6 +885,7 @@ class AppDisplay extends BaseAppView {
             if (Math.abs(this._lastOvershootY - dragEvent.y) > OVERSHOOT_THRESHOLD)
                 this._resetOvershoot();
 
+            this._grid.removeNudges();
             return;
         }
 
@@ -889,10 +940,14 @@ class AppDisplay extends BaseAppView {
         if (this._grid.contains(appIcon))
             this._handleDragOvershoot(dragEvent);
 
+        if (!this._grid.contains(dragEvent.targetActor))
+            this._grid.removeNudges();
+
         return DND.DragMotionResult.CONTINUE;
     }
 
     _onDragEnd() {
+        this._grid.removeNudges();
         if (this._dragMonitor) {
             DND.removeDragMonitor(this._dragMonitor);
             this._dragMonitor = null;
@@ -902,42 +957,23 @@ class AppDisplay extends BaseAppView {
         this._resetOvershoot();
     }
 
-    _canAccept(source) {
-        if (!(source instanceof AppIcon))
-            return false;
-
-        let view = _getViewFromIcon(source);
-        if (!(view instanceof FolderView))
+    acceptDrop(source, actor, x, y) {
+        if (!super.acceptDrop(source, actor, x, y))
             return false;
 
-        return true;
-    }
-
-    handleDragOver(source) {
-        if (!this._canAccept(source))
-            return DND.DragMotionResult.NO_DROP;
-
-        return DND.DragMotionResult.MOVE_DROP;
-    }
-
-    acceptDrop(source) {
-        if (!this._canAccept(source))
-            return false;
-
-        this._iconGridLayout.appendIcon(
-            source.app.id, IconGridLayout.DESKTOP_GRID_ID);
-
         if (this._currentDialog)
             this._currentDialog.popdown();
 
         return true;
     }
 
-    createFolder(apps) {
+    createFolder(apps, iconAtPosition) {
         let appItems = apps.map(id => this._items.get(id).app);
         let folderName = _findBestFolderName(appItems);
 
-        let newFolderId = this._iconGridLayout.addFolder(folderName);
+        let newFolderId =
+            this._iconGridLayout.addFolder(folderName, iconAtPosition);
+
         if (!newFolderId)
             return false;
 
@@ -1316,6 +1352,11 @@ class ViewIcon extends St.Button {
         });
     }
 
+    _betweenLeeways(x, y) {
+        return x >= IconGrid.LEFT_DIVIDER_LEEWAY &&
+               x <= this.width - IconGrid.RIGHT_DIVIDER_LEEWAY;
+    }
+
     _onLabelUpdate() {
         // Do nothing by default
     }
@@ -1474,10 +1515,13 @@ var FolderIcon = GObject.registerClass({
         return true;
     }
 
-    handleDragOver(source) {
+    handleDragOver(source, _actor, x, y) {
         if (!this._canAccept(source))
             return DND.DragMotionResult.NO_DROP;
 
+        if (!this._betweenLeeways(x, y))
+            return DND.DragMotionResult.CONTINUE;
+
         return DND.DragMotionResult.MOVE_DROP;
     }
 
@@ -2209,13 +2253,16 @@ var AppIcon = GObject.registerClass({
         }
     }
 
-    handleDragOver(source) {
+    handleDragOver(source, _actor, x, y) {
         if (source == this)
             return DND.DragMotionResult.NO_DROP;
 
         if (!this._canAccept(source))
             return DND.DragMotionResult.CONTINUE;
 
+        if (!this._betweenLeeways(x, y))
+            return DND.DragMotionResult.CONTINUE;
+
         return DND.DragMotionResult.MOVE_DROP;
     }
 
@@ -2228,7 +2275,7 @@ var AppIcon = GObject.registerClass({
         let view = _getViewFromIcon(this);
         let apps = [this.id, source.id];
 
-        return view.createFolder(apps);
+        return view.createFolder(apps, this.id);
     }
 });
 
diff --git a/js/ui/iconGrid.js b/js/ui/iconGrid.js
index 1f9aa1d4f8..0dd9ceb95d 100644
--- a/js/ui/iconGrid.js
+++ b/js/ui/iconGrid.js
@@ -26,8 +26,8 @@ var APPICON_ANIMATION_OUT_TIME = 250;
 
 const ICON_POSITION_DELAY = 25;
 
-const LEFT_DIVIDER_LEEWAY = 30;
-const RIGHT_DIVIDER_LEEWAY = 30;
+var LEFT_DIVIDER_LEEWAY = 30;
+var RIGHT_DIVIDER_LEEWAY = 30;
 
 const NUDGE_ANIMATION_TYPE = Clutter.AnimationMode.EASE_OUT_ELASTIC;
 const NUDGE_DURATION = 800;


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