Re: [PATCH] New folder loses focus
- From: Nelson Benítez <gnel cenobioracing com>
- To: Alexander Larsson <alexl redhat com>
- Cc: nautilus-list gnome org
- Subject: Re: [PATCH] New folder loses focus
- Date: Sun, 19 Feb 2006 21:01:49 +0000
Alexander Larsson wrote:
> On Sun, 2006-02-12 at 23:49 +0000, Nelson Benítez wrote:
>
>>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
>
>
> The way the rename failure/success is gotten to the list view is a bit
> strange. I think you should just add a callback to fm_rename_file() that
> always gets called when the rename operation finished, with an argument
> that says whether is succeeded or not. This way there is no need for an
I tried this way and and made a new patch that I'm attaching to this
mail, and imho the result is more complicated code than the signal
approach, also see my comment in bugzilla[1].
[1] http://bugzilla.gnome.org/show_bug.cgi?id=326581#c6
> extra signal, nor do you have to watch the file_changed signal like
> that.
The file_changed code has to stay the same as its purpose it's to notice
when the new renamed file appears in the treeview and so tell the
activation code that the rename ended[1] so it can activate the file (it
reads the name from the treeview row).
[1] Actually, the rename operation yet ended in fm-error-reporting.c but
the activation code needs to wait till the new row appears in treeview.
> Also, make sure it correctly handles if the rename operation is
> cancelled. It doesn't look like your patch does that.
For this, I attached in bugzilla an update of the signal approach patch.
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 19 Feb 2006 18:28:50 -0000
@@ -36,7 +36,7 @@
#define NEW_NAME_TAG "Nautilus: new name"
#define MAXIMUM_DISPLAYED_FILE_NAME_LENGTH 50
-static void cancel_rename (NautilusFile *file, gboolean stop_timer);
+static void cancel_rename (NautilusFile *file, gpointer callback_data, gboolean stop_timer);
void
fm_report_error_loading_directory (NautilusFile *file,
@@ -257,26 +257,44 @@ rename_callback (NautilusFile *file, Gno
char *name;
g_assert (NAUTILUS_IS_FILE (file));
- g_assert (callback_data == NULL);
+ g_assert (callback_data != NULL);
name = g_object_get_data (G_OBJECT (file), NEW_NAME_TAG);
g_assert (name != NULL);
/* If rename failed, notify the user. */
fm_report_error_renaming_file (file, name, result, NULL);
- cancel_rename (file, TRUE);
+ cancel_rename (file, callback_data, TRUE);
+
+ /* List view sends a function pointer in callback_data */
+ GList *list;
+ list = (GList *) callback_data;
+ if (list->next != NULL && list->next->data != NULL) {
+ void (*callback_func) (NautilusFile *, gpointer, gboolean);
+ callback_func = list->next->data;
+ (* callback_func) (file, callback_data, result == GNOME_VFS_OK);
+ }
}
static void
cancel_rename_callback (gpointer callback_data)
{
- cancel_rename (NAUTILUS_FILE (callback_data), FALSE);
+ GList *list;
+ list = (GList *) callback_data;
+ cancel_rename (NAUTILUS_FILE (list->data), callback_data, FALSE);
+
+ if (list->next != NULL && list->next->data != NULL) {
+ void (*callback_func) (NautilusFile *, gpointer, gboolean);
+ callback_func = list->next->data;
+ (* callback_func) (NAUTILUS_FILE (list->data), callback_data, FALSE);
+ }
}
static void
-cancel_rename (NautilusFile *file, gboolean stop_timer)
+cancel_rename (NautilusFile *file, gpointer callback_data, gboolean stop_timer)
{
char *name;
+ GList *list;
name = g_object_get_data (G_OBJECT (file), NEW_NAME_TAG);
if (name == NULL) {
@@ -286,24 +304,31 @@ cancel_rename (NautilusFile *file, gbool
/* Cancel both the rename and the timed wait. */
nautilus_file_cancel (file, rename_callback, NULL);
if (stop_timer) {
- eel_timed_wait_stop (cancel_rename_callback, file);
+ eel_timed_wait_stop (cancel_rename_callback, callback_data);
}
+ list = (GList *) callback_data;
+ if (list->next == NULL) {
+ g_list_free (list);
+ }
+
/* Let go of file name. */
g_object_set_data (G_OBJECT (file), NEW_NAME_TAG, NULL);
}
void
fm_rename_file (NautilusFile *file,
- const char *new_name)
+ const char *new_name,
+ gpointer callback_data)
{
char *old_name, *wait_message;
+ GList *list;
g_return_if_fail (NAUTILUS_IS_FILE (file));
g_return_if_fail (new_name != NULL);
/* Stop any earlier rename that's already in progress. */
- cancel_rename (file, TRUE);
+ cancel_rename (file, callback_data, TRUE);
/* Attach the new name to the file. */
g_object_set_data_full (G_OBJECT (file),
@@ -317,11 +342,16 @@ fm_rename_file (NautilusFile *file,
old_name,
new_name);
g_free (old_name);
- eel_timed_wait_start (cancel_rename_callback, file, wait_message,
+ list = NULL;
+ if (callback_data == NULL) {
+ list = g_list_prepend (list, file);
+ callback_data = list;
+ }
+ eel_timed_wait_start (cancel_rename_callback, callback_data, wait_message,
NULL); /* FIXME bugzilla.gnome.org 42395: Parent this? */
g_free (wait_message);
/* Start the rename. */
nautilus_file_rename (file, new_name,
- rename_callback, NULL);
+ rename_callback, callback_data);
}
Index: src/file-manager/fm-error-reporting.h
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-error-reporting.h,v
retrieving revision 1.11
diff -p -u -r1.11 fm-error-reporting.h
--- src/file-manager/fm-error-reporting.h 12 Dec 2005 16:59:11 -0000 1.11
+++ src/file-manager/fm-error-reporting.h 19 Feb 2006 18:28:50 -0000
@@ -50,6 +50,7 @@ void fm_report_error_setting_group
/* FIXME bugzilla.gnome.org 42394: Should this file be renamed or should this function be moved? */
void fm_rename_file (NautilusFile *file,
- const char *new_name);
+ const char *new_name,
+ gpointer callback_data);
#endif /* FM_ERROR_REPORTING_H */
Index: src/file-manager/fm-icon-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-icon-view.c,v
retrieving revision 1.318
diff -p -u -r1.318 fm-icon-view.c
--- src/file-manager/fm-icon-view.c 12 Dec 2005 16:59:11 -0000 1.318
+++ src/file-manager/fm-icon-view.c 19 Feb 2006 18:28:54 -0000
@@ -2214,7 +2214,7 @@ fm_icon_view_icon_text_changed_callback
if (new_name[0] == '\0') {
return;
}
- fm_rename_file (file, new_name);
+ fm_rename_file (file, new_name, NULL);
}
static char *
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 19 Feb 2006 18:28:56 -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,9 @@ 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_callback (NautilusFile *file,
+ gpointer callback_data,
+ gboolean success);
@@ -200,6 +208,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 +999,14 @@ cell_renderer_edited (GtkCellRendererTex
/* Only rename if name actually changed */
if (strcmp (new_text, view->details->original_name) != 0) {
- fm_rename_file (file, new_text);
+ GList *callback_data = NULL;
+ callback_data = g_list_prepend (callback_data, view);
+ callback_data = g_list_prepend (callback_data, fm_list_view_rename_callback);
+ callback_data = g_list_prepend (callback_data, file);
+ fm_rename_file (file, new_text, callback_data);
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 +1543,48 @@ fm_list_view_clear (FMDirectoryView *vie
}
static void
+fm_list_view_rename_callback (NautilusFile *file, gpointer callback_data, gboolean success)
+{
+ GList *data;
+ data = (GList *) callback_data;
+ FMListView *view;
+ view = FM_LIST_VIEW (data->next->next->data);
+ if (view->details->renaming_file && !success) {
+ g_free (view->details->renaming_file);
+ view->details->renaming_file = NULL;
+ }
+
+ g_list_free (data);
+}
+
+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]