summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandru Pandelea <alexandru.pandelea@gmail.com>2016-08-05 22:46:50 +0300
committerAlexandru Pandelea <alexandru.pandelea@gmail.com>2016-08-05 22:46:50 +0300
commit500d629bedf6a46d876c261c55e2fbe14b06aa2d (patch)
treed7c8b13e6aae5d1996fb58a61b423bd34ff84eff
parentad5c2bf458365014d7618176a76df8f3de98f7df (diff)
downloadnautilus-500d629bedf6a46d876c261c55e2fbe14b06aa2d.tar.gz
Fix multiple issues
The following problems were fixed: - files weren't selected when operation was finished - conflict label wasn't ellipsizing right - cancel button was not working - in replace mode, the replaced part weren't highlighted - the rows of the listboxes didn't always have the same height - segmentation fault if quiting dialog while checking for conflicts - the conflict message for non unique new names was not appropriate, as it was meant for conflicts with files that already exist
-rw-r--r--src/nautilus-batch-rename-utilities.c91
-rw-r--r--src/nautilus-batch-rename-utilities.h3
-rw-r--r--src/nautilus-batch-rename.c265
-rw-r--r--src/nautilus-directory-private.h2
-rw-r--r--src/nautilus-directory.c23
-rw-r--r--src/nautilus-directory.h2
-rw-r--r--src/nautilus-file.c115
-rw-r--r--src/nautilus-files-view.c20
-rw-r--r--src/resources/ui/nautilus-batch-rename-dialog.ui7
9 files changed, 325 insertions, 203 deletions
diff --git a/src/nautilus-batch-rename-utilities.c b/src/nautilus-batch-rename-utilities.c
index 50aebf7af..5b40ed2c1 100644
--- a/src/nautilus-batch-rename-utilities.c
+++ b/src/nautilus-batch-rename-utilities.c
@@ -60,7 +60,7 @@ batch_rename_replace (gchar *string,
return new_string;
}
- if (strcmp (substr, "") == 0) {
+ if (g_strcmp0 (substr, "") == 0) {
g_string_append (new_string, string);
return new_string;
@@ -76,10 +76,91 @@ batch_rename_replace (gchar *string,
n_splits = g_strv_length (splitted_string);
for (i = 0; i < n_splits; i++) {
- g_string_append (new_string, splitted_string[i]);
+ g_string_append (new_string, splitted_string[i]);
- if (i != n_splits - 1)
- g_string_append (new_string, replacement);
+ if (i != n_splits - 1)
+ g_string_append (new_string, replacement);
+ }
+
+ g_strfreev (splitted_string);
+
+ return new_string;
+}
+
+static GString*
+escape_ampersand (const gchar *string)
+{
+ GString *new_string;
+ gchar **splitted_string;
+ gint i, n_splits;
+
+ new_string = g_string_new ("");
+
+ splitted_string = g_strsplit (string, "&", -1);
+ if (splitted_string == NULL) {
+ new_string = g_string_append (new_string, string);
+
+ return new_string;
+ }
+
+ n_splits = g_strv_length (splitted_string);
+
+ for (i = 0; i < n_splits; i++) {
+ new_string = g_string_append (new_string, splitted_string[i]);
+
+ if (i != n_splits - 1)
+ new_string = g_string_append (new_string,"&amp;");
+ }
+
+ g_strfreev (splitted_string);
+
+ return new_string;
+}
+
+
+GString*
+batch_rename_replace_label_text (gchar *string,
+ const gchar *substr)
+{
+ GString *new_string, *token;
+ gchar **splitted_string;
+ gint i, n_splits;
+
+ new_string = g_string_new ("");
+
+ if (substr == NULL || g_strcmp0 (substr, "") == 0) {
+ token = escape_ampersand (string);
+ new_string = g_string_append (new_string, token->str);
+ g_string_free (token, TRUE);
+
+ return new_string;
+ }
+
+ splitted_string = g_strsplit (string, substr, -1);
+ if (splitted_string == NULL) {
+ token = escape_ampersand (string);
+ new_string = g_string_append (new_string, token->str);
+ g_string_free (token, TRUE);
+
+ return new_string;
+ }
+
+ n_splits = g_strv_length (splitted_string);
+
+ for (i = 0; i < n_splits; i++) {
+ token = escape_ampersand (splitted_string[i]);
+ new_string = g_string_append (new_string, token->str);
+
+ g_string_free (token, TRUE);
+
+ if (i != n_splits - 1) {
+ token = escape_ampersand (substr);
+ g_string_append_printf (new_string,
+ "<span background=\'#FF8C00\'>%s</span>",
+ token->str);
+
+ g_string_free (token, TRUE);
+ }
}
g_strfreev (splitted_string);
@@ -164,7 +245,7 @@ batch_rename_format (NautilusFile *file,
base_name = g_malloc (MAX_FILE_LEN);
g_utf8_strncpy (base_name, name, end_offset);
- new_name = g_string_append (new_name, name);
+ new_name = g_string_append (new_name, base_name);
added_tag = TRUE;
g_free (name);
diff --git a/src/nautilus-batch-rename-utilities.h b/src/nautilus-batch-rename-utilities.h
index f9233e880..cc2c2704e 100644
--- a/src/nautilus-batch-rename-utilities.h
+++ b/src/nautilus-batch-rename-utilities.h
@@ -56,4 +56,7 @@ gboolean file_name_changed (GList *selection,
GString *old_name,
gchar *parent_uri);
+GString* batch_rename_replace_label_text (gchar *string,
+ const gchar *substr);
+
#endif /* NAUTILUS_BATCH_RENAME_UTILITIES_H */ \ No newline at end of file
diff --git a/src/nautilus-batch-rename.c b/src/nautilus-batch-rename.c
index e3c7e4890..04ba8e1c2 100644
--- a/src/nautilus-batch-rename.c
+++ b/src/nautilus-batch-rename.c
@@ -64,6 +64,7 @@ struct _NautilusBatchRename
GList *listbox_rows_right;
GList *listbox_labels_new;
GList *listbox_labels_old;
+ GList *listbox_icons;
GtkSizeGroup *size_group;
GList *selection;
@@ -90,11 +91,8 @@ struct _NautilusBatchRename
GList *duplicates;
GList *distinct_parents;
GTask *conflict_task;
- GTask *labels_task;
- GCancellable *labels_cancellable;
GCancellable *conflict_cancellable;
gboolean checking_conflicts;
- gboolean updating_labels;
/* starting tag position, -1 if tag is missing and
* -2 if tag can't be added at all */
@@ -109,6 +107,9 @@ struct _NautilusBatchRename
GtkWidget *preselected_row1;
GtkWidget *preselected_row2;
+
+ gint row_height;
+ gboolean rename_clicked;
};
static void file_names_widget_entry_on_changed (NautilusBatchRename *dialog);
@@ -576,8 +577,6 @@ static void
rename_files_on_names_accepted (NautilusBatchRename *dialog,
GList *new_names)
{
- gtk_window_close (GTK_WINDOW (dialog));
-
/* do the actual rename here */
nautilus_file_batch_rename (dialog->selection, new_names, NULL, NULL);
}
@@ -626,7 +625,6 @@ create_left_row_for_label (NautilusBatchRename *dialog,
gtk_list_box_row_set_selectable (GTK_LIST_BOX_ROW (row), TRUE);
dialog->listbox_labels_old = g_list_append (dialog->listbox_labels_old, label_old);
- gtk_size_group_add_widget (dialog->size_group, label_old);
gtk_container_add (GTK_CONTAINER (row), label_old);
gtk_widget_show_all (row);
@@ -634,6 +632,60 @@ create_left_row_for_label (NautilusBatchRename *dialog,
return row;
}
+static void
+update_rows_height (NautilusBatchRename *dialog)
+{
+ GList *l;
+ gboolean height_changed;
+ GtkAllocation allocation;
+
+ gtk_widget_get_allocation (dialog->listbox_labels_old->data, &allocation);
+
+ height_changed = FALSE;
+
+ /* check if maximum height has changed */
+ for (l = dialog->listbox_labels_new; l != NULL; l = l->next) {
+ gtk_widget_get_allocation (GTK_WIDGET (l->data), &allocation);
+
+ if (allocation.height > dialog->row_height) {
+ dialog->row_height = allocation.height;
+ height_changed = TRUE;
+ }
+ }
+
+ for (l = dialog->listbox_labels_old; l != NULL; l = l->next) {
+ gtk_widget_get_allocation (GTK_WIDGET (l->data), &allocation);
+
+ if (allocation.height > dialog->row_height) {
+ dialog->row_height = allocation.height;
+ height_changed = TRUE;
+ }
+ }
+
+ for (l = dialog->listbox_icons; l != NULL; l = l->next) {
+ gtk_widget_get_allocation (GTK_WIDGET (l->data), &allocation);
+
+ if (allocation.height > dialog->row_height) {
+ dialog->row_height = allocation.height;
+ height_changed = TRUE;
+ }
+ }
+
+ if (height_changed) {
+ for (l = dialog->listbox_icons; l != NULL; l = l->next) {
+ g_object_set (G_OBJECT (l->data), "height-request", dialog->row_height, NULL);
+ }
+
+ for (l = dialog->listbox_labels_new; l != NULL; l = l->next) {
+ g_object_set (G_OBJECT (l->data), "height-request", dialog->row_height, NULL);
+ }
+
+ for (l = dialog->listbox_labels_old; l != NULL; l = l->next) {
+ g_object_set (G_OBJECT (l->data), "height-request", dialog->row_height, NULL);
+ }
+ }
+}
+
static GtkWidget*
create_right_row_for_label (NautilusBatchRename *dialog,
const gchar *new_text,
@@ -654,7 +706,6 @@ create_right_row_for_label (NautilusBatchRename *dialog,
NULL);
gtk_label_set_ellipsize (GTK_LABEL (label_new), PANGO_ELLIPSIZE_END);
- gtk_size_group_add_widget (dialog->size_group, label_new);
gtk_list_box_row_set_selectable (GTK_LIST_BOX_ROW (row), TRUE);
@@ -677,9 +728,14 @@ create_middle_row_for_label (NautilusBatchRename *dialog,
g_object_set_data (G_OBJECT (row), "show-separator", GINT_TO_POINTER (show_separator));
- icon = gtk_image_new_from_icon_name ("media-playlist-consecutive-symbolic",
- GTK_ICON_SIZE_SMALL_TOOLBAR);
- g_object_set (icon, "height-request", 20, NULL);
+ icon = g_object_new (GTK_TYPE_LABEL,
+ "label","→",
+ "hexpand", FALSE,
+ "xalign", 1.0,
+ "margin-start", 6,
+ NULL);
+
+ dialog->listbox_icons = g_list_append (dialog->listbox_icons, icon);
gtk_list_box_row_set_selectable (GTK_LIST_BOX_ROW (row), TRUE);
@@ -690,6 +746,32 @@ create_middle_row_for_label (NautilusBatchRename *dialog,
}
static void
+batch_rename_dialog_on_response (NautilusBatchRename *dialog,
+ gint response_id,
+ gpointer user_data)
+{
+ if (response_id == GTK_RESPONSE_OK) {
+ /* wait for checking conflicts to finish, to be sure that
+ * the rename can actually take place */
+ if (dialog->checking_conflicts) {
+ dialog->rename_clicked = TRUE;
+ return;
+ }
+
+ if (!gtk_widget_is_sensitive (dialog->rename_button))
+ return;
+
+ /* if names are all right call rename_files_on_names_accepted*/
+ rename_files_on_names_accepted (dialog, dialog->new_names);
+ }
+
+ if (dialog->conflict_cancellable)
+ g_cancellable_cancel (dialog->conflict_cancellable);
+
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
+static void
fill_display_listbox (NautilusBatchRename *dialog)
{
GtkWidget *row;
@@ -703,6 +785,9 @@ fill_display_listbox (NautilusBatchRename *dialog)
dialog->listbox_rows_middle = NULL;
dialog->listbox_rows_right = NULL;
+ gtk_size_group_add_widget (dialog->size_group, dialog->right_listbox);
+ gtk_size_group_add_widget (dialog->size_group, dialog->left_listbox);
+
/* add rows to a list so that they can be removed when the renaming
* result changes */
for (l1 = dialog->new_names, l2 = dialog->selection; l1 != NULL || l2 != NULL; l1 = l1->next, l2 = l2->next) {
@@ -747,7 +832,7 @@ select_nth_conflict (NautilusBatchRename *dialog)
{
GList *l, *l2;
GString *file_name, *display_text, *new_name;
- gint n, nth_conflict;
+ gint n, nth_conflict, name_occurances;
NautilusFile *file;
GtkAdjustment *adjustment;
GtkAllocation allocation;
@@ -805,14 +890,26 @@ select_nth_conflict (NautilusBatchRename *dialog)
gtk_widget_get_allocation (GTK_WIDGET (l->data), &allocation);
gtk_adjustment_set_value (adjustment, (allocation.height + 1)*n);
- if (strstr (file_name->str, "/") == NULL)
- g_string_append_printf (display_text,
- "\"%s\" would conflict with an existing file.",
- file_name->str);
- else
+ if (strstr (file_name->str, "/") == NULL) {
+ name_occurances = 0;
+ for (l = dialog->new_names; l != NULL; l = l->next) {
+ new_name = l->data;
+ if (g_string_equal (new_name, file_name))
+ name_occurances++;
+ }
+ if (name_occurances > 1)
+ g_string_append_printf (display_text,
+ "\"%s\" would not be a unique new name",
+ file_name->str);
+ else
+ g_string_append_printf (display_text,
+ "\"%s\" would conflict with an existing file.",
+ file_name->str);
+ } else {
g_string_append_printf (display_text,
"\"%s\" has unallowed character '/'.",
file_name->str);
+ }
gtk_label_set_label (GTK_LABEL (dialog->conflict_label),
display_text->str);
@@ -847,75 +944,6 @@ move_next_conflict_up (NautilusBatchRename *dialog)
}
static void
-update_labels_async_thread (GTask *task,
- gpointer object,
- gpointer task_data,
- GCancellable *cancellable)
-{
- NautilusBatchRename *dialog;
- NautilusFile *file;
- GList *l1, *l2, *new_names;
- GtkLabel *label;
- GString *new_name;
- gchar *old_name;
-
- dialog = NAUTILUS_BATCH_RENAME (object);
-
- new_names = batch_rename_get_new_names (dialog);
-
- /* Update labels in the listbox */
- for (l1 = new_names, l2 = dialog->listbox_labels_new; l1 != NULL && l2 != NULL; l1 = l1->next, l2 = l2->next) {
- if (g_cancellable_is_cancelled (cancellable))
- break;
-
- label = GTK_LABEL (l2->data);
- new_name = l1->data;
-
- gtk_label_set_text (label, new_name->str);
- }
-
- for (l1 = dialog->selection, l2 = dialog->listbox_labels_old; l1 != NULL && l2 != NULL; l1 = l1->next, l2 = l2->next) {
- if (g_cancellable_is_cancelled (cancellable))
- break;
-
- label = GTK_LABEL (l2->data);
- file = NAUTILUS_FILE (l1->data);
-
- old_name = nautilus_file_get_name (file);
-
- gtk_label_set_text (label, old_name);
-
- g_free (old_name);
- }
-
- g_list_free_full (new_names, string_free);
-
- dialog->updating_labels = FALSE;
-
- g_task_return_pointer (task, object, NULL);
-}
-
-static void
-update_labels_async (NautilusBatchRename *dialog,
- gint io_priority,
- GAsyncReadyCallback callback,
- gpointer user_data)
-{
- if (dialog->updating_labels)
- g_cancellable_cancel (dialog->labels_cancellable);
-
- dialog->labels_cancellable = g_cancellable_new ();
-
- dialog->updating_labels = TRUE;
- dialog->labels_task = g_task_new (dialog, dialog->labels_cancellable, callback, user_data);
-
- g_task_set_priority (dialog->labels_task, io_priority);
- g_task_run_in_thread (dialog->labels_task, update_labels_async_thread);
-
- g_object_unref (dialog->labels_task);
-}
-
-static void
update_listbox (NautilusBatchRename *dialog)
{
GList *l1, *l2;
@@ -937,11 +965,21 @@ update_listbox (NautilusBatchRename *dialog)
old_name = nautilus_file_get_name (file);
- gtk_label_set_label (label, old_name);
+ if (dialog->mode == NAUTILUS_BATCH_RENAME_FORMAT) {
+ gtk_label_set_label (label, old_name);
+ } else {
+ new_name = batch_rename_replace_label_text (old_name,
+ gtk_entry_get_text (GTK_ENTRY (dialog->find_entry)));
+ gtk_label_set_markup (GTK_LABEL (label), new_name->str);
+
+ g_string_free (new_name, TRUE);
+ }
g_free (old_name);
}
+ update_rows_height (dialog);
+
/* check if there are name conflicts and display them if they exist */
if (dialog->duplicates != NULL) {
gtk_widget_set_sensitive (dialog->rename_button, FALSE);
@@ -966,6 +1004,15 @@ update_listbox (NautilusBatchRename *dialog)
if (dialog->duplicates == NULL && !gtk_widget_is_sensitive (dialog->rename_button))
gtk_widget_set_sensitive (dialog->rename_button, TRUE);
}
+
+ /* if the rename button was clicked and there's no conflict, then start renaming */
+ if (dialog->rename_clicked && dialog->duplicates == NULL) {
+ batch_rename_dialog_on_response (dialog, GTK_RESPONSE_OK, NULL);
+ }
+
+ if (dialog->rename_clicked && dialog->duplicates != NULL) {
+ dialog->rename_clicked = FALSE;
+ }
}
@@ -1038,6 +1085,9 @@ list_has_duplicates_callback (GObject *object,
dialog = NAUTILUS_BATCH_RENAME (object);
+ if (g_cancellable_is_cancelled (dialog->conflict_cancellable))
+ return;
+
update_listbox (dialog);
}
@@ -1253,6 +1303,7 @@ tag_removed (NautilusBatchRename *dialog,
entry_text->str + old_position + strlen (tag_part->str));
gtk_entry_set_text (GTK_ENTRY (dialog->name_entry), new_entry_text->str);
+ gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), old_position);
g_string_free (new_entry_text, TRUE);
return_value = TRUE;
@@ -1332,9 +1383,6 @@ file_names_widget_entry_on_changed (NautilusBatchRename *dialog)
if (dialog->conflict_cancellable != NULL)
g_cancellable_cancel (dialog->conflict_cancellable);
- if (dialog->updating_labels)
- g_cancellable_cancel (dialog->labels_cancellable);
-
if(dialog->selection == NULL)
return;
@@ -1364,11 +1412,6 @@ file_names_widget_entry_on_changed (NautilusBatchRename *dialog)
dialog->new_names = batch_rename_get_new_names (dialog);
dialog->checked_parents = 0;
- /*update_labels_async (dialog,
- G_PRIORITY_DEFAULT,
- NULL,
- NULL);*/
-
list_has_duplicates_async (dialog,
G_PRIORITY_DEFAULT,
list_has_duplicates_callback,
@@ -1376,21 +1419,6 @@ file_names_widget_entry_on_changed (NautilusBatchRename *dialog)
}
static void
-file_names_widget_on_activate (NautilusBatchRename *dialog)
-{
- /* wait for checking conflicts to finish, to be sure that
- * the rename can actually take place */
- while (dialog->checking_conflicts){
- }
-
- if (!gtk_widget_is_sensitive (dialog->rename_button))
- return;
-
- /* if names are all right call rename_files_on_names_accepted*/
- rename_files_on_names_accepted (dialog, dialog->new_names);
-}
-
-static void
batch_rename_mode_changed (NautilusBatchRename *dialog)
{
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->format_mode_button))) {
@@ -1634,6 +1662,12 @@ nautilus_batch_rename_initialize_actions (NautilusBatchRename *dialog)
}
static void
+file_names_widget_on_activate (NautilusBatchRename *dialog)
+{
+ batch_rename_dialog_on_response (dialog, GTK_RESPONSE_OK, NULL);
+}
+
+static void
nautilus_batch_rename_finalize (GObject *object)
{
NautilusBatchRename *dialog;
@@ -1643,12 +1677,6 @@ nautilus_batch_rename_finalize (GObject *object)
if (dialog->checking_conflicts) {
g_cancellable_cancel (dialog->conflict_cancellable);
- g_object_unref (dialog->conflict_task);
- }
-
- if (dialog->updating_labels) {
- g_cancellable_cancel (dialog->labels_cancellable);
- g_object_unref (dialog->labels_task);
}
g_list_free (dialog->listbox_rows_left);
@@ -1656,6 +1684,7 @@ nautilus_batch_rename_finalize (GObject *object)
g_list_free (dialog->listbox_rows_right);
g_list_free (dialog->listbox_labels_new);
g_list_free (dialog->listbox_labels_old);
+ g_list_free (dialog->listbox_icons);
for (l = dialog->selection_metadata; l != NULL; l = l->next) {
FileMetadata *metadata;
@@ -1736,6 +1765,7 @@ nautilus_batch_rename_class_init (NautilusBatchRenameClass *klass)
gtk_widget_class_bind_template_callback (widget_class, numbering_order_popover_closed);
gtk_widget_class_bind_template_callback (widget_class, move_next_conflict_up);
gtk_widget_class_bind_template_callback (widget_class, move_next_conflict_down);
+ gtk_widget_class_bind_template_callback (widget_class, batch_rename_dialog_on_response);
}
GtkWidget*
@@ -1810,16 +1840,21 @@ nautilus_batch_rename_init (NautilusBatchRename *self)
NULL);
gtk_label_set_ellipsize (GTK_LABEL (self->conflict_label), PANGO_ELLIPSIZE_END);
+ gtk_label_set_max_width_chars (GTK_LABEL (self->conflict_label), 1);
self->duplicates = NULL;
self->new_names = NULL;
self->checking_conflicts = FALSE;
+ self->rename_clicked = FALSE;
+
self->original_name_tag = 0;
self->numbering_tag = -1;
gtk_entry_set_text (GTK_ENTRY (self->name_entry),"[Original file name]");
+ self->row_height = -1;
+
g_signal_connect (self->left_listbox, "row-selected", G_CALLBACK (row_selected), self);
g_signal_connect (self->middle_listbox, "row-selected", G_CALLBACK (row_selected), self);
g_signal_connect (self->right_listbox, "row-selected", G_CALLBACK (row_selected), self);
diff --git a/src/nautilus-directory-private.h b/src/nautilus-directory-private.h
index 0128fa02a..dae1b96ce 100644
--- a/src/nautilus-directory-private.h
+++ b/src/nautilus-directory-private.h
@@ -185,8 +185,6 @@ void nautilus_directory_emit_files_changed (NautilusD
GList *changed_files);
void nautilus_directory_emit_change_signals (NautilusDirectory *directory,
GList *changed_files);
-void nautilus_directory_emit_change_selection (NautilusDirectory *directory,
- GList *selection);
void emit_change_signals_for_all_files (NautilusDirectory *directory);
void emit_change_signals_for_all_files_in_all_directories (void);
void nautilus_directory_emit_done_loading (NautilusDirectory *directory);
diff --git a/src/nautilus-directory.c b/src/nautilus-directory.c
index 13ecb4a22..3595406fe 100644
--- a/src/nautilus-directory.c
+++ b/src/nautilus-directory.c
@@ -44,7 +44,6 @@ enum {
FILES_CHANGED,
DONE_LOADING,
LOAD_ERROR,
- CHANGE_SELECTION,
LAST_SIGNAL
};
@@ -160,15 +159,6 @@ nautilus_directory_class_init (NautilusDirectoryClass *klass)
G_TYPE_FILE,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
- signals[CHANGE_SELECTION] =
- g_signal_new ("change-selection",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusDirectoryClass, change_selection),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1, G_TYPE_POINTER);
-
klass->get_file_list = real_get_file_list;
klass->is_editable = real_is_editable;
klass->handles_location = real_handles_location;
@@ -895,19 +885,6 @@ nautilus_directory_emit_files_changed (NautilusDirectory *directory,
}
void
-nautilus_directory_emit_change_selection (NautilusDirectory *directory,
- GList *selection)
-{
- nautilus_profile_start (NULL);
- if (selection != NULL) {
- g_signal_emit (directory,
- signals[CHANGE_SELECTION], 0,
- selection);
- }
- nautilus_profile_end (NULL);
-}
-
-void
nautilus_directory_emit_change_signals (NautilusDirectory *directory,
GList *changed_files)
{
diff --git a/src/nautilus-directory.h b/src/nautilus-directory.h
index ca4fae7c3..dc8c73253 100644
--- a/src/nautilus-directory.h
+++ b/src/nautilus-directory.h
@@ -103,8 +103,6 @@ typedef struct
void (* load_error) (NautilusDirectory *directory,
GError *error);
- void (* change_selection) (NautilusDirectory *directory,
- GList *selection);
/*** Virtual functions for subclasses to override. ***/
gboolean (* contains_file) (NautilusDirectory *directory,
NautilusFile *file);
diff --git a/src/nautilus-file.c b/src/nautilus-file.c
index 1b1d07a14..ff4b92038 100644
--- a/src/nautilus-file.c
+++ b/src/nautilus-file.c
@@ -1690,23 +1690,6 @@ nautilus_file_operation_free (NautilusFileOperation *op)
g_free (op);
}
-typedef struct {
- NautilusDirectory *directory;
- GList *files;
-} SelectionData;
-
-static gboolean
-change_selection_callback (gpointer user_data)
-{
- SelectionData *data;
-
- data = user_data;
- nautilus_directory_emit_change_selection (data->directory, data->files);
-
- g_free (data);
-
- return FALSE;
-}
void
nautilus_file_operation_complete (NautilusFileOperation *op,
@@ -1717,19 +1700,10 @@ nautilus_file_operation_complete (NautilusFileOperation *op,
* This makes it easier for some clients who see the "reverting"
* as "changing back".
*/
- SelectionData *data;
-
nautilus_file_operation_remove (op);
- if (g_list_length (op->files) == 0) {
+ if (g_list_length (op->files) == 0)
nautilus_file_changed (op->file);
- } else {
- data = g_malloc (sizeof (SelectionData*));
- data->directory = op->file->details->directory;
- data->files = op->files;
-
- g_idle_add (change_selection_callback, data);
- }
if (op->callback) {
(* op->callback) (op->file, result_file, error, op->callback_data);
@@ -1803,6 +1777,75 @@ rename_get_info_callback (GObject *source_object,
g_object_unref (new_info);
}
+ nautilus_file_operation_complete (op, NULL, error);
+ if (error) {
+ g_error_free (error);
+ }
+}
+
+typedef struct {
+ NautilusFileOperation *op;
+ NautilusFile *file;
+} BatchRenameData;
+
+static void
+batch_rename_get_info_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer callback_data)
+{
+ NautilusFileOperation *op;
+ NautilusDirectory *directory;
+ NautilusFile *existing_file;
+ char *old_uri;
+ char *new_uri;
+ const char *new_name;
+ GFileInfo *new_info;
+ GError *error;
+ BatchRenameData *data;
+
+ data = callback_data;
+
+ op = data->op;
+ op->file = data->file;
+
+ error = NULL;
+ new_info = g_file_query_info_finish (G_FILE (source_object), res, &error);
+ if (new_info != NULL) {
+ old_uri = nautilus_file_get_uri (op->file);
+
+ new_name = g_file_info_get_name (new_info);
+
+ directory = op->file->details->directory;
+
+ /* If there was another file by the same name in this
+ * directory and it is not the same file that we are
+ * renaming, mark it gone.
+ */
+ existing_file = nautilus_directory_find_file_by_name (directory, new_name);
+ if (existing_file != NULL && existing_file != op->file) {
+ nautilus_file_mark_gone (existing_file);
+ nautilus_file_changed (existing_file);
+ }
+
+ update_info_and_name (op->file, new_info);
+
+ new_uri = nautilus_file_get_uri (op->file);
+ nautilus_directory_moved (old_uri, new_uri);
+ g_free (new_uri);
+ g_free (old_uri);
+
+ /* the rename could have affected the display name if e.g.
+ * we're in a vfolder where the name comes from a desktop file
+ * and a rename affects the contents of the desktop file.
+ */
+ if (op->file->details->got_custom_display_name) {
+ nautilus_file_invalidate_attributes (op->file,
+ NAUTILUS_FILE_ATTRIBUTE_INFO |
+ NAUTILUS_FILE_ATTRIBUTE_LINK_INFO);
+ }
+
+ g_object_unref (new_info);
+ }
op->renamed_files++;
@@ -1813,9 +1856,11 @@ rename_get_info_callback (GObject *source_object,
if (g_list_length (op->files) == 0)
nautilus_file_operation_complete (op, NULL, error);
- if (error) {
- g_error_free (error);
- }
+ g_free (data);
+
+ if (error) {
+ g_error_free (error);
+ }
}
static void
@@ -1885,6 +1930,7 @@ real_batch_rename (GList *files,
GFile *new_file;
gboolean is_renameable_desktop_file, success, name_changed;
gchar *uri, *desktop_name, *old_name;
+ BatchRenameData *data;
error = NULL;
old_files = NULL;
@@ -2003,16 +2049,19 @@ real_batch_rename (GList *files,
op->cancellable,
&error);
+ data = g_new0 (BatchRenameData, 1);
+ data->op = op;
+ data->file = file;
+
new_files = g_list_append (new_files, new_file);
- op->file = file;
g_file_query_info_async (new_file,
NAUTILUS_FILE_DEFAULT_ATTRIBUTES,
0,
G_PRIORITY_DEFAULT,
op->cancellable,
- rename_get_info_callback,
- op);
+ batch_rename_get_info_callback,
+ data);
if (error != NULL) {
g_error_free (error);
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 2abaa3129..eb6e28c52 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -3928,18 +3928,6 @@ files_changed_callback (NautilusDirectory *directory,
}
static void
-change_selection_callback (NautilusDirectory *directory,
- GList *selection,
- gpointer callback_data)
-{
- NautilusFilesView *view;
-
- view = NAUTILUS_FILES_VIEW (callback_data);
-
- nautilus_view_set_selection (view, selection);
-}
-
-static void
done_loading_callback (NautilusDirectory *directory,
gpointer callback_data)
{
@@ -4011,9 +3999,6 @@ nautilus_files_view_add_subdirectory (NautilusFilesView *view,
g_signal_connect
(directory, "files-changed",
G_CALLBACK (files_changed_callback), view);
- g_signal_connect
- (directory, "change-selection",
- G_CALLBACK (change_selection_callback), view);
view->details->subdirectory_list = g_list_prepend (
view->details->subdirectory_list, directory);
@@ -7222,11 +7207,6 @@ finish_loading (NautilusFilesView *view)
(view->details->model, "files-changed",
G_CALLBACK (files_changed_callback), view);
- g_signal_connect (view->details->model,
- "change-selection",
- G_CALLBACK (change_selection_callback),
- view);
-
nautilus_profile_end (NULL);
}
diff --git a/src/resources/ui/nautilus-batch-rename-dialog.ui b/src/resources/ui/nautilus-batch-rename-dialog.ui
index ab15341e7..396ab79f8 100644
--- a/src/resources/ui/nautilus-batch-rename-dialog.ui
+++ b/src/resources/ui/nautilus-batch-rename-dialog.ui
@@ -5,6 +5,7 @@
<property name="modal">True</property>
<property name="window_position">center-on-parent</property>
<property name="destroy_with_parent">True</property>
+ <signal name="response" handler="batch_rename_dialog_on_response"/>
<child type="action">
<object class="GtkButton" id="cancel_button">
<property name="label" translatable="yes">_Cancel</property>
@@ -19,7 +20,6 @@
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="can_default">True</property>
- <signal name="clicked" handler="file_names_widget_on_activate" swapped="yes" />
<style>
<class name="suggested-action"/>
</style>
@@ -327,13 +327,14 @@
<object class="GtkBox" id="conflict_box">
<property name="orientation">horizontal</property>
<property name="spacing">6</property>
- <property name="visible">True</property>
+ <property name="visible">False</property>
<property name="margin-left">6</property>
<child>
<object class="GtkLabel" id="conflict_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="hexpand">False</property>
+ <property name="hexpand">True</property>
+ <property name="xalign">0</property>
</object>
<packing>
<property name="pack-type">start</property>