[PATCH] Add "Copy to..."/"Move to ..." to menus



Hi guys...
I wrote a patch which add "Copy to folder" and "Move to folder" to
nautilus menus.
I miss this feature from Konqueror or Windows Explorer, so I thought it
could be useful.
Hope you like it.
Best regards.
   Shogun

PS: I'm Italian, so don't blame my English :)
Index: src/file-manager/nautilus-directory-view-ui.xml
===================================================================
--- src/file-manager/nautilus-directory-view-ui.xml	(revisione 13217)
+++ src/file-manager/nautilus-directory-view-ui.xml	(copia locale)
@@ -53,6 +53,9 @@
 			<menuitem name="Cut" action="Cut"/>
 			<menuitem name="Copy" action="Copy"/>
 			<menuitem name="Paste" action="Paste"/>
+			<separator name="Before Copy or Move Actions"/>
+			<menuitem name="CopyTo" action="CopyTo"/>
+			<menuitem name="MoveTo" action="MoveTo"/>
 		</placeholder>
 		<placeholder name="Select Items">
 		<menuitem name="Select All" action="Select All"/>
@@ -137,6 +140,9 @@
 		<menuitem name="Cut" action="Cut"/>
 		<menuitem name="Copy" action="Copy"/>
 		<menuitem name="Paste Files Into" action="Paste Files Into"/>
+		<separator name="Before Copy or Move Actions"/>
+		<menuitem name="CopyTo" action="CopyTo"/>
+		<menuitem name="MoveTo" action="MoveTo"/>
 	</placeholder>
 	<separator name="File actions separator"/>
 	<placeholder name="File Actions">
Index: src/file-manager/fm-directory-view.c
===================================================================
--- src/file-manager/fm-directory-view.c	(revisione 13217)
+++ src/file-manager/fm-directory-view.c	(copia locale)
@@ -48,6 +48,7 @@
 #include <eel/eel-string.h>
 #include <eel/eel-vfs-extensions.h>
 #include <eel/eel-marshal.h>
+#include <gtk/gtk.h>
 #include <gtk/gtkcheckmenuitem.h>
 #include <gtk/gtkclipboard.h>
 #include <gtk/gtkiconfactory.h>
@@ -402,6 +403,8 @@
 						    gpointer   callback_data);
 static void action_paste_files_callback            (GtkAction *action,
 						    gpointer   callback_data);
+static void action_copy_or_move_files_to_folder_callback   (GtkAction *action,
+						    gpointer   callback_data);
 static void action_rename_callback                 (GtkAction *action,
 						    gpointer   callback_data);
 static void action_rename_select_all_callback      (GtkAction *action,
@@ -6077,7 +6080,7 @@
 
 	return g_list_reverse (tmp);
 }
-	
+
 static void
 copy_or_cut_files (FMDirectoryView *view,
 		   GList           *clipboard_contents,
@@ -6149,6 +6152,64 @@
 }
 
 static void
+action_copy_or_move_files_to_folder_callback (GtkAction *action,
+			    gpointer callback_data)
+{
+	/* Used variables */
+	FMDirectoryView *view = NULL;
+	GList *selection = NULL;
+	GList *source_uris = NULL;
+	GdkDragAction transfer_action = GDK_ACTION_COPY;
+	gchar *target_uri = NULL;
+	GConfClient *gconf = NULL;
+	GtkWidget *file_chooser = NULL;
+	gint response_id = 0;
+	
+	/* Get view and selected files */
+	view = FM_DIRECTORY_VIEW (callback_data);
+	selection = fm_directory_view_get_selection_for_file_transfer (view);
+
+	/* Convert selection to uris */
+	for (selection = selection; selection != NULL; selection = selection->next) {
+		source_uris = g_list_prepend (source_uris, nautilus_file_get_uri ((NautilusFile *) selection->data));
+	}
+	source_uris = g_list_reverse (source_uris);
+
+	/* Choose the right action */
+	if (strcmp (gtk_action_get_name (action), "MoveTo") == 0) transfer_action = GDK_ACTION_MOVE;
+	
+	/* Get last destination folder from GConf */
+	gconf = gconf_client_get_default ();
+	target_uri = gconf_client_get_string (gconf, "/apps/nautilus/preferences/last_transfer_folder", NULL);
+	if (target_uri == NULL)
+		target_uri = nautilus_get_home_directory_uri ();
+		
+	/* Get the destination folder */
+	file_chooser = gtk_file_chooser_dialog_new (_("Choose destination folder"), NULL, 
+		GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
+	gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (file_chooser), target_uri);
+	response_id = gtk_dialog_run (GTK_DIALOG (file_chooser));
+	gtk_widget_hide_all (GTK_WIDGET(file_chooser));
+	
+	if (response_id == GTK_RESPONSE_ACCEPT) {	
+		target_uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (file_chooser));
+
+		/* Do the transfer */
+		fm_directory_view_move_copy_items (source_uris, NULL, target_uri, transfer_action, 0, 0, view);
+		
+		/* Save last destination folder to GConf */
+		gconf_client_set_string (gconf, "/apps/nautilus/preferences/last_transfer_folder", target_uri, NULL);
+	}
+	
+	/* Free used data */
+	gtk_widget_destroy (GTK_WIDGET (file_chooser));
+	g_list_free (source_uris);
+	g_free (target_uri);
+	g_object_unref(gconf);
+	nautilus_file_list_free (selection);
+}
+
+static void
 action_cut_files_callback (GtkAction *action,
 			   gpointer callback_data)
 {
@@ -6957,6 +7018,15 @@
     NULL, NULL,                /* label, accelerator */
     N_("Move or copy files previously selected by a Cut or Copy command"),                   /* tooltip */ 
     G_CALLBACK (action_paste_files_callback) },
+  { "CopyTo", NULL,                  /* name, stock id */
+    N_("Copy into folder ..."), NULL,                /* label, accelerator */
+    N_("Prepare the selected files to be copied with a Paste command"),                   /* tooltip */ 
+    G_CALLBACK (action_copy_or_move_files_to_folder_callback) },
+  { "MoveTo", NULL,                  /* name, stock id */
+    N_("Move into folder ..."), NULL,                /* label, accelerator */
+    N_("Move or copy files previously selected by a Cut or Copy command"),                   /* tooltip */ 
+    G_CALLBACK (action_copy_or_move_files_to_folder_callback) },
+
   /* We make accelerator "" instead of null here to not inherit the stock
      accelerator for paste */
   { "Paste Files Into", GTK_STOCK_PASTE,                  /* name, stock id */


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