Skip to content

Commit 436a093

Browse files
Minabsapiclefebvre
authored andcommitted
file operations: Add duplicate button (#2841)
This feature appears in the GUI as a new button "Autorename" added to all the different conflict dialogs This uses the native "unique name" policy that allows copying/moving a file/folder with the same name than another in detination folder by renaming it automatically in this fashion: "example file (copy).txt" "example file (another copy).txt" "example file (3rd copy).txt" etc. The main interest of this new feature is its cumulation with the "apply to all" checkbox, allowing automatic renaming for all conflicts.
1 parent 1f48a27 commit 436a093

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

libnemo-private/nemo-file-conflict-dialog.c

+7
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ struct _NemoFileConflictDialogDetails
5757
GtkWidget *checkbox;
5858
GtkWidget *rename_button;
5959
GtkWidget *replace_button;
60+
GtkWidget *auto_rename_button;
6061
GtkWidget *dest_image;
6162
GtkWidget *src_image;
6263
};
@@ -558,6 +559,12 @@ nemo_file_conflict_dialog_init (NemoFileConflictDialog *fcd)
558559
_("_Skip"),
559560
CONFLICT_RESPONSE_SKIP,
560561
NULL);
562+
563+
details->auto_rename_button =
564+
gtk_dialog_add_button (dialog,
565+
_("Auto_rename"),
566+
CONFLICT_RESPONSE_AUTO_RENAME);
567+
561568
details->rename_button =
562569
gtk_dialog_add_button (dialog,
563570
_("Re_name"),

libnemo-private/nemo-file-conflict-dialog.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ struct _NemoFileConflictDialogClass {
6262
enum
6363
{
6464
CONFLICT_RESPONSE_SKIP = 1,
65-
CONFLICT_RESPONSE_REPLACE = 2,
66-
CONFLICT_RESPONSE_RENAME = 3,
65+
CONFLICT_RESPONSE_AUTO_RENAME = 2,
66+
CONFLICT_RESPONSE_REPLACE = 3,
67+
CONFLICT_RESPONSE_RENAME = 4
6768
};
6869

6970
GType nemo_file_conflict_dialog_get_type (void) G_GNUC_CONST;

libnemo-private/nemo-file-operations.c

+23-1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ typedef struct {
100100
gboolean skip_all_error;
101101
gboolean skip_all_conflict;
102102
gboolean merge_all;
103+
gboolean auto_rename_all;
103104
gboolean replace_all;
104105
gboolean delete_all;
105106
} CommonJob;
@@ -4616,7 +4617,7 @@ copy_move_file (CopyMoveJob *copy_job,
46164617

46174618
g_error_free (error);
46184619

4619-
if (unique_names) {
4620+
if (unique_names || job->auto_rename_all) {
46204621
g_object_unref (dest);
46214622
dest = get_unique_target_file (src, dest_dir, same_fs, *dest_fs_type, unique_name_nr++);
46224623
goto retry;
@@ -4666,6 +4667,13 @@ copy_move_file (CopyMoveJob *copy_job,
46664667
resp->new_name);
46674668
conflict_response_data_free (resp);
46684669
goto retry;
4670+
} else if (resp->id == CONFLICT_RESPONSE_AUTO_RENAME) {
4671+
if (resp->apply_to_all) {
4672+
job->auto_rename_all = TRUE;
4673+
}
4674+
unique_names = TRUE;
4675+
conflict_response_data_free (resp);
4676+
goto retry;
46694677
} else {
46704678
g_assert_not_reached ();
46714679
}
@@ -5130,6 +5138,7 @@ move_file_prepare (CopyMoveJob *move_job,
51305138
GError *error;
51315139
CommonJob *job;
51325140
gboolean overwrite;
5141+
gboolean auto_rename;
51335142
char *primary, *secondary, *details;
51345143
int response;
51355144
GFileCopyFlags flags;
@@ -5275,6 +5284,12 @@ move_file_prepare (CopyMoveJob *move_job,
52755284
goto retry;
52765285
}
52775286

5287+
if (job->auto_rename_all || auto_rename) {
5288+
g_object_unref (dest);
5289+
dest = get_unique_target_file (src, dest_dir, same_fs, *dest_fs_type, 1);
5290+
goto retry;
5291+
}
5292+
52785293
if (job->skip_all_conflict) {
52795294
goto out;
52805295
}
@@ -5307,6 +5322,13 @@ move_file_prepare (CopyMoveJob *move_job,
53075322
resp->new_name);
53085323
conflict_response_data_free (resp);
53095324
goto retry;
5325+
} else if (resp->id == CONFLICT_RESPONSE_AUTO_RENAME) {
5326+
if (resp->apply_to_all) {
5327+
job->auto_rename_all = TRUE;
5328+
}
5329+
auto_rename = TRUE;
5330+
conflict_response_data_free (resp);
5331+
goto retry;
53105332
} else {
53115333
g_assert_not_reached ();
53125334
}

0 commit comments

Comments
 (0)