summaryrefslogtreecommitdiff
path: root/libcaja-private
diff options
context:
space:
mode:
authorColomban Wendling <[email protected]>2017-01-26 17:20:47 +0100
committermonsta <[email protected]>2017-02-07 17:51:36 +0400
commit2a294282863634721b46a0a386aa10414de78bab (patch)
treee81384088a3b1b912c7c15d67a3bebbadb8260e1 /libcaja-private
parentd575ecad1297e3200df6370efd5d9ae6db12b96a (diff)
downloadcaja-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.
Diffstat (limited to 'libcaja-private')
-rw-r--r--libcaja-private/caja-file-operations.c63
-rw-r--r--libcaja-private/caja-global-preferences.h1
-rw-r--r--libcaja-private/org.mate.caja.gschema.xml5
3 files changed, 68 insertions, 1 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>