Skip to content

Commit

Permalink
file operations: Add duplicate button (#2841)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Minabsapi authored and clefebvre committed Nov 15, 2021
1 parent 1f48a27 commit 436a093
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
7 changes: 7 additions & 0 deletions libnemo-private/nemo-file-conflict-dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ struct _NemoFileConflictDialogDetails
GtkWidget *checkbox;
GtkWidget *rename_button;
GtkWidget *replace_button;
GtkWidget *auto_rename_button;
GtkWidget *dest_image;
GtkWidget *src_image;
};
Expand Down Expand Up @@ -558,6 +559,12 @@ nemo_file_conflict_dialog_init (NemoFileConflictDialog *fcd)
_("_Skip"),
CONFLICT_RESPONSE_SKIP,
NULL);

details->auto_rename_button =
gtk_dialog_add_button (dialog,
_("Auto_rename"),
CONFLICT_RESPONSE_AUTO_RENAME);

details->rename_button =
gtk_dialog_add_button (dialog,
_("Re_name"),
Expand Down
5 changes: 3 additions & 2 deletions libnemo-private/nemo-file-conflict-dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ struct _NemoFileConflictDialogClass {
enum
{
CONFLICT_RESPONSE_SKIP = 1,
CONFLICT_RESPONSE_REPLACE = 2,
CONFLICT_RESPONSE_RENAME = 3,
CONFLICT_RESPONSE_AUTO_RENAME = 2,
CONFLICT_RESPONSE_REPLACE = 3,
CONFLICT_RESPONSE_RENAME = 4
};

GType nemo_file_conflict_dialog_get_type (void) G_GNUC_CONST;
Expand Down
24 changes: 23 additions & 1 deletion libnemo-private/nemo-file-operations.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ typedef struct {
gboolean skip_all_error;
gboolean skip_all_conflict;
gboolean merge_all;
gboolean auto_rename_all;
gboolean replace_all;
gboolean delete_all;
} CommonJob;
Expand Down Expand Up @@ -4616,7 +4617,7 @@ copy_move_file (CopyMoveJob *copy_job,

g_error_free (error);

if (unique_names) {
if (unique_names || job->auto_rename_all) {
g_object_unref (dest);
dest = get_unique_target_file (src, dest_dir, same_fs, *dest_fs_type, unique_name_nr++);
goto retry;
Expand Down Expand Up @@ -4666,6 +4667,13 @@ copy_move_file (CopyMoveJob *copy_job,
resp->new_name);
conflict_response_data_free (resp);
goto retry;
} else if (resp->id == CONFLICT_RESPONSE_AUTO_RENAME) {
if (resp->apply_to_all) {
job->auto_rename_all = TRUE;
}
unique_names = TRUE;
conflict_response_data_free (resp);
goto retry;
} else {
g_assert_not_reached ();
}
Expand Down Expand Up @@ -5130,6 +5138,7 @@ move_file_prepare (CopyMoveJob *move_job,
GError *error;
CommonJob *job;
gboolean overwrite;
gboolean auto_rename;
char *primary, *secondary, *details;
int response;
GFileCopyFlags flags;
Expand Down Expand Up @@ -5275,6 +5284,12 @@ move_file_prepare (CopyMoveJob *move_job,
goto retry;
}

if (job->auto_rename_all || auto_rename) {
g_object_unref (dest);
dest = get_unique_target_file (src, dest_dir, same_fs, *dest_fs_type, 1);
goto retry;
}

if (job->skip_all_conflict) {
goto out;
}
Expand Down Expand Up @@ -5307,6 +5322,13 @@ move_file_prepare (CopyMoveJob *move_job,
resp->new_name);
conflict_response_data_free (resp);
goto retry;
} else if (resp->id == CONFLICT_RESPONSE_AUTO_RENAME) {
if (resp->apply_to_all) {
job->auto_rename_all = TRUE;
}
auto_rename = TRUE;
conflict_response_data_free (resp);
goto retry;
} else {
g_assert_not_reached ();
}
Expand Down

0 comments on commit 436a093

Please sign in to comment.