[gthumb] suggest the right action when starting a DnD from the folder tree



commit 1aeeeed05d2fae69d3c5ffac487607010c4d3841
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Thu Jan 20 20:15:06 2011 +0100

    suggest the right action when starting a DnD from the folder tree

 extensions/file_manager/actions.c   |    2 +-
 extensions/file_manager/callbacks.c |   20 +++++++++++---------
 gthumb/gth-browser.c                |   18 +++++++++++++-----
 gthumb/gth-file-source-vfs.c        |    3 ++-
 gthumb/gth-file-source.c            |    8 +++++---
 gthumb/gth-file-source.h            |    6 ++++--
 6 files changed, 36 insertions(+), 21 deletions(-)
---
diff --git a/extensions/file_manager/actions.c b/extensions/file_manager/actions.c
index 5808c12..70f4a4e 100644
--- a/extensions/file_manager/actions.c
+++ b/extensions/file_manager/actions.c
@@ -319,7 +319,7 @@ clipboard_received_cb (GtkClipboard     *clipboard,
 	paste_data->files = g_list_reverse (paste_data->files);
 	paste_data->file_source = gth_main_get_file_source (paste_data->destination->file);
 
-	if (paste_data->cut && ! gth_file_source_can_cut (paste_data->file_source)) {
+	if (paste_data->cut && ! gth_file_source_can_cut (paste_data->file_source, paste_data->files->data)) {
 		GtkWidget *dialog;
 		int        response;
 
diff --git a/extensions/file_manager/callbacks.c b/extensions/file_manager/callbacks.c
index fa3fb3f..2733c58 100644
--- a/extensions/file_manager/callbacks.c
+++ b/extensions/file_manager/callbacks.c
@@ -272,15 +272,15 @@ gth_file_list_drag_data_received (GtkWidget        *file_view,
 	g_signal_stop_emission_by_name (file_view, "drag-data-received");
 
 	/*
-	if ((gdk_drag_context_get_suggested_action (context) == GDK_ACTION_COPY)
-	    || (gdk_drag_context_get_suggested_action (context) == GDK_ACTION_MOVE))
+	if ((gdk_drag_context_get_action (context) == GDK_ACTION_COPY)
+	    || (gdk_drag_context_get_action (context) == GDK_ACTION_MOVE))
 	{
 		success = TRUE;
 	}
 	*/
 
-	if ((context->suggested_action == GDK_ACTION_COPY)
-	    || (context->suggested_action == GDK_ACTION_MOVE))
+	if ((context->action == GDK_ACTION_COPY)
+	    || (context->action == GDK_ACTION_MOVE))
 	{
 		success = TRUE;
 	}
@@ -317,9 +317,9 @@ gth_file_list_drag_data_received (GtkWidget        *file_view,
 			gboolean       move;
 
 			file_source = gth_browser_get_location_source (browser);
-			/*move = gdk_drag_context_get_suggested_action (context) == GDK_ACTION_MOVE;*/
-			move = context->suggested_action == GDK_ACTION_MOVE;
-			if (move && ! gth_file_source_can_cut (file_source)) {
+			/*move = gdk_drag_context_get_action (context) == GDK_ACTION_MOVE;*/
+			move = context->action == GDK_ACTION_MOVE;
+			if (move && ! gth_file_source_can_cut (file_source, (GFile *) selected_files->data)) {
 				GtkWidget *dialog;
 				int        response;
 
@@ -723,7 +723,7 @@ fm__gth_browser_folder_tree_drag_data_received_cb (GthBrowser    *browser,
 	if (file_source == NULL)
 		return;
 
-	if ((action == GDK_ACTION_MOVE) && ! gth_file_source_can_cut (file_source)) {
+	if ((action == GDK_ACTION_MOVE) && ! gth_file_source_can_cut (file_source, (GFile *) file_list->data)) {
 		GtkWidget *dialog;
 		int        response;
 
@@ -809,6 +809,7 @@ fm__gth_browser_update_sensitivity_cb (GthBrowser *browser)
 	BrowserData   *data;
 	GthFileSource *file_source;
 	int            n_selected;
+	GthFileData   *location_data;
 	gboolean       sensitive;
 	GthFileData   *folder;
 
@@ -818,7 +819,8 @@ fm__gth_browser_update_sensitivity_cb (GthBrowser *browser)
 	file_source = gth_browser_get_location_source (browser);
 	n_selected = gth_file_selection_get_n_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
 
-	sensitive = (n_selected > 0) && (file_source != NULL) && gth_file_source_can_cut (file_source);
+	location_data = gth_browser_get_location_data (browser);
+	sensitive = (n_selected > 0) && (file_source != NULL) && (location_data != NULL) && gth_file_source_can_cut (file_source, location_data->file);
 	set_action_sensitive (data, "Edit_CutFiles", sensitive);
 
 	sensitive = (n_selected > 0) && (file_source != NULL);
diff --git a/gthumb/gth-browser.c b/gthumb/gth-browser.c
index 67b6fc2..46ec0ee 100644
--- a/gthumb/gth-browser.c
+++ b/gthumb/gth-browser.c
@@ -2529,25 +2529,33 @@ folder_tree_drag_data_received (GtkWidget        *tree_view,
 static void
 folder_tree_drag_data_get_cb (GtkWidget        *widget,
 			      GdkDragContext   *drag_context,
-			      GtkSelectionData *data,
+			      GtkSelectionData *selection_data,
 			      guint             info,
 			      guint             time,
 			      gpointer          user_data)
 {
-	GthBrowser   *browser = user_data;
-	GthFileData  *file_data;
-	char        **uris;
+	GthBrowser     *browser = user_data;
+	GthFileData    *file_data;
+	GthFileSource  *file_source;
+	char          **uris;
 
 	file_data = gth_folder_tree_get_selected (GTH_FOLDER_TREE (browser->priv->folder_tree));
 	if (file_data == NULL)
 		return;
 
+	file_source = gth_main_get_file_source (file_data->file);
+	if (file_source == NULL)
+		return;
+
+	drag_context->suggested_action = gth_file_source_can_cut (file_source, file_data->file) ? GDK_ACTION_MOVE : GDK_ACTION_COPY;
+
 	uris = g_new (char *, 2);
 	uris[0] = g_file_get_uri (file_data->file);
 	uris[1] = NULL;
-	gtk_selection_data_set_uris (data, uris);
+	gtk_selection_data_set_uris (selection_data, uris);
 
 	g_strfreev (uris);
+	g_object_unref (file_source);
 	g_object_unref (file_data);
 }
 
diff --git a/gthumb/gth-file-source-vfs.c b/gthumb/gth-file-source-vfs.c
index b71f0ad..ebe16f1 100644
--- a/gthumb/gth-file-source-vfs.c
+++ b/gthumb/gth-file-source-vfs.c
@@ -331,7 +331,8 @@ gth_file_source_vfs_copy (GthFileSource    *file_source,
 
 
 static gboolean
-gth_file_source_vfs_can_cut (GthFileSource *file_source)
+gth_file_source_vfs_can_cut (GthFileSource *file_source,
+			     GFile         *file)
 {
 	return TRUE;
 }
diff --git a/gthumb/gth-file-source.c b/gthumb/gth-file-source.c
index 6f80d2e..1878784 100644
--- a/gthumb/gth-file-source.c
+++ b/gthumb/gth-file-source.c
@@ -631,7 +631,8 @@ base_rename (GthFileSource *file_source,
 
 
 static gboolean
-base_can_cut (GthFileSource *file_source)
+base_can_cut (GthFileSource *file_source,
+	      GFile         *file)
 {
 	return FALSE;
 }
@@ -1123,9 +1124,10 @@ gth_file_source_copy (GthFileSource    *file_source,
 
 
 gboolean
-gth_file_source_can_cut (GthFileSource *file_source)
+gth_file_source_can_cut (GthFileSource *file_source,
+			 GFile         *file)
 {
-	return GTH_FILE_SOURCE_GET_CLASS (G_OBJECT (file_source))->can_cut (file_source);
+	return GTH_FILE_SOURCE_GET_CLASS (G_OBJECT (file_source))->can_cut (file_source, file);
 }
 
 
diff --git a/gthumb/gth-file-source.h b/gthumb/gth-file-source.h
index dbdd0d7..57ce3dd 100644
--- a/gthumb/gth-file-source.h
+++ b/gthumb/gth-file-source.h
@@ -107,7 +107,8 @@ struct _GthFileSourceClass
 					       DialogCallback    dialog_callback,
 					       ReadyCallback     callback,
 					       gpointer          data);
-	gboolean     (*can_cut)               (GthFileSource    *file_source);
+	gboolean     (*can_cut)               (GthFileSource    *file_source,
+					       GFile            *file);
 	void         (*monitor_entry_points)  (GthFileSource    *file_source);
 	void         (*monitor_directory)     (GthFileSource    *file_source,
 					       GFile            *file,
@@ -184,7 +185,8 @@ void           gth_file_source_copy                  (GthFileSource    *file_sou
 						      DialogCallback    dialog_callback,
 						      ReadyCallback     ready_callback,
 						      gpointer          data);
-gboolean       gth_file_source_can_cut               (GthFileSource    *file_source);
+gboolean       gth_file_source_can_cut               (GthFileSource    *file_source,
+						      GFile            *file);
 void           gth_file_source_monitor_entry_points  (GthFileSource    *file_source);
 void           gth_file_source_monitor_directory     (GthFileSource    *file_source,
 						      GFile            *file,



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