gulong acc_removed_handler;
HeaderViewStatus status;
+ GList *drag_begin_cached_selected_rows;
};
typedef struct _HeadersCountChangedHelper HeadersCountChangedHelper;
/* Drag and drop stuff */
static void
-drag_data_get_cb (GtkWidget *widget, GdkDragContext *context,
+drag_data_get_cb (GtkWidget *widget,
+ GdkDragContext *context,
GtkSelectionData *selection_data,
- guint info, guint time, gpointer data)
+ guint info,
+ guint time,
+ gpointer data)
{
- GtkTreeModel *model = NULL;
- GtkTreeIter iter;
- GtkTreePath *source_row = NULL;
-/* GtkTreeSelection *sel = NULL;*/
-
- source_row = get_selected_row (GTK_TREE_VIEW (widget), &model);
-
- if ((source_row == NULL) || (!gtk_tree_model_get_iter(model, &iter, source_row))) return;
+ ModestHeaderView *self = NULL;
+ ModestHeaderViewPrivate *priv = NULL;
- switch (info) {
- case MODEST_HEADER_ROW:
- gtk_tree_set_row_drag_data (selection_data, model, source_row);
- break;
- case MODEST_MSG: {
- TnyHeader *hdr = NULL;
- gtk_tree_model_get (model, &iter,
- TNY_GTK_HEADER_LIST_MODEL_INSTANCE_COLUMN, &hdr,
- -1);
- if (hdr) {
- g_object_unref (G_OBJECT(hdr));
- }
- break;
- }
- default:
- g_message ("%s: default switch case.", __FUNCTION__);
- }
+ self = MODEST_HEADER_VIEW (widget);
+ priv = MODEST_HEADER_VIEW_GET_PRIVATE(self);
+
+ /* Set the data. Do not use the current selection because it
+ could be different than the selection at the beginning of
+ the d&d */
+ modest_dnd_selection_data_set_paths (selection_data,
+ priv->drag_begin_cached_selected_rows);
+}
+
+/**
+ * We're caching the selected rows at the beginning because the
+ * selection could change between drag-begin and drag-data-get, for
+ * example if we have a set of rows already selected, and then we
+ * click in one of them (without SHIFT key pressed) and begin a drag,
+ * the selection at that moment contains all the selected lines, but
+ * after dropping the selection, the release event provokes that only
+ * the row used to begin the drag is selected, so at the end the
+ * drag&drop affects only one rows instead of all the selected ones.
+ *
+ */
+static void
+drag_begin_cb (GtkWidget *widget,
+ GdkDragContext *context,
+ gpointer data)
+{
+ ModestHeaderView *self = NULL;
+ ModestHeaderViewPrivate *priv = NULL;
+ GtkTreeSelection *selection;
+
+ self = MODEST_HEADER_VIEW (widget);
+ priv = MODEST_HEADER_VIEW_GET_PRIVATE(self);
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
+ priv->drag_begin_cached_selected_rows =
+ gtk_tree_selection_get_selected_rows (selection, NULL);
+}
- /* commenting out the next, fixes NB#62963 */
-#if 0
- /* Set focus on next header */
- sel = gtk_tree_view_get_selection(GTK_TREE_VIEW (widget));
- gtk_tree_path_next (source_row);
- gtk_tree_selection_select_path (sel, source_row);
+/**
+ * We use the drag-end signal to clear the cached selection, we use
+ * this because this allways happens, whether or not the d&d was a
+ * success
+ */
+static void
+drag_end_cb (GtkWidget *widget,
+ GdkDragContext *dc,
+ gpointer data)
+{
+ ModestHeaderView *self = NULL;
+ ModestHeaderViewPrivate *priv = NULL;
- gtk_tree_path_free (source_row);
-#endif
+ self = MODEST_HEADER_VIEW (widget);
+ priv = MODEST_HEADER_VIEW_GET_PRIVATE(self);
+
+ /* Free cached data */
+ g_list_foreach (priv->drag_begin_cached_selected_rows, (GFunc) gtk_tree_path_free, NULL);
+ g_list_free (priv->drag_begin_cached_selected_rows);
+ priv->drag_begin_cached_selected_rows = NULL;
}
/* Header view drag types */
const GtkTargetEntry header_view_drag_types[] = {
- { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_APP, MODEST_HEADER_ROW },
- { "text/uri-list", 0, MODEST_MSG },
+ { GTK_TREE_PATH_AS_STRING_LIST, GTK_TARGET_SAME_APP, MODEST_HEADER_ROW }
};
static void
g_signal_connect(G_OBJECT (self), "drag_data_get",
G_CALLBACK(drag_data_get_cb), NULL);
+
+ g_signal_connect(G_OBJECT (self), "drag_begin",
+ G_CALLBACK(drag_begin_cb), NULL);
+
+ g_signal_connect(G_OBJECT (self), "drag_end",
+ G_CALLBACK(drag_end_cb), NULL);
}
static GtkTreePath *