From 2a294282863634721b46a0a386aa10414de78bab Mon Sep 17 00:00:00 2001 From: Colomban Wendling Date: Thu, 26 Jan 2017 17:20:47 +0100 Subject: Add an option for asking confirmation before moving files to the trash Add an option to show a confirmation dialog when moving files to the trash, like there is for deleting files directly or emptying the trash. Closes #632. --- libcaja-private/caja-file-operations.c | 63 ++++++++++++++++++++++++++++++- libcaja-private/caja-global-preferences.h | 1 + libcaja-private/org.mate.caja.gschema.xml | 5 +++ src/caja-file-management-properties.c | 4 ++ src/caja-file-management-properties.ui | 17 ++++++++- 5 files changed, 88 insertions(+), 2 deletions(-) diff --git a/libcaja-private/caja-file-operations.c b/libcaja-private/caja-file-operations.c index 2767922b..ad525d2d 100644 --- a/libcaja-private/caja-file-operations.c +++ b/libcaja-private/caja-file-operations.c @@ -1315,6 +1315,18 @@ should_confirm_trash (void) return confirm_trash; } +static gboolean +should_confirm_move_to_trash (void) +{ + GSettings *prefs; + gboolean confirm_trash; + + prefs = g_settings_new ("org.mate.caja.preferences"); + confirm_trash = g_settings_get_boolean (prefs, CAJA_PREFERENCES_CONFIRM_MOVE_TO_TRASH); + g_object_unref (prefs); + return confirm_trash; +} + static gboolean job_aborted (CommonJob *job) { @@ -1426,6 +1438,48 @@ confirm_delete_directly (CommonJob *job, return response == 1; } +static gboolean +confirm_trash (CommonJob *job, + GList *files) +{ + char *prompt; + int file_count; + int response; + + /* Just Say Yes if the preference says not to confirm. */ + if (!should_confirm_move_to_trash ()) { + return TRUE; + } + + file_count = g_list_length (files); + g_assert (file_count > 0); + + if (can_delete_files_without_confirm (files)) { + return TRUE; + } + + if (file_count == 1) { + prompt = f (_("Are you sure you want to trash \"%B\"?"), + files->data); + } else { + prompt = f (ngettext("Are you sure you want to trash " + "the %'d selected item?", + "Are you sure you want to trash " + "the %'d selected items?", file_count), + file_count); + } + + response = run_warning (job, + prompt, + f (_("Items moved to the trash may be recovered until the trash is emptied.")), + NULL, + FALSE, + GTK_STOCK_CANCEL, _("Move to _Trash"), + NULL); + + return response == 1; +} + static void report_delete_progress (CommonJob *job, SourceInfo *source_info, @@ -1917,6 +1971,7 @@ delete_job (GIOSchedulerJob *io_job, CommonJob *common; gboolean must_confirm_delete_in_trash; gboolean must_confirm_delete; + gboolean must_confirm_trash; int files_skipped; common = (CommonJob *)job; @@ -1929,6 +1984,7 @@ delete_job (GIOSchedulerJob *io_job, must_confirm_delete_in_trash = FALSE; must_confirm_delete = FALSE; + must_confirm_trash = FALSE; files_skipped = 0; for (l = job->files; l != NULL; l = l->next) { @@ -1942,6 +1998,7 @@ delete_job (GIOSchedulerJob *io_job, to_delete_files = g_list_prepend (to_delete_files, file); } else { if (job->try_trash) { + must_confirm_trash = TRUE; to_trash_files = g_list_prepend (to_trash_files, file); } else { must_confirm_delete = TRUE; @@ -1968,7 +2025,11 @@ delete_job (GIOSchedulerJob *io_job, if (to_trash_files != NULL) { to_trash_files = g_list_reverse (to_trash_files); - trash_files (common, to_trash_files, &files_skipped); + if (! must_confirm_trash || confirm_trash (common, to_trash_files)) { + trash_files (common, to_trash_files, &files_skipped); + } else { + job->user_cancel = TRUE; + } } g_list_free (to_trash_files); diff --git a/libcaja-private/caja-global-preferences.h b/libcaja-private/caja-global-preferences.h index 6fae1fc0..7a0da287 100644 --- a/libcaja-private/caja-global-preferences.h +++ b/libcaja-private/caja-global-preferences.h @@ -55,6 +55,7 @@ G_BEGIN_DECLS /* Trash options */ #define CAJA_PREFERENCES_CONFIRM_TRASH "confirm-trash" +#define CAJA_PREFERENCES_CONFIRM_MOVE_TO_TRASH "confirm-move-to-trash" #define CAJA_PREFERENCES_ENABLE_DELETE "enable-delete" /* Desktop options */ diff --git a/libcaja-private/org.mate.caja.gschema.xml b/libcaja-private/org.mate.caja.gschema.xml index 645a3d73..559d70f0 100644 --- a/libcaja-private/org.mate.caja.gschema.xml +++ b/libcaja-private/org.mate.caja.gschema.xml @@ -94,6 +94,11 @@ Whether to ask for confirmation when deleting files, or emptying Trash If set to true, then Caja will ask for confirmation when you attempt to delete files, or empty the Trash. + + false + Whether to ask for confirmation when moving files to the Trash + If set to true, then Caja will ask for confirmation when you attempt to move files to the Trash. + false Whether to enable immediate deletion diff --git a/src/caja-file-management-properties.c b/src/caja-file-management-properties.c index 94ce7443..5dc2251d 100644 --- a/src/caja-file-management-properties.c +++ b/src/caja-file-management-properties.c @@ -63,6 +63,7 @@ #define CAJA_FILE_MANAGEMENT_PROPERTIES_ALWAYS_USE_BROWSER_WIDGET "always_use_browser_checkbutton" #define CAJA_FILE_MANAGEMENT_PROPERTIES_ALWAYS_USE_LOCATION_ENTRY_WIDGET "always_use_location_entry_checkbutton" #define CAJA_FILE_MANAGEMENT_PROPERTIES_TRASH_CONFIRM_WIDGET "trash_confirm_checkbutton" +#define CAJA_FILE_MANAGEMENT_PROPERTIES_TRASH_CONFIRM_TRASH_WIDGET "trash_confirm_trash_checkbutton" #define CAJA_FILE_MANAGEMENT_PROPERTIES_TRASH_DELETE_WIDGET "trash_delete_checkbutton" #define CAJA_FILE_MANAGEMENT_PROPERTIES_SHOW_HIDDEN_WIDGET "hidden_files_checkbutton" #define CAJA_FILE_MANAGEMENT_PROPERTIES_TREE_VIEW_FOLDERS_WIDGET "treeview_folders_checkbutton" @@ -1100,6 +1101,9 @@ caja_file_management_properties_dialog_setup (GtkBuilder *builder, GtkWindow *wi bind_builder_bool (builder, caja_preferences, CAJA_FILE_MANAGEMENT_PROPERTIES_TRASH_CONFIRM_WIDGET, CAJA_PREFERENCES_CONFIRM_TRASH); + bind_builder_bool (builder, caja_preferences, + CAJA_FILE_MANAGEMENT_PROPERTIES_TRASH_CONFIRM_TRASH_WIDGET, + CAJA_PREFERENCES_CONFIRM_MOVE_TO_TRASH); bind_builder_bool (builder, caja_preferences, CAJA_FILE_MANAGEMENT_PROPERTIES_TRASH_DELETE_WIDGET, diff --git a/src/caja-file-management-properties.ui b/src/caja-file-management-properties.ui index 526a80d4..f0e55b5a 100644 --- a/src/caja-file-management-properties.ui +++ b/src/caja-file-management-properties.ui @@ -1118,6 +1118,21 @@ 0 + + + Ask before moving files to the _Trash + True + True + False + True + True + + + False + False + 1 + + I_nclude a Delete command that bypasses Trash @@ -1130,7 +1145,7 @@ False False - 1 + 2 -- cgit v1.2.1