[Xfce4-commits] [xfce/xfdesktop] 04/05: Preserve order when moving multiple icons (Bug #11195)

noreply at xfce.org noreply at xfce.org
Thu Mar 26 04:30:14 CET 2015


This is an automated email from the git hooks/post-receive script.

eric pushed a commit to branch master
in repository xfce/xfdesktop.

commit a6dd7d7171367f0e9af29152ccd1bfc0e6279b09
Author: Thaddaeus Tintenfisch <thad.fisch at gmail.com>
Date:   Fri Mar 13 17:04:00 2015 +0100

    Preserve order when moving multiple icons (Bug #11195)
    
    Signed-off-by: Eric Koegel <eric.koegel at gmail.com>
---
 src/xfdesktop-icon-view.c |   44 +++++++++++++++++++++++++++++++-------------
 1 file changed, 31 insertions(+), 13 deletions(-)

diff --git a/src/xfdesktop-icon-view.c b/src/xfdesktop-icon-view.c
index ae3a1a0..6ce5e8b 100644
--- a/src/xfdesktop-icon-view.c
+++ b/src/xfdesktop-icon-view.c
@@ -1576,6 +1576,32 @@ xfdesktop_icon_view_drag_motion(GtkWidget *widget,
     return TRUE;
 }
 
+static gint
+xfdesktop_icon_view_compare_icon_positions(gconstpointer *a,
+                                           gconstpointer *b)
+{
+    XfdesktopIcon *a_icon, *b_icon;
+    gint16 a_row, a_col, b_row, b_col;
+
+    a_icon = XFDESKTOP_ICON(a);
+    b_icon = XFDESKTOP_ICON(b);
+
+    if(!xfdesktop_icon_get_position(a_icon, &a_row, &a_col))
+        return 0;
+    if(!xfdesktop_icon_get_position(b_icon, &b_row, &b_col))
+        return 0;
+
+    if(a_col == b_col) {
+        if(a_row < b_row)
+            return -1;
+        else
+            return 1;
+    } else if(a_col < b_col)
+        return -1;
+    else
+        return 1;
+}
+
 static gboolean
 xfdesktop_icon_view_drag_drop(GtkWidget *widget,
                               GdkDragContext *context,
@@ -1655,22 +1681,15 @@ xfdesktop_icon_view_drag_drop(GtkWidget *widget,
                 xfdesktop_grid_set_position_free(icon_view, old_row, old_col);
         }
 
-        /* set new position */
-        xfdesktop_icon_set_position(icon, row, col);
-        xfdesktop_grid_unset_position_free(icon_view, icon);
-        
-        /* clear out old extents, if any */
-        /* FIXME: is this right? */
-        xfdesktop_icon_view_invalidate_icon(icon_view, icon, TRUE);
+        /* Preserve order when moving multiple icons */
+        icon_view->priv->selected_icons = g_list_sort(icon_view->priv->selected_icons,
+                                                      (GCompareFunc)xfdesktop_icon_view_compare_icon_positions);
 
         /* Now that we have moved the icon the user selected,
          * append all the other selected icons after it. */
         for(l = icon_view->priv->selected_icons; l; l = l->next) {
-            if(l->data == icon)
-                continue;
-
             /* Find the next available spot for an icon */
-            do {
+            while(!xfdesktop_grid_is_free_position(icon_view, row, col)) {
                 if(row + 1 >= icon_view->priv->nrows) {
                     if(col + 1 >= icon_view->priv->ncols)
                         col = 0;
@@ -1680,14 +1699,13 @@ xfdesktop_icon_view_drag_drop(GtkWidget *widget,
                 } else {
                     ++row;
                 }
-            } while(!xfdesktop_grid_is_free_position(icon_view, row, col));
+            }
 
             /* set new position */
             xfdesktop_icon_set_position(l->data, row, col);
             xfdesktop_grid_unset_position_free(icon_view, l->data);
 
             /* clear out old extents, if any */
-            /* FIXME: is this right? */
             xfdesktop_icon_view_invalidate_icon(icon_view, l->data, TRUE);
         }
         

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list