Help to solve bug 132326



Hi all,

I'm trying to provide a patch to bug 132326, since it seems to have been "abandoned" for some time. I attach the work I've done so far (against the gnome 2.12 branch), based on the original patch by Nirmal kumar and the comments provided, although there are two parts which I'm not sure how should be done:

1. Now the "delete" command in the popup menu is always enabled (if the user has activated the option to show the command). Should I do exactly the same checks done in fm-directory-view.c before enabling it (file is not read only, file is not an special link and file is neither home nor desktop directory) ??
2. When I delete a file with this patch, the file is deleted, but nautilus crashes... obviously I'm missing something, but I don't know what it is? Any idea?

Don't be too hard about the patch, this is my second patch for a gnome bug (and the first was a one-liner :P)...

Ferran
Index: fm-tree-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-tree-view.c,v
retrieving revision 1.18.2.1
diff -u -r1.18.2.1 fm-tree-view.c
--- fm-tree-view.c	8 Nov 2005 22:30:23 -0000	1.18.2.1
+++ fm-tree-view.c	3 Jan 2006 21:16:13 -0000
@@ -104,6 +104,7 @@
 	GtkWidget *popup_paste;
 	GtkWidget *popup_rename;
 	GtkWidget *popup_trash;
+	GtkWidget *popup_delete;
 	GtkWidget *popup_properties;
 	GtkWidget *popup_unmount_separator;
 	GtkWidget *popup_unmount;
@@ -118,6 +119,7 @@
 } PrependURIParameters;
 
 static GdkAtom copied_files_atom;
+static gboolean show_delete_command_auto_value;
 
 enum {
 	GNOME_COPIED_FILES
@@ -741,6 +743,13 @@
 		gtk_widget_set_sensitive (view->details->popup_trash, can_move_uri_to_trash (uri));
 		g_free (uri);
 		
+		if (show_delete_command_auto_value) {
+			gtk_widget_show (view->details->popup_delete);
+			gtk_widget_set_sensitive (view->details->popup_delete, TRUE);
+		} else {
+			gtk_widget_hide (view->details->popup_delete);
+		}
+		
 		volume = fm_tree_model_get_volume_for_root_node_file (view->details->child_model, view->details->popup_file);
 		if (volume) {
 			show_unmount = TRUE;
@@ -1036,6 +1045,87 @@
 	g_free (directory_uri);
 }
 
+static GtkWindow *
+fm_tree_view_get_containing_window (FMTreeView *view)
+{
+	GtkWidget *window;
+
+	g_assert (FM_IS_TREE_VIEW (view));
+
+	window = gtk_widget_get_ancestor (GTK_WIDGET (view), GTK_TYPE_WINDOW);
+	if (window == NULL) {
+		return NULL;
+	}
+
+	return GTK_WINDOW (window);
+}
+
+static char *
+file_name_from_uri (const char *uri)
+{
+	NautilusFile *file;
+	char *file_name;
+	
+	file = nautilus_file_get (uri);
+	file_name = nautilus_file_get_display_name (file);
+	nautilus_file_unref (file);
+
+	return file_name;	
+}
+
+static gboolean
+confirm_delete_directly (FMTreeView *view,
+			 char *directory_uri)
+{
+	GtkDialog *dialog;
+	char *file_name;
+	char *prompt;
+	int response;
+
+	file_name = file_name_from_uri (directory_uri);
+	
+	prompt = g_strdup_printf (_("Are you sure you want to permanently delete \"%s\"?"), 
+				  file_name);
+	g_free (file_name);
+	
+	dialog = eel_show_yes_no_dialog
+		(prompt,
+		 _("If you delete an item, it is permanently lost."),
+	         _("Delete?"), GTK_STOCK_DELETE, GTK_STOCK_CANCEL,
+		fm_tree_view_get_containing_window (view));
+		 
+	g_free (prompt);
+	
+	response = gtk_dialog_run (dialog);
+	
+	gtk_object_destroy (GTK_OBJECT(dialog));	
+	
+	return (response == GTK_RESPONSE_YES);
+}
+
+static void
+fm_tree_view_delete_cb (GtkWidget *menu_item,
+		        FMTreeView *view)
+{
+	GList *uri_list;
+	char *directory_uri;
+		
+	if (!show_delete_command_auto_value) {
+		return;
+	}
+	
+	directory_uri = nautilus_file_get_uri (view->details->popup_file);
+	
+	if (confirm_delete_directly (view, (char *)directory_uri)) {
+		uri_list = NULL;
+		uri_list = g_list_prepend (uri_list, g_strdup (directory_uri));
+		
+		nautilus_file_operations_delete (uri_list, GTK_WIDGET(view));
+		eel_g_list_free_deep (uri_list);
+	}
+	g_free (directory_uri);
+}
+
 static void
 fm_tree_view_properties_cb (GtkWidget *menu_item,
 			    FMTreeView *view)
@@ -1189,6 +1279,15 @@
 	gtk_menu_shell_append (GTK_MENU_SHELL (popup), menu_item);
 	view->details->popup_trash = menu_item;
 	
+	/* add the "delete" menu item */
+	menu_item = gtk_menu_item_new_with_mnemonic (_("_Delete"));
+	g_signal_connect (menu_item, "activate",
+			  G_CALLBACK (fm_tree_view_delete_cb),
+			  view);
+	gtk_widget_show (menu_item);
+	gtk_menu_shell_append (GTK_MENU_SHELL (popup), menu_item);
+	view->details->popup_delete = menu_item;
+	
 	separator_item = gtk_separator_menu_item_new ();
 	gtk_widget_show (separator_item);
 	gtk_menu_shell_append (GTK_MENU_SHELL (popup), separator_item);
@@ -1387,6 +1486,15 @@
 static void
 fm_tree_view_init (FMTreeView *view)
 {
+	static gboolean setup_autos = FALSE;
+
+	if (setup_autos == FALSE) {
+		eel_preferences_add_auto_boolean (NAUTILUS_PREFERENCES_ENABLE_DELETE,
+						  &show_delete_command_auto_value);
+		setup_autos = TRUE;	
+	}
+	
+
 	view->details = g_new0 (FMTreeViewDetails, 1);
 	
 	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (view), 



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