[gnome-shell/gbsneto/icon-grid-part2: 45/48] allView: Remove icon from folder when dropping outside



commit c83f5dc2a1e61199fb8763b38c758be840e0a817
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sat Jun 29 01:26:08 2019 -0300

    allView: Remove icon from folder when dropping outside
    
    When dropping an app icon to outside the folder, remove the
    app from that folder. GNOME Shell is already smart enough
    to figure out the setting changes and update the icons.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/664

 js/ui/appDisplay.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index 454313804..41d319cea 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -240,6 +240,7 @@ var AllView = class AllView extends BaseAppView {
         this.actor = new St.Widget({ layout_manager: new Clutter.BinLayout(),
                                      x_expand: true, y_expand: true });
         this.actor.add_actor(this._scrollView);
+        this._grid._delegate = this;
 
         this._scrollView.set_policy(St.PolicyType.NEVER,
                                     St.PolicyType.EXTERNAL);
@@ -729,6 +730,42 @@ var AllView = class AllView extends BaseAppView {
         }
     }
 
+    _getViewFromIcon(icon) {
+        let view = icon.actor.get_parent()._delegate;
+        return view;
+    }
+
+    _canAccept(source) {
+        if (!(source instanceof AppIcon))
+            return false;
+
+        let view = this._getViewFromIcon(source);
+        if (!(view instanceof FolderView))
+            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;
+
+        let view = this._getViewFromIcon(source);
+        view.removeApp(source.app);
+
+        if (this._currentPopup)
+            this._currentPopup.popdown();
+
+        return true;
+    }
+
     inhibitEventBlocker() {
         this._nEventBlockerInhibits++;
         this._eventBlocker.visible = this._nEventBlockerInhibits == 0;
@@ -1106,6 +1143,7 @@ var FolderView = class FolderView extends BaseAppView {
         this._grid.x_expand = true;
         this._folder = folder;
         this._parentView = parentView;
+        this._grid._delegate = this;
 
         this.actor = new St.ScrollView({ overlay_scrollbars: true });
         this.actor.set_policy(St.PolicyType.NEVER, St.PolicyType.AUTOMATIC);
@@ -1249,6 +1287,19 @@ var FolderView = class FolderView extends BaseAppView {
 
         return apps;
     }
+
+    removeApp(app) {
+        let folderApps = this._folder.get_strv('apps');
+        let index = folderApps.indexOf(app.id);
+        if (index < 0)
+            return false;
+
+        folderApps.splice(index, 1);
+
+        this._folder.set_strv('apps', folderApps);
+
+        return true;
+    }
 };
 
 var FolderIcon = class FolderIcon {


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