[gthumb/ext] Fixed drag and drop between gthumb and nautilus



commit f1d288a86dcbcd8bd44d550d880c00b964f5c897
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sat Aug 29 22:16:45 2009 +0200

    Fixed drag and drop between gthumb and nautilus
    
    [bug #593431]

 extensions/file_manager/callbacks.c |  101 ++++++++++++++++++++++++-----------
 gthumb/gth-browser.c                |   20 ++++++-
 gthumb/gth-file-list.c              |    7 +++
 gthumb/gth-file-list.h              |    1 +
 4 files changed, 96 insertions(+), 33 deletions(-)
---
diff --git a/extensions/file_manager/callbacks.c b/extensions/file_manager/callbacks.c
index 920d713..17dca99 100644
--- a/extensions/file_manager/callbacks.c
+++ b/extensions/file_manager/callbacks.c
@@ -122,8 +122,14 @@ static const char *folder_popup_ui_info =
 "</ui>";
 
 
-static GtkTargetEntry drag_dest_targets[] = {
-        { "text/uri-list", 0, 0 }
+static GtkTargetEntry reorderable_drag_dest_targets[] = {
+        { "text/uri-list", 0, 0 },
+        { "text/uri-list", GTK_TARGET_SAME_WIDGET, 0 }
+};
+
+
+static GtkTargetEntry non_reorderable_drag_dest_targets[] = {
+        { "text/uri-list", GTK_TARGET_OTHER_WIDGET, 0 }
 };
 
 
@@ -222,7 +228,7 @@ set_action_sensitive (BrowserData *data,
 
 
 static void
-gth_file_list_drag_data_received (GtkWidget        *widget,
+gth_file_list_drag_data_received (GtkWidget        *file_view,
 				  GdkDragContext   *context,
 				  int               x,
 				  int               y,
@@ -232,12 +238,11 @@ gth_file_list_drag_data_received (GtkWidget        *widget,
 				  gpointer          user_data)
 {
 	GthBrowser  *browser = user_data;
-
 	gboolean     success = FALSE;
 	char       **uris;
 	GList       *file_list;
 
-	g_signal_stop_emission_by_name (widget, "drag-data-received");
+	g_signal_stop_emission_by_name (file_view, "drag-data-received");
 
 	if ((context->suggested_action == GDK_ACTION_COPY)
 	    || (context->suggested_action == GDK_ACTION_MOVE))
@@ -250,7 +255,7 @@ gth_file_list_drag_data_received (GtkWidget        *widget,
 	uris = gtk_selection_data_get_uris (selection_data);
 	file_list = _g_file_list_new_from_uriv (uris);
 	if (file_list != NULL) {
-		if (gtk_drag_get_source_widget (context) == gth_file_list_get_view (GTH_FILE_LIST (gth_browser_get_file_list (browser)))) {
+		if (gtk_drag_get_source_widget (context) == file_view) {
 			BrowserData *data;
 			GthTask     *task;
 
@@ -329,43 +334,41 @@ gth_file_list_drag_drop (GtkWidget      *widget,
 
 
 static gboolean
-gth_file_list_drag_motion (GtkWidget          *widget,
-			   GdkDragContext     *context,
-			   gint                x,
-			   gint                y,
-			   guint               time,
-			   gpointer            extra_data)
+gth_file_list_drag_motion (GtkWidget      *file_view,
+			   GdkDragContext *context,
+			   gint            x,
+			   gint            y,
+			   guint           time,
+			   gpointer        extra_data)
 {
 	GthBrowser  *browser = extra_data;
 	BrowserData *data;
-	GtkWidget   *file_view;
 
 	data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);
 
-	file_view = gth_file_list_get_view (GTH_FILE_LIST (gth_browser_get_file_list (browser)));
 	if ((gtk_drag_get_source_widget (context) == file_view) && ! gth_file_source_is_reorderable (gth_browser_get_location_source (browser))) {
 		data->drop_pos = -1;
 		gdk_drag_status (context, 0, time);
 		return FALSE;
 	}
 
-	gdk_drag_status (context, GDK_ACTION_MOVE, time);
-	gth_file_view_set_drag_dest_pos (GTH_FILE_VIEW (file_view), context, x, y, time, &data->drop_pos);
+	if ((gtk_drag_get_source_widget (context) == file_view) && gth_file_source_is_reorderable (gth_browser_get_location_source (browser))) {
+		gdk_drag_status (context, GDK_ACTION_MOVE, time);
+		gth_file_view_set_drag_dest_pos (GTH_FILE_VIEW (file_view), context, x, y, time, &data->drop_pos);
+	}
+	else
+		gdk_drag_status (context, GDK_ACTION_COPY, time);
 
 	return TRUE;
 }
 
 
 static gboolean
-gth_file_list_drag_leave (GtkWidget          *widget,
-			  GdkDragContext     *context,
-			  guint               time,
-			  gpointer            extra_data)
+gth_file_list_drag_leave (GtkWidget      *file_view,
+			  GdkDragContext *context,
+			  guint           time,
+			  gpointer        extra_data)
 {
-	GthBrowser *browser = extra_data;
-	GtkWidget  *file_view;
-
-	file_view = gth_file_list_get_view (GTH_FILE_LIST (gth_browser_get_file_list (browser)));
 	if (gtk_drag_get_source_widget (context) == file_view)
 		gth_file_view_set_drag_dest_pos (GTH_FILE_VIEW (file_view), context, -1, -1, time, NULL);
 
@@ -410,6 +413,24 @@ fm__gth_browser_construct_cb (GthBrowser *browser)
 	                  G_CALLBACK (gth_file_list_drag_leave),
 	                  browser);
 
+	file_view = gth_file_list_get_empty_view (GTH_FILE_LIST (gth_browser_get_file_list (browser)));
+	g_signal_connect (file_view,
+                          "drag_data_received",
+                          G_CALLBACK (gth_file_list_drag_data_received),
+                          browser);
+	g_signal_connect (file_view,
+	                  "drag_drop",
+	                  G_CALLBACK (gth_file_list_drag_drop),
+	                  browser);
+	g_signal_connect (file_view,
+			  "drag_motion",
+			  G_CALLBACK (gth_file_list_drag_motion),
+			  browser);
+	g_signal_connect (file_view,
+	                  "drag_leave",
+	                  G_CALLBACK (gth_file_list_drag_leave),
+	                  browser);
+
 	g_object_set_data_full (G_OBJECT (browser), BROWSER_DATA_KEY, data, (GDestroyNotify) browser_data_free);
 }
 
@@ -494,14 +515,32 @@ fm__gth_browser_load_location_after_cb (GthBrowser   *browser,
 	data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);
 	file_manager_update_ui (data, browser);
 
-	file_view = gth_file_list_get_view (GTH_FILE_LIST (gth_browser_get_file_list (browser)));
-	if (gth_file_source_is_reorderable (gth_browser_get_location_source (browser)))
+	if (gth_file_source_is_reorderable (gth_browser_get_location_source (browser))) {
+		file_view = gth_file_list_get_view (GTH_FILE_LIST (gth_browser_get_file_list (browser)));
 		gth_file_view_enable_drag_dest (GTH_FILE_VIEW (file_view),
-						drag_dest_targets,
-						G_N_ELEMENTS (drag_dest_targets),
-						GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_ASK);
-	else
-		gth_file_view_unset_drag_dest (GTH_FILE_VIEW (file_view));
+						reorderable_drag_dest_targets,
+						G_N_ELEMENTS (reorderable_drag_dest_targets),
+						GDK_ACTION_COPY | GDK_ACTION_MOVE);
+		file_view = gth_file_list_get_empty_view (GTH_FILE_LIST (gth_browser_get_file_list (browser)));
+		gtk_drag_dest_set (file_view,
+				   0,
+				   reorderable_drag_dest_targets,
+				   G_N_ELEMENTS (reorderable_drag_dest_targets),
+				   GDK_ACTION_COPY | GDK_ACTION_MOVE);
+	}
+	else {
+		file_view = gth_file_list_get_view (GTH_FILE_LIST (gth_browser_get_file_list (browser)));
+		gth_file_view_enable_drag_dest (GTH_FILE_VIEW (file_view),
+						non_reorderable_drag_dest_targets,
+						G_N_ELEMENTS (non_reorderable_drag_dest_targets),
+						GDK_ACTION_COPY);
+		file_view = gth_file_list_get_empty_view (GTH_FILE_LIST (gth_browser_get_file_list (browser)));
+		gtk_drag_dest_set (file_view,
+				   0,
+				   non_reorderable_drag_dest_targets,
+				   G_N_ELEMENTS (non_reorderable_drag_dest_targets),
+				   GDK_ACTION_COPY);
+	}
 }
 
 
diff --git a/gthumb/gth-browser.c b/gthumb/gth-browser.c
index a15a09f..8059b21 100644
--- a/gthumb/gth-browser.c
+++ b/gthumb/gth-browser.c
@@ -978,7 +978,15 @@ load_data_done (LoadData *load_data,
 		browser->priv->location_source = g_object_ref (load_data->file_source);
 	}
 
-	gth_hook_invoke ("gth-browser-load-location-after", browser, load_data->requested_folder->file, error);
+	if ((load_data->action == GTH_ACTION_GO_TO)
+	    || (load_data->action == GTH_ACTION_GO_INTO)
+	    || (load_data->action == GTH_ACTION_GO_BACK)
+	    || (load_data->action == GTH_ACTION_GO_FORWARD)
+	    || (load_data->action == GTH_ACTION_GO_UP)
+	    || (load_data->action == GTH_ACTION_VIEW))
+	{
+		gth_hook_invoke ("gth-browser-load-location-after", browser, load_data->requested_folder->file, error);
+	}
 
 	if (error == NULL)
 		return;
@@ -1559,7 +1567,15 @@ _gth_browser_load (GthBrowser *browser,
 	entry_point = get_nearest_entry_point (location);
 	load_data = load_data_new (browser, location, action, automatic, entry_point);
 
-	gth_hook_invoke ("gth-browser-load-location-before", browser, load_data->requested_folder->file);
+	if ((load_data->action == GTH_ACTION_GO_TO)
+	    || (load_data->action == GTH_ACTION_GO_INTO)
+	    || (load_data->action == GTH_ACTION_GO_BACK)
+	    || (load_data->action == GTH_ACTION_GO_FORWARD)
+	    || (load_data->action == GTH_ACTION_GO_UP)
+	    || (load_data->action == GTH_ACTION_VIEW))
+	{
+		gth_hook_invoke ("gth-browser-load-location-before", browser, load_data->requested_folder->file);
+	}
 	browser->priv->activity_ref++;
 
 	if (entry_point == NULL) {
diff --git a/gthumb/gth-file-list.c b/gthumb/gth-file-list.c
index 8922cd2..7c5d9b5 100644
--- a/gthumb/gth-file-list.c
+++ b/gthumb/gth-file-list.c
@@ -1171,6 +1171,13 @@ gth_file_list_get_view (GthFileList *file_list)
 }
 
 
+GtkWidget *
+gth_file_list_get_empty_view (GthFileList *file_list)
+{
+	return file_list->priv->message;
+}
+
+
 /* thumbs */
 
 
diff --git a/gthumb/gth-file-list.h b/gthumb/gth-file-list.h
index 35b0f08..5996540 100644
--- a/gthumb/gth-file-list.h
+++ b/gthumb/gth-file-list.h
@@ -89,6 +89,7 @@ void           gth_file_list_set_thumb_size (GthFileList          *file_list,
 void           gth_file_list_set_caption    (GthFileList          *file_list,
 					     const char           *attribute);
 GtkWidget *    gth_file_list_get_view       (GthFileList          *file_list);
+GtkWidget *    gth_file_list_get_empty_view (GthFileList          *file_list);
 int            gth_file_list_first_file     (GthFileList          *file_list,
 					     gboolean              skip_broken,
 					     gboolean              only_selected);



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