[gnome-commander] Ask a second time if the user wants to delete a non-empty dir; fixes #12
- From: Uwe Scholz <uwescholz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-commander] Ask a second time if the user wants to delete a non-empty dir; fixes #12
- Date: Tue, 9 Mar 2021 07:05:42 +0000 (UTC)
commit 50a72db59a88385c1ad630aef12c768c21307464
Author: Uwe Scholz <u scholz83 gmx de>
Date: Tue Mar 9 08:03:18 2021 +0100
Ask a second time if the user wants to delete a non-empty dir; fixes #12
src/dialogs/gnome-cmd-delete-dialog.cc | 95 +++++++++++++++++++++++++++++++++-
1 file changed, 94 insertions(+), 1 deletion(-)
---
diff --git a/src/dialogs/gnome-cmd-delete-dialog.cc b/src/dialogs/gnome-cmd-delete-dialog.cc
index ef5ce8ba..83aa493c 100644
--- a/src/dialogs/gnome-cmd-delete-dialog.cc
+++ b/src/dialogs/gnome-cmd-delete-dialog.cc
@@ -254,6 +254,93 @@ inline void do_delete (DeleteData *data)
}
+/**
+ * Remove a directory from the list of files to be deleted.
+ * This happens as of user interaction.
+ * The returned list has to be free'ed by g_list_free.
+ */
+static GList *remove_items_from_list_to_be_deleted(GList *files)
+{
+ if (!gnome_cmd_data.options.confirm_delete)
+ {
+ return files;
+ };
+
+ auto itemsToDelete = g_list_copy(files);
+
+ guint dirCount = 0;
+ guint guiResponse;
+ for (auto file = files; file; file = file->next)
+ {
+ auto gnomeCmdFile = (GnomeCmdFile*) file->data;
+ if (gnomeCmdFile->GetGfileAttributeUInt32(G_FILE_ATTRIBUTE_STANDARD_TYPE) == G_FILE_TYPE_DIRECTORY)
+ {
+ GError *error;
+ error = nullptr;
+ guint64 num_dirs;
+ guint64 num_files;
+
+ g_file_measure_disk_usage (gnomeCmdFile->gFile,
+ G_FILE_MEASURE_NONE,
+ nullptr, nullptr, nullptr, nullptr,
+ &num_dirs,
+ &num_files,
+ &error);
+
+ if (error)
+ {
+ g_message ("remove_items_from_list_to_be_deleted: g_file_measure_disk_usage failed: %s",
error->message);
+ g_error_free (error);
+ return 0;
+ }
+ if (num_dirs != 1 || num_files != 0) // num_dirs = 1 -> this is the folder to be deleted
+ {
+ gchar *msg = NULL;
+ gchar *fname = get_utf8 (gnomeCmdFile->get_name());
+
+ msg = g_strdup_printf (_("The directory ā%sā is not empty. Do you really want to delete
it?"), fname);
+ guiResponse = run_simple_dialog (*main_win, FALSE, GTK_MESSAGE_WARNING, msg, _("Delete"),
+ gnome_cmd_data.options.confirm_delete_default==GTK_BUTTONS_CANCEL ? 0 : 3,
+ _("Cancel"), _("Skip"),
+ dirCount++ == 0 ? _("Delete All") : _("Delete Remaining"),
+ _("Delete"), nullptr);
+
+ g_free(fname);
+ g_free(msg);
+
+ if (guiResponse == 0 || guiResponse == 2) // Cancel or Delete All
+ {
+ break;
+ }
+ else if (guiResponse == 1) // Skip
+ {
+ itemsToDelete = g_list_remove(itemsToDelete, file->data);
+ continue;
+ }
+ else if (guiResponse == 3) // Delete
+ {
+ continue;
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+ }
+ if (guiResponse != 1 && guiResponse != 2 && guiResponse != 3) // Cancel or Escape
+ {
+ g_list_free(itemsToDelete);
+ return nullptr;
+ }
+ if (g_list_length(itemsToDelete) == 0)
+ {
+ return nullptr; // file list is empty
+ }
+ return itemsToDelete;
+}
+
+
void gnome_cmd_delete_dialog_show (GList *files)
{
g_return_if_fail (files != NULL);
@@ -293,9 +380,15 @@ void gnome_cmd_delete_dialog_show (GList *files)
if (response != 1)
return;
+ // eventually remove non-empty dirs from list
+ files = remove_items_from_list_to_be_deleted(files);
+
+ if (files == nullptr)
+ return;
+
DeleteData *data = g_new0 (DeleteData, 1);
- data->files = gnome_cmd_file_list_copy (files);
+ data->files = files;
// data->stop = FALSE;
// data->problem = FALSE;
// data->delete_done = FALSE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]