[gnome-shell/gbsneto/icon-grid-dnd: 4/10] folderView: Allow moving to specific position



commit b0b9c71b56d6d35d491d2ec5d2d237c5289721cf
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Fri Jul 5 11:05:29 2019 -0300

    folderView: Allow moving to specific position
    
    As of now, the only way to add an app icon to a folder is
    by dragging it to the folder icon itself. Even though we
    allow opening the folder popup when hovering the icon,
    dropping an app icon there wouldn't work.
    
    Make the folder view add the app icon to it's GSettings
    key (which will trigger _redisplay() and will show the
    new icon) when dropping to a specific position.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/603

 js/ui/appDisplay.js | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index e04383aa2..e4bfa5c45 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -1343,19 +1343,36 @@ var FolderView = class FolderView extends BaseAppView {
         [x, y] = this._transformToGridCoordinates(x, y);
 
         let [index, dragLocation] = this.canDropAt(x, y);
-        let sourceIndex = this._allItems.indexOf(source);
         let success = index != -1;
 
         // AppIcon hides itself, show it again
         source.actor.show();
 
-        // When moving to a position forward, the index will be misadjusted by
-        // one, because the original actor is hidden. Adjust it back.
-        if (sourceIndex != -1 && index > sourceIndex)
-            index++;
+        if (success) {
+            // If we're dragging from another folder, remove from the old folder
+            if (source.parentView != this &&
+                (source instanceof AppIcon) &&
+                (source.parentView instanceof FolderView)) {
+                source.parentView._folderIcon.removeApp(source.app);
+            }
 
-        if (success)
-            this.moveItem(source, index);
+            // If the new app icon is not in this folder yet, add it; otherwise,
+            // just move the icon to the new position
+            let folderApps = this._folder.get_strv('apps');
+            if (!folderApps.includes(source.id)) {
+                folderApps.splice(index, 0, source.id);
+                this._folder.set_strv('apps', folderApps);
+            } else {
+                let sourceIndex = this._allItems.indexOf(source);
+
+                // When moving to a position forward, the index will be misadjusted by
+                // one, because the original actor is hidden. Adjust it back.
+                if (sourceIndex != -1 && index > sourceIndex)
+                    index++;
+
+                this.moveItem(source, index);
+            }
+        }
 
         this.removeNudges();
         return success;


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