[gnome-shell/gbsneto/icon-grid-dnd: 8/10] baseViewIcon: Allow creating icons that are not drop targets



commit 400a1b3a0a7f546036222047c429229e328af3cf
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Fri Jul 5 16:25:21 2019 -0300

    baseViewIcon: Allow creating icons that are not drop targets
    
    Places like the Dash and search results have icons that aren't valid
    drop targets, in the same way that their grids aren't valid as well.
    
    Add a new 'isDropTarget' parameter to BaseViewIcon and prevent DnD
    when it is true.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/603

 js/ui/appDisplay.js | 25 +++++++++++++++++++------
 js/ui/dash.js       |  3 ++-
 2 files changed, 21 insertions(+), 7 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index 7fc09935e..b79579f6c 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -1235,10 +1235,12 @@ var AppSearchProvider = class AppSearchProvider {
     }
 
     createResultObject(resultMeta) {
-        if (resultMeta.id.endsWith('.desktop'))
-            return new AppIcon(this._appSys.lookup_app(resultMeta['id']), null);
-        else
+        if (resultMeta.id.endsWith('.desktop')) {
+            return new AppIcon(this._appSys.lookup_app(resultMeta['id']), null,
+                                                       { isDropTarget: false });
+        } else {
             return new SystemActionIcon(this, resultMeta);
+        }
     }
 };
 
@@ -1471,10 +1473,12 @@ var BaseViewIcon = class BaseViewIcon {
 
         // Get the isDraggable property without passing it on to the BaseIcon:
         params = Params.parse(params, { isDraggable: true,
-                                        hideWhileDragging: false }, true);
+                                        hideWhileDragging: false,
+                                        isDropTarget: true }, true);
         let isDraggable = params['isDraggable'];
         let hideWhileDragging = params['hideWhileDragging'];
 
+        this._isDropTarget = params.isDropTarget;
         this._hasDndHover = false;
 
         if (isDraggable) {
@@ -1497,8 +1501,10 @@ var BaseViewIcon = class BaseViewIcon {
             });
         }
 
-        Main.overview.connect('item-drag-begin', this._onDragBegin.bind(this));
-        Main.overview.connect('item-drag-end', this._onDragEnd.bind(this));
+        if (this._isDropTarget) {
+            Main.overview.connect('item-drag-begin', this._onDragBegin.bind(this));
+            Main.overview.connect('item-drag-end', this._onDragEnd.bind(this));
+        }
 
         this.actor.connect('destroy', this._onDestroy.bind(this));
     }
@@ -1557,6 +1563,9 @@ var BaseViewIcon = class BaseViewIcon {
     }
 
     handleDragOver(source, actor, x, y, time) {
+        if (!this._isDropTarget)
+            return DND.DragMotionResult.NO_DROP;
+
         if (!this._canDropAt(source))
             return DND.DragMotionResult.NO_DROP;
 
@@ -1568,6 +1577,9 @@ var BaseViewIcon = class BaseViewIcon {
 
         this._setHoveringByDnd(false);
 
+        if (!this._isDropTarget)
+            return false;
+
         if (!this._canDropAt(source))
             false;
 
@@ -2058,6 +2070,7 @@ var AppIcon = class AppIcon extends BaseViewIcon {
         this._scaleInId = 0;
 
         delete iconParams['isDraggable'];
+        delete iconParams['isDropTarget'];
         delete iconParams['hideWhileDragging'];
 
         iconParams['createIcon'] = this._createIcon.bind(this);
diff --git a/js/ui/dash.js b/js/ui/dash.js
index b7a1d33e6..76479e947 100644
--- a/js/ui/dash.js
+++ b/js/ui/dash.js
@@ -476,7 +476,8 @@ var Dash = class Dash {
     _createAppItem(app) {
         let appIcon = new AppDisplay.AppIcon(app, null,
                                              { setSizeManually: true,
-                                               showLabel: false });
+                                               showLabel: false,
+                                               isDropTarget: false });
         if (appIcon._draggable) {
             appIcon._draggable.connect('drag-begin',
                                        () => {


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