[Xfce4-commits] [xfce/thunar] 01/01: delete key in tree-view can delete the user home folder (Bug #15095)

noreply at xfce.org noreply at xfce.org
Tue Apr 23 20:59:46 CEST 2019


This is an automated email from the git hooks/post-receive script.

a   l   e   x       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       x   f   c   e   -   4   .   1   4   
   in repository xfce/thunar.

commit ac629bb919764294d3c37b110facc8e2652fd61c
Author: Alexander Schwinn <alexxcons at xfce.org>
Date:   Tue Apr 23 12:19:22 2019 +0200

    delete key in tree-view can delete the user home folder (Bug #15095)
---
 thunar/thunar-tree-view.c | 70 +++++++++++++++++++++--------------------------
 1 file changed, 31 insertions(+), 39 deletions(-)

diff --git a/thunar/thunar-tree-view.c b/thunar/thunar-tree-view.c
index b53a8ef..84eecbe 100644
--- a/thunar/thunar-tree-view.c
+++ b/thunar/thunar-tree-view.c
@@ -142,6 +142,8 @@ static GdkDragAction            thunar_tree_view_get_dest_actions             (T
                                                                                ThunarFile             **file_return);
 static ThunarFile              *thunar_tree_view_get_selected_file            (ThunarTreeView          *view);
 static ThunarDevice            *thunar_tree_view_get_selected_device          (ThunarTreeView          *view);
+static void                     thunar_tree_view_action_unlink_selected_folder(ThunarTreeView          *view,
+                                                                               gboolean                 permanently);
 static void                     thunar_tree_view_action_copy                  (ThunarTreeView          *view);
 static void                     thunar_tree_view_action_create_folder         (ThunarTreeView          *view);
 static void                     thunar_tree_view_action_cut                   (ThunarTreeView          *view);
@@ -1230,7 +1232,8 @@ thunar_tree_view_row_collapsed (GtkTreeView *tree_view,
 static gboolean
 thunar_tree_view_delete_selected_files (ThunarTreeView *view)
 {
-  GtkAccelKey key;
+  GtkAccelKey     key;
+  GdkModifierType state;
 
   _thunar_return_val_if_fail (THUNAR_IS_TREE_VIEW (view), FALSE);
 
@@ -1241,8 +1244,12 @@ thunar_tree_view_delete_selected_files (ThunarTreeView *view)
       && (key.accel_key != 0 || key.accel_mods != 0))
     return FALSE;
 
-  /* ask the user whether to delete the folder... */
-  thunar_tree_view_action_move_to_trash (view);
+  /* check if we should permanently delete the files (user holds shift or no gvfs available) */
+  if ((gtk_get_current_event_state (&state) && (state & GDK_SHIFT_MASK) != 0) ||
+      (gtk_get_current_event_state (&state) && !thunar_g_vfs_is_uri_scheme_supported ("trash")))
+    thunar_tree_view_action_delete (view);
+  else
+    thunar_tree_view_action_move_to_trash (view);
 
   /* ...and we're done */
   return TRUE;
@@ -1820,13 +1827,12 @@ thunar_tree_view_action_cut (ThunarTreeView *view)
 
 
 static void
-thunar_tree_view_action_move_to_trash (ThunarTreeView *view)
+thunar_tree_view_action_unlink_selected_folder (ThunarTreeView *view,
+                                                gboolean        permanently)
 {
   ThunarApplication *application;
   ThunarFile        *file;
   GList              file_list;
-  gboolean           permanently;
-  GdkModifierType    state;
 
   _thunar_return_if_fail (THUNAR_IS_TREE_VIEW (view));
 
@@ -1834,18 +1840,18 @@ thunar_tree_view_action_move_to_trash (ThunarTreeView *view)
   file = thunar_tree_view_get_selected_file (view);
   if (G_LIKELY (file != NULL))
     {
-      /* fake a file list */
-      file_list.data = file;
-      file_list.next = NULL;
-      file_list.prev = NULL;
-
-      /* check if we should permanently delete the files (user holds shift) */
-      permanently = (gtk_get_current_event_state (&state) && (state & GDK_SHIFT_MASK) != 0);
-
-      /* delete the file */
-      application = thunar_application_get ();
-      thunar_application_unlink_files (application, GTK_WIDGET (view), &file_list, permanently);
-      g_object_unref (G_OBJECT (application));
+      if (thunar_file_can_be_trashed (file))
+        {
+          /* fake a file list */
+          file_list.data = file;
+          file_list.next = NULL;
+          file_list.prev = NULL;
+
+          /* delete the file */
+          application = thunar_application_get ();
+          thunar_application_unlink_files (application, GTK_WIDGET (view), &file_list, permanently);
+          g_object_unref (G_OBJECT (application));
+        }
 
       /* release the file */
       g_object_unref (G_OBJECT (file));
@@ -1855,31 +1861,17 @@ thunar_tree_view_action_move_to_trash (ThunarTreeView *view)
 
 
 static void
-thunar_tree_view_action_delete (ThunarTreeView *view)
+thunar_tree_view_action_move_to_trash (ThunarTreeView *view)
 {
-  ThunarApplication *application;
-  ThunarFile        *file;
-  GList              file_list;
-
-  _thunar_return_if_fail (THUNAR_IS_TREE_VIEW (view));
+  thunar_tree_view_action_unlink_selected_folder (view, FALSE);
+}
 
-  /* determine the selected file */
-  file = thunar_tree_view_get_selected_file (view);
-  if (G_LIKELY (file != NULL))
-    {
-      /* fake a file list */
-      file_list.data = file;
-      file_list.next = NULL;
-      file_list.prev = NULL;
 
-      /* delete the file */
-      application = thunar_application_get ();
-      thunar_application_unlink_files (application, GTK_WIDGET (view), &file_list, TRUE);
-      g_object_unref (G_OBJECT (application));
 
-      /* release the file */
-      g_object_unref (G_OBJECT (file));
-    }
+static void
+thunar_tree_view_action_delete (ThunarTreeView *view)
+{
+  thunar_tree_view_action_unlink_selected_folder (view, TRUE);
 }
 
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list