[gnome-builder] allow dropping anywhere on workbench (that doesnt supress dnd)
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] allow dropping anywhere on workbench (that doesnt supress dnd)
- Date: Tue, 24 Mar 2015 00:27:16 +0000 (UTC)
commit 5aaae53712333e409154ebd415ebf0b90c45b37c
Author: Christian Hergert <christian hergert me>
Date: Thu Mar 19 15:03:35 2015 -0700
allow dropping anywhere on workbench (that doesnt supress dnd)
src/workbench/gb-workbench-actions.c | 11 +-----
src/workbench/gb-workbench.c | 68 ++++++++++++++++++++++++++++++++++
src/workbench/gb-workbench.h | 16 ++++---
3 files changed, 78 insertions(+), 17 deletions(-)
---
diff --git a/src/workbench/gb-workbench-actions.c b/src/workbench/gb-workbench-actions.c
index 7289e56..0ee68ca 100644
--- a/src/workbench/gb-workbench-actions.c
+++ b/src/workbench/gb-workbench-actions.c
@@ -55,16 +55,7 @@ gb_workbench_actions_open_uri_list (GSimpleAction *action,
if (uri_list != NULL)
{
- gsize i;
-
- for (i = 0; uri_list [i]; i++)
- {
- g_autoptr(GFile) file = NULL;
-
- file = g_file_new_for_uri (uri_list [i]);
- gb_workbench_open (self, file);
- }
-
+ gb_workbench_open_uri_list (self, (const gchar * const *)uri_list);
g_free (uri_list);
}
}
diff --git a/src/workbench/gb-workbench.c b/src/workbench/gb-workbench.c
index 1ec405f..12fdfec 100644
--- a/src/workbench/gb-workbench.c
+++ b/src/workbench/gb-workbench.c
@@ -22,6 +22,7 @@
#include <ide.h>
#include "gb-command-gaction-provider.h"
+#include "gb-dnd.h"
#include "gb-widget.h"
#include "gb-workbench-actions.h"
#include "gb-workbench-private.h"
@@ -38,7 +39,14 @@ enum {
LAST_PROP
};
+enum {
+ TARGET_URI_LIST = 100
+};
+
static GParamSpec *gParamSpecs [LAST_PROP];
+static const GtkTargetEntry gDropTypes[] = {
+ { "text/uri-list", 0, TARGET_URI_LIST}
+};
static void
gb_workbench_set_context (GbWorkbench *self,
@@ -123,6 +131,42 @@ gb_workbench_draw (GtkWidget *widget,
}
static void
+gb_workbench_drag_data_received (GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint timestamp)
+{
+ GbWorkbench *self = (GbWorkbench *)widget;
+ gchar **uri_list;
+ gboolean handled = FALSE;
+
+ g_assert (GB_IS_WORKBENCH (self));
+
+ switch (info)
+ {
+ case TARGET_URI_LIST:
+ uri_list = gb_dnd_get_uri_list (selection_data);
+
+ if (uri_list)
+ {
+ gb_workbench_open_uri_list (self, (const gchar * const *)uri_list);
+ g_strfreev (uri_list);
+ }
+
+ handled = TRUE;
+ break;
+
+ default:
+ break;
+ }
+
+ gtk_drag_finish (context, handled, FALSE, timestamp);
+}
+
+static void
gb_workbench_realize (GtkWidget *widget)
{
GbWorkbench *self = (GbWorkbench *)widget;
@@ -287,6 +331,7 @@ gb_workbench_class_init (GbWorkbenchClass *klass)
object_class->get_property = gb_workbench_get_property;
object_class->set_property = gb_workbench_set_property;
+ widget_class->drag_data_received = gb_workbench_drag_data_received;
widget_class->draw = gb_workbench_draw;
widget_class->realize = gb_workbench_realize;
widget_class->delete_event = gb_workbench_delete_event;
@@ -356,6 +401,12 @@ gb_workbench_init (GbWorkbench *self)
NULL);
gb_command_manager_add_provider (self->command_manager, gaction_provider);
+
+ /* Drag and drop support*/
+ gtk_drag_dest_set (GTK_WIDGET (self),
+ (GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP),
+ gDropTypes, G_N_ELEMENTS (gDropTypes), GDK_ACTION_COPY);
+
IDE_EXIT;
}
@@ -440,3 +491,20 @@ gb_workbench_get_command_manager (GbWorkbench *self)
return self->command_manager;
}
+
+void
+gb_workbench_open_uri_list (GbWorkbench *self,
+ const gchar * const *uri_list)
+{
+ gsize i;
+
+ g_return_if_fail (GB_IS_WORKBENCH (self));
+
+ for (i = 0; uri_list [i]; i++)
+ {
+ g_autoptr(GFile) file = NULL;
+
+ file = g_file_new_for_uri (uri_list [i]);
+ gb_workbench_open (self, file);
+ }
+}
diff --git a/src/workbench/gb-workbench.h b/src/workbench/gb-workbench.h
index 54ea1bf..4cd2412 100644
--- a/src/workbench/gb-workbench.h
+++ b/src/workbench/gb-workbench.h
@@ -31,13 +31,15 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GbWorkbench, gb_workbench, GB, WORKBENCH, GtkApplicationWindow)
-IdeContext *gb_workbench_get_context (GbWorkbench *self);
-GbWorkspace *gb_workbench_get_active_workspace (GbWorkbench *self);
-void gb_workbench_set_active_workspace (GbWorkbench *self,
- GbWorkspace *workspace);
-void gb_workbench_open (GbWorkbench *self,
- GFile *file);
-GbCommandManager *gb_workbench_get_command_manager (GbWorkbench *self);
+IdeContext *gb_workbench_get_context (GbWorkbench *self);
+GbWorkspace *gb_workbench_get_active_workspace (GbWorkbench *self);
+void gb_workbench_set_active_workspace (GbWorkbench *self,
+ GbWorkspace *workspace);
+void gb_workbench_open (GbWorkbench *self,
+ GFile *file);
+void gb_workbench_open_uri_list (GbWorkbench *self,
+ const gchar * const *uri_list);
+GbCommandManager *gb_workbench_get_command_manager (GbWorkbench *self);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]