[libgd/wip/rishi/main-box: 10/10] main box
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgd/wip/rishi/main-box: 10/10] main box
- Date: Fri, 16 Dec 2016 18:28:35 +0000 (UTC)
commit bf9669352194080c84cfda90a97e2b8d6521a083
Author: Debarshi Ray <debarshir gnome org>
Date: Fri Dec 16 19:26:38 2016 +0100
main box
libgd/gd-main-box.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 57 insertions(+), 3 deletions(-)
---
diff --git a/libgd/gd-main-box.c b/libgd/gd-main-box.c
index 2e17ccc..230ee9a 100644
--- a/libgd/gd-main-box.c
+++ b/libgd/gd-main-box.c
@@ -92,6 +92,54 @@ gd_main_box_apply_selection_mode (GdMainBox *self)
}
static void
+gd_main_box_drag_data_get_cb (GdMainBox *self,
+ GdkDragContext *context,
+ GtkSelectionData *data,
+ guint info,
+ guint time)
+{
+ GdMainBoxPrivate *priv;
+ GPtrArray *uri_array;
+ gchar **uris = NULL;
+
+ priv = gd_main_box_get_instance_private (self);
+
+ if (info != 0)
+ goto out;
+
+ uri_array = g_ptr_array_new ();
+
+ if (priv->selection_mode)
+ {
+ GList *l;
+ GList *selected_children;
+
+ selected_children = gd_main_box_generic_get_selected_children (GD_MAIN_BOX_GENERIC
(priv->current_box));
+ for (l = selected_children; l != NULL; l = l->next)
+ {
+ GdMainBoxChild *child = GD_MAIN_BOX_CHILD (l->data);
+ GdMainBoxItem *item;
+ const gchar *uri;
+
+ item = gd_main_box_child_get_item (child);
+ uri = gd_main_box_item_get_uri (item);
+ g_ptr_array_add (uri_array, g_strdup (uri));
+ }
+
+ g_list_free (selected_children);
+ }
+ else
+ {
+ }
+
+ uris = (gchar **) g_ptr_array_free (uri_array, FALSE);
+ gtk_selection_data_set_uris (data, uris);
+
+ out:
+ g_strfreev (uris);
+}
+
+static void
gd_main_box_item_activated_cb (GdMainBox *self, GdMainBoxChild *child)
{
GdMainBoxPrivate *priv;
@@ -128,6 +176,7 @@ gd_main_box_rebuild (GdMainBox *self)
{
GdMainBoxPrivate *priv;
GtkStyleContext *context;
+ const GtkTargetEntry targets[] = { { (gchar *) "text/uri-list", GTK_TARGET_OTHER_APP, 0 } };
priv = gd_main_box_get_instance_private (self);
@@ -148,12 +197,16 @@ gd_main_box_rebuild (GdMainBox *self)
gtk_widget_set_hexpand (priv->current_box, TRUE);
gtk_widget_set_vexpand (priv->current_box, TRUE);
-
context = gtk_widget_get_style_context (priv->current_box);
gtk_style_context_add_class (context, "content-view");
-
gtk_container_add (GTK_CONTAINER (self), priv->current_box);
+ gtk_drag_source_set (priv->current_box, GDK_BUTTON1_MASK, targets, G_N_ELEMENTS (targets),
GDK_ACTION_COPY);
+
+ g_signal_connect_swapped (priv->current_box,
+ "drag-data-get",
+ G_CALLBACK (gd_main_box_drag_data_get_cb),
+ self);
g_signal_connect_swapped (priv->current_box,
"item-activated",
G_CALLBACK (gd_main_box_item_activated_cb),
@@ -463,11 +516,12 @@ gd_main_box_get_selection (GdMainBox *self)
GdMainBoxChild *child = GD_MAIN_BOX_CHILD (l->data);
GdMainBoxItem *item;
- item = gd_main_box_child_get_item (GD_MAIN_BOX_CHILD (child));
+ item = gd_main_box_child_get_item (child);
selection = g_list_prepend (selection, g_object_ref (item));
}
selection = g_list_reverse (selection);
+ g_list_free (selected_children);
return selection;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]