From f9ff6bb2380b0a311650dcfd9ddedfb6f7bcc4ac Mon Sep 17 00:00:00 2001 From: Alexander Schwinn Date: Tue, 21 Aug 2018 22:41:22 +0200 Subject: [PATCH] Add preferences item to control "move to trash" / "delete" in the context menu (Bug #13327) --- thunar/thunar-enum-types.c | 23 ++++++++++++++++++++++ thunar/thunar-enum-types.h | 15 +++++++++++++++ thunar/thunar-preferences-dialog.c | 39 ++++++++++++++++++++++++++++++++++++++ thunar/thunar-preferences.c | 14 ++++++++++++++ thunar/thunar-standard-view.c | 24 +++++++++++++---------- 5 files changed, 105 insertions(+), 10 deletions(-) diff --git a/thunar/thunar-enum-types.c b/thunar/thunar-enum-types.c index 63b48218..11c69794 100644 --- a/thunar/thunar-enum-types.c +++ b/thunar/thunar-enum-types.c @@ -410,3 +410,26 @@ thunar_file_mode_get_type (void) } return type; } + + + +GType +thunar_removal_actions_get_type (void) +{ + static GType type = G_TYPE_INVALID; + + if (G_UNLIKELY (type == G_TYPE_INVALID)) + { + static const GEnumValue values[] = + { + { THUNAR_REMOVAL_ACTIONS_DELETE, "THUNAR_REMOVAL_ACTIONS_DELETE", "delete", }, + { THUNAR_REMOVAL_ACTIONS_TRASH, "THUNAR_REMOVAL_ACTIONS_TRASH", "trash", }, + { THUNAR_REMOVAL_ACTIONS_DELETE_AND_TRASH, "THUNAR_REMOVAL_ACTIONS_DELETE_AND_TRASH", "delete-and-trash", }, + { 0, NULL, NULL, }, + }; + + type = g_enum_register_static (I_("ThunarRemovalActions"), values); + } + + return type; +} diff --git a/thunar/thunar-enum-types.h b/thunar/thunar-enum-types.h index 17a792d4..76c6a285 100644 --- a/thunar/thunar-enum-types.h +++ b/thunar/thunar-enum-types.h @@ -70,6 +70,21 @@ typedef enum GType thunar_date_style_get_type (void) G_GNUC_CONST; +#define THUNAR_TYPE_REMOVAL_ACTIONS (thunar_removal_actions_get_type ()) + +/** + * ThunarRemovalAction: + * + * Removal Actions which are displayed in the context menu + **/ +typedef enum +{ + THUNAR_REMOVAL_ACTIONS_DELETE, + THUNAR_REMOVAL_ACTIONS_TRASH, + THUNAR_REMOVAL_ACTIONS_DELETE_AND_TRASH, +} ThunarRemovalActions; + +GType thunar_removal_actions_get_type (void) G_GNUC_CONST; #define THUNAR_TYPE_COLUMN (thunar_column_get_type ()) diff --git a/thunar/thunar-preferences-dialog.c b/thunar/thunar-preferences-dialog.c index f3731c71..da588ac9 100644 --- a/thunar/thunar-preferences-dialog.c +++ b/thunar/thunar-preferences-dialog.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -725,6 +726,44 @@ thunar_preferences_dialog_init (ThunarPreferencesDialog *dialog) gtk_widget_set_hexpand (label, TRUE); gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1); gtk_widget_show (label); + + frame = g_object_new (GTK_TYPE_FRAME, "border-width", 0, "shadow-type", GTK_SHADOW_NONE, NULL); + gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, TRUE, 0); + gtk_widget_show (frame); + + label = gtk_label_new (_("Trash")); + gtk_label_set_attributes (GTK_LABEL (label), thunar_pango_attr_list_bold ()); + gtk_frame_set_label_widget (GTK_FRAME (frame), label); + gtk_widget_show (label); + + grid = gtk_grid_new (); + gtk_grid_set_column_spacing (GTK_GRID (grid), 12); + gtk_grid_set_row_spacing (GTK_GRID (grid), 6); + gtk_container_set_border_width (GTK_CONTAINER (grid), 12); + gtk_container_add (GTK_CONTAINER (frame), grid); + gtk_widget_show (grid); + + label = gtk_label_new_with_mnemonic (_("Show removal Actions:")); + gtk_label_set_xalign (GTK_LABEL (label), 0.0f); + gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1); + gtk_widget_show (label); + + combo = gtk_combo_box_text_new (); + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Delete")); + if( thunar_g_vfs_is_uri_scheme_supported ("trash") ) + { + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Move to Trash")); + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Move to Trash and Delete")); + } + exo_mutual_binding_new (G_OBJECT (dialog->preferences), "misc-removal-actions", G_OBJECT (combo), "active"); + gtk_widget_set_hexpand (combo, TRUE); + gtk_grid_attach (GTK_GRID (grid), combo, 1, 0, 1, 1); + thunar_gtk_label_set_a11y_relation (GTK_LABEL (label), combo); + gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo); + gtk_widget_set_tooltip_text (combo, _("'Move to Trash'\n Move files into the trash folder. It is possible to restore them.\n\n" + "'Delete'\n Erase files from disc without any option to recover.\n\n" + "In order to enable support for 'Move to Trash', the 'gvfs' package of your distribution needs to be installed.")); + gtk_widget_show (combo); /* cleanup */ g_free (path); diff --git a/thunar/thunar-preferences.c b/thunar/thunar-preferences.c index 8a5df7c9..5013a1e7 100644 --- a/thunar/thunar-preferences.c +++ b/thunar/thunar-preferences.c @@ -85,6 +85,7 @@ enum PROP_MISC_OPEN_NEW_WINDOW_AS_TAB, PROP_MISC_RECURSIVE_PERMISSIONS, PROP_MISC_REMEMBER_GEOMETRY, + PROP_MISC_REMOVAL_ACTIONS, PROP_MISC_SHOW_ABOUT_TEMPLATES, PROP_MISC_SINGLE_CLICK, PROP_MISC_SINGLE_CLICK_TIMEOUT, @@ -631,6 +632,19 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass) EXO_PARAM_READWRITE); /** + * ThunarPreferences:misc-removal-actions: + * + * Removal Actions which are displayed in the context menu + **/ + preferences_props[PROP_MISC_REMOVAL_ACTIONS] = + g_param_spec_enum ("misc-removal-actions", + "MiscRemovalActions", + NULL, + THUNAR_TYPE_REMOVAL_ACTIONS, + THUNAR_REMOVAL_ACTIONS_TRASH, + EXO_PARAM_READWRITE); + + /** * ThunarPreferences:misc-show-about-templates: * * Whether to display the "About Templates" dialog, when opening the diff --git a/thunar/thunar-standard-view.c b/thunar/thunar-standard-view.c index 9b1f917e..a0b4bee7 100644 --- a/thunar/thunar-standard-view.c +++ b/thunar/thunar-standard-view.c @@ -4454,15 +4454,16 @@ thunar_standard_view_queue_popup (ThunarStandardView *standard_view, void thunar_standard_view_selection_changed (ThunarStandardView *standard_view) { - GtkTreeIter iter; - ThunarFile *current_directory; - gboolean can_paste_into_folder; - gboolean restorable; - gboolean pastable; - gboolean writable; - gboolean trashed; - GList *lp, *selected_files; - gint n_selected_files = 0; + GtkTreeIter iter; + ThunarFile *current_directory; + gboolean can_paste_into_folder; + gboolean restorable; + gboolean pastable; + gboolean writable; + gboolean trashed; + GList *lp, *selected_files; + gint n_selected_files = 0; + ThunarRemovalActions removal_actions; _thunar_return_if_fail (THUNAR_IS_STANDARD_VIEW (standard_view)); @@ -4504,6 +4505,8 @@ thunar_standard_view_selection_changed (ThunarStandardView *standard_view) writable = (current_directory != NULL && thunar_file_is_writable (current_directory)); trashed = (current_directory != NULL && thunar_file_is_trashed (current_directory)); + g_object_get (G_OBJECT (standard_view->preferences), "misc-removal-actions", &removal_actions, NULL); + /* check whether the clipboard contains data that can be pasted here */ pastable = (standard_view->clipboard != NULL && thunar_clipboard_manager_get_can_paste (standard_view->clipboard)); @@ -4547,7 +4550,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS /* update the "Move to Trash" action */ g_object_set (G_OBJECT (standard_view->priv->action_move_to_trash), "sensitive", (n_selected_files > 0) && writable, - "visible", !trashed && thunar_g_vfs_is_uri_scheme_supported ("trash"), + "visible", !trashed && thunar_g_vfs_is_uri_scheme_supported ("trash") && removal_actions != THUNAR_REMOVAL_ACTIONS_DELETE, "tooltip", ngettext ("Move the selected file to the Trash", "Move the selected files to the Trash", n_selected_files), @@ -4556,6 +4559,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS /* update the "Delete" action */ g_object_set (G_OBJECT (standard_view->priv->action_delete), "sensitive", (n_selected_files > 0) && writable, + "visible", trashed || removal_actions != THUNAR_REMOVAL_ACTIONS_TRASH, "tooltip", ngettext ("Permanently delete the selected file", "Permanently delete the selected files", n_selected_files), -- 2.11.0