diff options
author | Alexandru Pandelea <alexandru.pandelea@gmail.com> | 2016-10-16 19:28:12 +0300 |
---|---|---|
committer | Alexandru Pandelea <alexandru.pandelea@gmail.com> | 2016-10-26 20:26:35 +0300 |
commit | fc4135d8124157d2435d66aceea5958ed643227d (patch) | |
tree | 0ae7dc0b1ee3599e47b9e96b603812205a4ea5f9 /src/nautilus-file-undo-operations.c | |
parent | 6cc8fdedf68dec159f18cee7039ce0b8b5c1a77a (diff) | |
download | nautilus-fc4135d8124157d2435d66aceea5958ed643227d.tar.gz |
batch-rename: fix file reordering before the rename
There are cases where the files are not reordered correctly.
To fix this, the order of the files is checked until no more changes
are made.
In this patch, the reordering code is also extracted in a common function.
https://bugzilla.gnome.org/show_bug.cgi?id=771583
Diffstat (limited to 'src/nautilus-file-undo-operations.c')
-rw-r--r-- | src/nautilus-file-undo-operations.c | 125 |
1 files changed, 15 insertions, 110 deletions
diff --git a/src/nautilus-file-undo-operations.c b/src/nautilus-file-undo-operations.c index 61a789d0e..19d7d90ea 100644 --- a/src/nautilus-file-undo-operations.c +++ b/src/nautilus-file-undo-operations.c @@ -31,6 +31,9 @@ #include "nautilus-file-operations.h" #include "nautilus-file.h" #include "nautilus-file-undo-manager.h" +#include "nautilus-batch-rename-dialog.h" +#include "nautilus-batch-rename-utilities.h" + /* Since we use g_get_current_time for setting "orig_trash_time" in the undo * info, there are situations where the difference between this value and the @@ -1125,19 +1128,6 @@ batch_rename_redo_func (NautilusFileUndoInfo *info, GList *l, *files; NautilusFile *file; GFile *old_file; - GFile *new_file; - GList *l1; - GList *l2; - GList *l3; - GList *l4; - GList *l5; - GList *l6; - GList *l7; - gchar *file_name; - gchar *old_file_name; - GString *new_file_name; - GString *new_name; - GString *old_name; files = NULL; @@ -1149,48 +1139,12 @@ batch_rename_redo_func (NautilusFileUndoInfo *info, files = g_list_prepend (files, file); } - files = g_list_reverse (files); - - for (l1 = self->priv->new_display_names, l2 = files; l1 != NULL && l2 != NULL; l1 = l1->next, l2 = l2->next) - { - old_file_name = nautilus_file_get_name (NAUTILUS_FILE (l2->data)); - new_file_name = l1->data; - - for (l3 = files, l4 = self->priv->new_display_names, l5 = self->priv->old_display_names, l6 = self->priv->old_files, l7 = self->priv->new_files; - l3 != NULL && l4 != NULL && l5 != NULL && l6 != NULL && l7 != NULL; - l3 = l3->next, l4 = l4->next, l5 = l5->next, l6 = l6->next, l7 = l7->next) - { - file_name = nautilus_file_get_name (NAUTILUS_FILE (l3->data)); - if (l3 != l2 && g_strcmp0 (file_name, new_file_name->str) == 0) - { - file = NAUTILUS_FILE (l3->data); - new_name = l4->data; - old_name = l5->data; - old_file = l6->data; - new_file = l7->data; - - files = g_list_remove_link (files, l3); - self->priv->new_display_names = g_list_remove_link (self->priv->new_display_names, l4); - self->priv->old_display_names = g_list_remove_link (self->priv->old_display_names, l5); - self->priv->old_files = g_list_remove_link (self->priv->old_files, l6); - self->priv->new_files = g_list_remove_link (self->priv->new_files, l7); - - files = g_list_prepend (files, file); - self->priv->new_display_names = g_list_prepend (self->priv->new_display_names, new_name); - self->priv->old_display_names = g_list_prepend (self->priv->old_display_names, old_name); - self->priv->old_files = g_list_prepend (self->priv->old_files, old_file); - self->priv->new_files = g_list_prepend (self->priv->new_files, new_file); - - g_free (file_name); - - break; - } - - g_free (file_name); - } - - g_free (old_file_name); - } + batch_rename_sort_lists_for_rename (&files, + &self->priv->new_display_names, + &self->priv->old_display_names, + &self->priv->new_files, + &self->priv->old_files, + TRUE); nautilus_file_batch_rename (files, self->priv->new_display_names, file_undo_info_operation_callback, self); } @@ -1204,19 +1158,6 @@ batch_rename_undo_func (NautilusFileUndoInfo *info, GList *l, *files; NautilusFile *file; GFile *new_file; - GFile *old_file; - GList *l1; - GList *l2; - GList *l3; - GList *l4; - GList *l5; - GList *l6; - GList *l7; - gchar *file_name; - gchar *old_file_name; - GString *new_file_name; - GString *new_name; - GString *old_name; files = NULL; @@ -1228,48 +1169,12 @@ batch_rename_undo_func (NautilusFileUndoInfo *info, files = g_list_prepend (files, file); } - files = g_list_reverse (files); - - for (l1 = self->priv->old_display_names, l2 = files; l1 != NULL && l2 != NULL; l1 = l1->next, l2 = l2->next) - { - old_file_name = nautilus_file_get_name (NAUTILUS_FILE (l2->data)); - new_file_name = l1->data; - - for (l3 = files, l4 = self->priv->old_display_names, l5 = self->priv->new_display_names, l6 = self->priv->old_files, l7 = self->priv->new_files; - l3 != NULL && l4 != NULL && l5 != NULL && l6 != NULL && l7 != NULL; - l3 = l3->next, l4 = l4->next, l5 = l5->next, l6 = l6->next, l7 = l7->next) - { - file_name = nautilus_file_get_name (NAUTILUS_FILE (l3->data)); - if (l3 != l2 && g_strcmp0 (file_name, new_file_name->str) == 0) - { - file = NAUTILUS_FILE (l3->data); - new_name = l4->data; - old_name = l5->data; - old_file = l6->data; - new_file = l7->data; - - files = g_list_remove_link (files, l3); - self->priv->old_display_names = g_list_remove_link (self->priv->old_display_names, l4); - self->priv->new_display_names = g_list_remove_link (self->priv->new_display_names, l5); - self->priv->old_files = g_list_remove_link (self->priv->old_files, l6); - self->priv->new_files = g_list_remove_link (self->priv->new_files, l7); - - files = g_list_prepend (files, file); - self->priv->old_display_names = g_list_prepend (self->priv->old_display_names, new_name); - self->priv->new_display_names = g_list_prepend (self->priv->new_display_names, old_name); - self->priv->old_files = g_list_prepend (self->priv->old_files, old_file); - self->priv->new_files = g_list_prepend (self->priv->new_files, new_file); - - g_free (file_name); - - break; - } - - g_free (file_name); - } - - g_free (old_file_name); - } + batch_rename_sort_lists_for_rename (&files, + &self->priv->old_display_names, + &self->priv->new_display_names, + &self->priv->old_files, + &self->priv->new_files, + TRUE); nautilus_file_batch_rename (files, self->priv->old_display_names, file_undo_info_operation_callback, self); } |