[gnome-builder] layout-grid: add support for DnD text/uri-list
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] layout-grid: add support for DnD text/uri-list
- Date: Wed, 13 Dec 2017 09:35:30 +0000 (UTC)
commit 3a0673ccea49cd54dfb97ba45973213c7dbdca81
Author: Christian Hergert <chergert redhat com>
Date: Wed Dec 13 01:27:19 2017 -0800
layout-grid: add support for DnD text/uri-list
This allows us to to drop text/uri-list onto the grid and let
consumers create a view for each of the URI.
src/libide/layout/ide-layout-grid.c | 118 ++++++++++++++++++++++++++++++++++-
1 files changed, 117 insertions(+), 1 deletions(-)
---
diff --git a/src/libide/layout/ide-layout-grid.c b/src/libide/layout/ide-layout-grid.c
index 777276e..afa2f01 100644
--- a/src/libide/layout/ide-layout-grid.c
+++ b/src/libide/layout/ide-layout-grid.c
@@ -460,7 +460,7 @@ ide_layout_grid_drag_motion (GtkWidget *widget,
IdeLayoutGridColumn *column = NULL;
IdeLayoutStack *stack = NULL;
DzlAnimation *drag_anim;
- GdkRectangle area = { 0 };
+ GdkRectangle area = {0};
GtkAllocation alloc;
gint drop = DROP_ONTO;
@@ -509,6 +509,100 @@ ide_layout_grid_drag_motion (GtkWidget *widget,
}
static void
+ide_layout_grid_drag_data_received (GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ GtkSelectionData *data,
+ guint info,
+ guint time_)
+{
+ IdeLayoutGrid *self = (IdeLayoutGrid *)widget;
+ IdeLayoutGridColumn *column = NULL;
+ IdeLayoutStack *stack = NULL;
+ g_auto(GStrv) uris = NULL;
+ GdkRectangle area = {0};
+ gint drop = DROP_ONTO;
+
+ g_assert (IDE_IS_LAYOUT_GRID (self));
+ g_assert (GDK_IS_DRAG_CONTEXT (context));
+
+ if (!ide_layout_grid_get_drop_area (self, x, y, &area, &column, &stack, &drop))
+ return;
+
+ g_assert (IDE_IS_LAYOUT_GRID_COLUMN (column));
+ g_assert (IDE_IS_LAYOUT_STACK (stack));
+
+ if (!(uris = gtk_selection_data_get_uris (data)))
+ return;
+
+ for (guint i = 0; uris[i] != NULL; i++)
+ {
+ const gchar *uri = uris[i];
+ IdeLayoutView *view = NULL;
+ gint column_index = 0;
+ gint stack_index = 0;
+
+ g_signal_emit (self, signals [CREATE_VIEW], 0, uri, &view);
+
+ if (view == NULL)
+ {
+ g_debug ("Failed to load IdeLayoutView for \"%s\"", uri);
+ continue;
+ }
+
+ gtk_container_child_get (GTK_CONTAINER (self), GTK_WIDGET (column),
+ "index", &column_index,
+ NULL);
+ gtk_container_child_get (GTK_CONTAINER (column), GTK_WIDGET (stack),
+ "index", &stack_index,
+ NULL);
+
+ switch (drop)
+ {
+ case DROP_ONTO:
+ gtk_container_add (GTK_CONTAINER (stack), GTK_WIDGET (view));
+ break;
+
+ case DROP_ABOVE:
+ stack = IDE_LAYOUT_STACK (ide_layout_grid_create_stack (self));
+ gtk_container_add_with_properties (GTK_CONTAINER (column), GTK_WIDGET (stack),
+ "index", stack_index,
+ NULL);
+ gtk_container_add (GTK_CONTAINER (stack), GTK_WIDGET (view));
+ break;
+
+ case DROP_BELOW:
+ stack = IDE_LAYOUT_STACK (ide_layout_grid_create_stack (self));
+ gtk_container_add_with_properties (GTK_CONTAINER (column), GTK_WIDGET (stack),
+ "index", stack_index + 1,
+ NULL);
+ gtk_container_add (GTK_CONTAINER (stack), GTK_WIDGET (view));
+ break;
+
+ case DROP_LEFT_OF:
+ column = IDE_LAYOUT_GRID_COLUMN (ide_layout_grid_create_column (self));
+ gtk_container_add_with_properties (GTK_CONTAINER (self), GTK_WIDGET (column),
+ "index", column_index,
+ NULL);
+ gtk_container_add (GTK_CONTAINER (column), GTK_WIDGET (view));
+ break;
+
+ case DROP_RIGHT_OF:
+ column = IDE_LAYOUT_GRID_COLUMN (ide_layout_grid_create_column (self));
+ gtk_container_add_with_properties (GTK_CONTAINER (self), GTK_WIDGET (column),
+ "index", column_index + 1,
+ NULL);
+ gtk_container_add (GTK_CONTAINER (column), GTK_WIDGET (view));
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+ }
+}
+
+static void
ide_layout_grid_drag_leave (GtkWidget *widget,
GdkDragContext *context,
guint time_)
@@ -638,6 +732,7 @@ ide_layout_grid_class_init (IdeLayoutGridClass *klass)
object_class->get_property = ide_layout_grid_get_property;
object_class->set_property = ide_layout_grid_set_property;
+ widget_class->drag_data_received = ide_layout_grid_drag_data_received;
widget_class->drag_motion = ide_layout_grid_drag_motion;
widget_class->drag_leave = ide_layout_grid_drag_leave;
widget_class->drag_failed = ide_layout_grid_drag_failed;
@@ -689,6 +784,27 @@ ide_layout_grid_class_init (IdeLayoutGridClass *klass)
G_STRUCT_OFFSET (IdeLayoutGridClass, create_stack),
g_signal_accumulator_first_wins, NULL, NULL,
IDE_TYPE_LAYOUT_STACK, 0);
+
+ /**
+ * IdeLayoutGrid::create-view:
+ * @self: an #IdeLayoutGrid
+ * @uri: the URI to open
+ *
+ * Creates a new view for @uri to be added to the grid.
+ *
+ * Returns: (transfer full): A newly created #IdeLayoutView
+ *
+ * Since: 3.28
+ */
+ signals [CREATE_VIEW] =
+ g_signal_new (g_intern_static_string ("create-view"),
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (IdeLayoutGridClass, create_view),
+ g_signal_accumulator_first_wins, NULL, NULL,
+ IDE_TYPE_LAYOUT_VIEW,
+ 1,
+ G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]