summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntónio Fernandes <antoniof@gnome.org>2021-10-15 23:38:39 +0100
committerAntónio Fernandes <antoniof@gnome.org>2021-11-27 20:32:18 +0000
commit709b19a9767872a4d6c7c3e0b027573ae68cff41 (patch)
tree42aee0b28d239b5dea8bfb1860f8209fae8773e4
parent8deb6682213582ca7a08b3c2e48d67f9d46bf8f3 (diff)
downloadnautilus-709b19a9767872a4d6c7c3e0b027573ae68cff41.tar.gz
file-undo-operations: Set NULL dest for duplication
In src/nautilus-file-operations.c, the duplication operation is identified within the 'copy' code paths by having a NULL destination imply it's the same as the source parent dir. For consistency, adopt the same paradigm in the undo stack. Also, while we are at it, adopt autocleanup for some related strings.
-rw-r--r--src/nautilus-file-operations.c2
-rw-r--r--src/nautilus-file-undo-operations.c30
2 files changed, 22 insertions, 10 deletions
diff --git a/src/nautilus-file-operations.c b/src/nautilus-file-operations.c
index 6b0afd70e..0a081e67e 100644
--- a/src/nautilus-file-operations.c
+++ b/src/nautilus-file-operations.c
@@ -7113,7 +7113,7 @@ nautilus_file_operations_duplicate (GList *files,
job->common.undo_info =
nautilus_file_undo_info_ext_new (NAUTILUS_FILE_UNDO_OP_DUPLICATE,
g_list_length (files),
- src_dir, src_dir);
+ src_dir, NULL);
}
task = g_task_new (NULL, job->common.cancellable, copy_task_done, job);
diff --git a/src/nautilus-file-undo-operations.c b/src/nautilus-file-undo-operations.c
index 64f9ce76c..70123dace 100644
--- a/src/nautilus-file-undo-operations.c
+++ b/src/nautilus-file-undo-operations.c
@@ -435,10 +435,20 @@ ext_strings_func (NautilusFileUndoInfo *info,
NautilusFileUndoInfoExt *self = NAUTILUS_FILE_UNDO_INFO_EXT (info);
NautilusFileUndoOp op_type = nautilus_file_undo_info_get_op_type (info);
gint count = nautilus_file_undo_info_get_item_count (info);
- gchar *name = NULL, *source, *destination;
+ g_autofree gchar *name = NULL;
+ g_autofree gchar *source = NULL;
+ g_autofree gchar *destination = NULL;
source = g_file_get_path (self->src_dir);
- destination = g_file_get_path (self->dest_dir);
+
+ if (self->dest_dir == NULL)
+ {
+ g_assert (op_type == NAUTILUS_FILE_UNDO_OP_DUPLICATE);
+ }
+ else
+ {
+ destination = g_file_get_path (self->dest_dir);
+ }
if (count <= 1)
{
@@ -528,7 +538,7 @@ ext_strings_func (NautilusFileUndoInfo *info,
count);
*redo_description = g_strdup_printf (ngettext ("Duplicate %d item in “%s”",
"Duplicate %d items in “%s”", count),
- count, destination);
+ count, source);
*undo_label = g_strdup_printf (ngettext ("_Undo Duplicate %d item",
"_Undo Duplicate %d items", count),
@@ -541,7 +551,7 @@ ext_strings_func (NautilusFileUndoInfo *info,
{
*undo_description = g_strdup_printf (_("Delete “%s”"), name);
*redo_description = g_strdup_printf (_("Duplicate “%s” in “%s”"),
- name, destination);
+ name, source);
*undo_label = g_strdup (_("_Undo Duplicate"));
*redo_label = g_strdup (_("_Redo Duplicate"));
@@ -571,10 +581,6 @@ ext_strings_func (NautilusFileUndoInfo *info,
{
g_assert_not_reached ();
}
-
- g_free (name);
- g_free (source);
- g_free (destination);
}
static void
@@ -777,13 +783,19 @@ nautilus_file_undo_info_ext_new (NautilusFileUndoOp op_type,
{
NautilusFileUndoInfoExt *self;
+ g_assert (src_dir != NULL);
+ g_assert (target_dir != NULL || op_type == NAUTILUS_FILE_UNDO_OP_DUPLICATE);
+
self = g_object_new (NAUTILUS_TYPE_FILE_UNDO_INFO_EXT,
"op-type", op_type,
"item-count", item_count,
NULL);
self->src_dir = g_object_ref (src_dir);
- self->dest_dir = g_object_ref (target_dir);
+ if (target_dir != NULL)
+ {
+ self->dest_dir = g_object_ref (target_dir);
+ }
self->sources = g_queue_new ();
self->destinations = g_queue_new ();