[anjuta] file-manager: Support drag & drop from file-manager



commit d02204f2900e71505c8f23b410e4820ee217c900
Author: Johannes Schmid <jhs gnome org>
Date:   Sun Jan 24 22:21:47 2010 +0100

    file-manager: Support drag & drop from file-manager

 plugins/file-manager/file-view.c |   51 ++++++++++++++++++++++++++++++++++++-
 1 files changed, 49 insertions(+), 2 deletions(-)
---
diff --git a/plugins/file-manager/file-view.c b/plugins/file-manager/file-view.c
index 4b90d66..cde5ef4 100644
--- a/plugins/file-manager/file-view.c
+++ b/plugins/file-manager/file-view.c
@@ -49,6 +49,16 @@ struct _AnjutaFileViewPrivate
 	GtkTreeRowReference* current_selection;
 };
 
+GtkTargetEntry uri_targets[] =
+{
+	{
+		"text/uri-list",
+		0, /* no flags */
+		0
+	}
+};
+	
+
 #define ANJUTA_FILE_VIEW_GET_PRIVATE(o) \
 	(G_TYPE_INSTANCE_GET_PRIVATE((o), ANJUTA_TYPE_FILE_VIEW, AnjutaFileViewPrivate))
 
@@ -127,7 +137,14 @@ file_view_get_selected (AnjutaFileView* view)
 	GtkTreeIter selected;
 	if (gtk_tree_selection_get_selected (selection, NULL, &selected))
 	{
-		GFile* file = file_model_get_file (priv->model, &selected);
+		GFile* file;
+		GtkTreeIter real_iter;
+		GtkTreeModel* sort_model = gtk_tree_view_get_model (GTK_TREE_VIEW(view));
+
+		gtk_tree_model_sort_convert_iter_to_child_iter(GTK_TREE_MODEL_SORT(sort_model),
+		                                               &real_iter, &selected);
+
+		file = file_model_get_file (priv->model, &real_iter);
 		return file;
 	}
 	else
@@ -135,6 +152,26 @@ file_view_get_selected (AnjutaFileView* view)
 }
 
 static void
+file_view_drag_data_get (GtkWidget* widget,
+                         GdkDragContext *drag_context,
+                         GtkSelectionData *data,
+                         guint info,
+                         guint time)
+{
+	AnjutaFileView* view = ANJUTA_FILE_VIEW(widget);
+	GFile* selected = file_view_get_selected (view);
+
+	if (selected)
+	{
+		gchar* uris[2];
+		uris[0] = g_file_get_uri (selected);
+		uris[1] = NULL;
+		gtk_selection_data_set_uris (data, uris);
+		g_free(uris[0]);
+	}
+}
+
+static void
 file_view_row_activated (GtkTreeView* widget, GtkTreePath* sort_path,
 						 GtkTreeViewColumn* column)
 {
@@ -546,6 +583,13 @@ file_view_init (AnjutaFileView *object)
 	gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (object), FALSE);
 	
 	g_object_set (object, "has-tooltip", TRUE, NULL);
+
+	/* DND */
+	gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW(object),
+	                                        GDK_BUTTON1_MASK,
+	                                        uri_targets,
+	                                        1,
+	                                        GDK_ACTION_MOVE);                                    
 }
 
 static void
@@ -655,7 +699,10 @@ file_view_class_init (AnjutaFileViewClass *klass)
 	widget_class->button_press_event = file_view_button_press_event;
 	
 	/* Tooltips */
-	widget_class->query_tooltip = file_view_query_tooltip;	
+	widget_class->query_tooltip = file_view_query_tooltip;
+
+	/* Dnd */
+	widget_class->drag_data_get = file_view_drag_data_get;
 }
 
 GtkWidget*



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]