Xfce Wiki

Sub domains
 
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThaddaeus Tintenfisch <thad.fisch@gmail.com>2015-03-13 17:04:00 +0100
committerEric Koegel <eric.koegel@gmail.com>2015-03-26 06:19:12 +0300
commita6dd7d7171367f0e9af29152ccd1bfc0e6279b09 (patch)
treefe5c4449589f9c82e13c265c18d246401fe106c4
parentb0388120725ff485e5ae40fde4017aa8c7efb9cf (diff)
downloadxfdesktop-a6dd7d7171367f0e9af29152ccd1bfc0e6279b09.tar.gz
Preserve order when moving multiple icons Bug #11195
Signed-off-by: Eric Koegel <eric.koegel@gmail.com>
-rw-r--r--src/xfdesktop-icon-view.c44
1 files 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);
}