diff options
author | Colomban Wendling <[email protected]> | 2017-01-26 17:20:47 +0100 |
---|---|---|
committer | monsta <[email protected]> | 2017-02-07 17:51:36 +0400 |
commit | 2a294282863634721b46a0a386aa10414de78bab (patch) | |
tree | e81384088a3b1b912c7c15d67a3bebbadb8260e1 | |
parent | d575ecad1297e3200df6370efd5d9ae6db12b96a (diff) | |
download | caja-2a294282863634721b46a0a386aa10414de78bab.tar.bz2 caja-2a294282863634721b46a0a386aa10414de78bab.tar.xz |
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.
-rw-r--r-- | libcaja-private/caja-file-operations.c | 63 | ||||
-rw-r--r-- | libcaja-private/caja-global-preferences.h | 1 | ||||
-rw-r--r-- | libcaja-private/org.mate.caja.gschema.xml | 5 | ||||
-rw-r--r-- | src/caja-file-management-properties.c | 4 | ||||
-rw-r--r-- | 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 @@ -1316,6 +1316,18 @@ should_confirm_trash (void) } 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) { return g_cancellable_is_cancelled (job->cancellable); @@ -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 @@ <summary>Whether to ask for confirmation when deleting files, or emptying Trash</summary> <description>If set to true, then Caja will ask for confirmation when you attempt to delete files, or empty the Trash.</description> </key> + <key name="confirm-move-to-trash" type="b"> + <default>false</default> + <summary>Whether to ask for confirmation when moving files to the Trash</summary> + <description>If set to true, then Caja will ask for confirmation when you attempt to move files to the Trash.</description> + </key> <key name="enable-delete" type="b"> <default>false</default> <summary>Whether to enable immediate deletion</summary> 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 @@ -1119,6 +1119,21 @@ </packing> </child> <child> + <object class="GtkCheckButton" id="trash_confirm_trash_checkbutton"> + <property name="label" translatable="yes">Ask before moving files to the _Trash</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="use_underline">True</property> + <property name="draw_indicator">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">1</property> + </packing> + </child> + <child> <object class="GtkCheckButton" id="trash_delete_checkbutton"> <property name="label" translatable="yes">I_nclude a Delete command that bypasses Trash</property> <property name="visible">True</property> @@ -1130,7 +1145,7 @@ <packing> <property name="expand">False</property> <property name="fill">False</property> - <property name="position">1</property> + <property name="position">2</property> </packing> </child> </object> |