[PATCH] New folder loses focus



I have attached a patch for "Bug 326581 – New folder loses focus", the
bugzilla page[1] has the details.

[1] http://bugzilla.gnome.org/show_bug.cgi?id=326581
Index: libnautilus-private/nautilus-file.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file.c,v
retrieving revision 1.380
diff -p -u -r1.380 nautilus-file.c
--- libnautilus-private/nautilus-file.c	28 Jan 2006 14:55:08 -0000	1.380
+++ libnautilus-private/nautilus-file.c	12 Feb 2006 21:45:06 -0000
@@ -115,6 +115,7 @@ typedef GList * (* ModifyListFunction) (
 enum {
 	CHANGED,
 	UPDATED_DEEP_COUNT_IN_PROGRESS,
+	RENAME_FAILED,
 	LAST_SIGNAL
 };
 
@@ -5709,6 +5710,11 @@ nautilus_file_invalidate_all_attributes 
 	nautilus_file_invalidate_attributes (file, all_attributes);
 }
 
+void
+nautilus_file_rename_failed (NautilusFile *file)
+{
+	g_signal_emit (file, signals[RENAME_FAILED], 0, file);
+}
 
 /**
  * nautilus_file_dump
@@ -6096,6 +6102,15 @@ nautilus_file_class_init (NautilusFileCl
 		              G_STRUCT_OFFSET (NautilusFileClass, updated_deep_count_in_progress),
 		              NULL, NULL,
 			      g_cclosure_marshal_VOID__VOID,
+		              G_TYPE_NONE, 0);
+
+	signals[RENAME_FAILED] =
+		g_signal_new ("rename_failed",
+		              G_TYPE_FROM_CLASS (class),
+		              G_SIGNAL_RUN_LAST,
+			      0,
+		              NULL, NULL,
+		              g_cclosure_marshal_VOID__VOID,
 		              G_TYPE_NONE, 0);
 	
 	g_type_class_add_private (class, sizeof (NautilusFileDetails));
Index: libnautilus-private/nautilus-file.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file.h,v
retrieving revision 1.111
diff -p -u -r1.111 nautilus-file.h
--- libnautilus-private/nautilus-file.h	16 Dec 2005 21:42:17 -0000	1.111
+++ libnautilus-private/nautilus-file.h	12 Feb 2006 21:45:08 -0000
@@ -352,6 +352,8 @@ void                    nautilus_file_li
 									 gpointer                        callback_data);
 void                    nautilus_file_list_cancel_call_when_ready       (NautilusFileListHandle         *handle);
 
+void                    nautilus_file_rename_failed                     (NautilusFile                   *file);
+
 /* Debugging */
 void                    nautilus_file_dump                              (NautilusFile                   *file);
 
Index: src/file-manager/fm-error-reporting.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-error-reporting.c,v
retrieving revision 1.41
diff -p -u -r1.41 fm-error-reporting.c
--- src/file-manager/fm-error-reporting.c	12 Jan 2006 14:24:21 -0000	1.41
+++ src/file-manager/fm-error-reporting.c	12 Feb 2006 21:45:09 -0000
@@ -145,6 +145,7 @@ fm_report_error_renaming_file (NautilusF
 	g_free (original_name_truncated);
 	g_free (new_name_truncated);
 
+	nautilus_file_rename_failed (file);
 	eel_show_error_dialog (_("The item could not be renamed."), message, parent_window);
 	g_free (message);
 }
Index: src/file-manager/fm-list-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-list-view.c,v
retrieving revision 1.265
diff -p -u -r1.265 fm-list-view.c
--- src/file-manager/fm-list-view.c	31 Jan 2006 00:23:55 -0000	1.265
+++ src/file-manager/fm-list-view.c	12 Feb 2006 21:45:12 -0000
@@ -111,6 +111,8 @@ struct FMListViewDetails {
 	GtkWidget *column_editor;
 
 	char *original_name;
+	char *renaming_file;
+	guint renaming_file_activate_timeout;
 };
 
 struct SelectionForeachData {
@@ -128,6 +130,9 @@ struct SelectionForeachData {
 /* We wait two seconds after row is collapsed to unload the subdirectory */
 #define COLLAPSE_TO_UNLOAD_DELAY 2000 
 
+/* Wait for the rename to end when activating a file being renamed */
+#define WAIT_FOR_RENAME_ON_ACTIVATE 200
+
 static int                      click_policy_auto_value;
 static char *              	default_sort_order_auto_value;
 static gboolean			default_sort_reversed_auto_value;
@@ -145,6 +150,8 @@ static void   fm_list_view_scale_font_si
 static void   fm_list_view_scroll_to_file                  (FMListView        *view,
 							    NautilusFile      *file);
 static void   fm_list_view_iface_init                      (NautilusViewIface *iface);
+static void   fm_list_view_rename_failed_callback          (NautilusFile      *file,
+							    FMListView        *view);
 
 
 
@@ -200,6 +207,20 @@ activate_selected_items (FMListView *vie
 	GList *file_list;
 	
 	file_list = fm_list_view_get_selection (FM_DIRECTORY_VIEW (view));
+	
+	if (view->details->renaming_file) {
+		if (! view->details->renaming_file_activate_timeout) {
+			view->details->renaming_file_activate_timeout =
+			g_timeout_add (WAIT_FOR_RENAME_ON_ACTIVATE, (GSourceFunc) activate_selected_items, view);
+		}
+		return;
+	}
+	
+	if (view->details->renaming_file_activate_timeout) {
+		g_source_remove (view->details->renaming_file_activate_timeout);
+		view->details->renaming_file_activate_timeout = 0;
+	}
+	
 	fm_directory_view_activate_files (FM_DIRECTORY_VIEW (view),
 					  file_list,
 					  NAUTILUS_WINDOW_OPEN_ACCORDING_TO_MODE,
@@ -977,9 +998,12 @@ cell_renderer_edited (GtkCellRendererTex
 
 	/* Only rename if name actually changed */
 	if (strcmp (new_text, view->details->original_name) != 0) {
+		g_signal_connect_object (file, "rename_failed",	
+			 G_CALLBACK (fm_list_view_rename_failed_callback), view, 0);
 		fm_rename_file (file, new_text);
 		g_free (view->details->original_name);
 		view->details->original_name = g_strdup (new_text);
+		view->details->renaming_file = g_strdup (new_text);
 	}
 	
 	nautilus_file_unref (file);
@@ -1516,9 +1540,42 @@ fm_list_view_clear (FMDirectoryView *vie
 }
 
 static void
+fm_list_view_rename_failed_callback (NautilusFile *file, FMListView *view)
+{
+	if (view->details->renaming_file) {
+		g_free (view->details->renaming_file);
+		view->details->renaming_file = NULL;
+	}
+}
+
+static void
 fm_list_view_file_changed (FMDirectoryView *view, NautilusFile *file, NautilusDirectory *directory)
 {
 	fm_list_model_file_changed (FM_LIST_VIEW (view)->details->model, file, directory);
+	
+	char *name;
+	FMListView *listview;
+	listview = FM_LIST_VIEW (view);
+	if (listview->details->renaming_file) {
+		name = nautilus_file_get_name (file);
+		if (strncmp (name, listview->details->renaming_file, strlen (name)) == 0) {
+			GtkTreeIter iter;
+			GtkTreeModel* tree_model;
+			GtkTreePath *file_path;
+			tree_model = GTK_TREE_MODEL (listview->details->model);
+	
+			if (fm_list_model_get_tree_iter_from_file (listview->details->model, file, directory, &iter)) {
+				// Select the new renamed file
+				file_path = gtk_tree_model_get_path (tree_model, &iter);
+				gtk_tree_view_set_cursor (listview->details->tree_view,
+							  file_path, NULL, FALSE);
+				gtk_tree_path_free (file_path);
+			}
+			g_free (listview->details->renaming_file);
+			listview->details->renaming_file = NULL;
+		}
+		g_free (name);
+	}
 }
 
 static GtkWidget *


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