[Xfce4-commits] <thunar:master> Change the way permanent deletes are detected.

Nick Schermer noreply at xfce.org
Sat Sep 22 20:38:01 CEST 2012


Updating branch refs/heads/master
         to 9b7506cc28a6dd1c0cc96438a75350cca86248ec (commit)
       from eb8320d307a27a1629fd5cbc4f96d8bed12e539d (commit)

commit 9b7506cc28a6dd1c0cc96438a75350cca86248ec
Author: Nick Schermer <nick at xfce.org>
Date:   Sat Sep 22 20:35:34 2012 +0200

    Change the way permanent deletes are detected.
    
    A part of bug #4173 was not resolved properly. The hard-coded
    actions were properly blocked, but custom actions with a Shift
    key (override delete with Shift+Delete to avoid easy deletion)
    was always detected as a permanent deleted, not move to trash.

 thunar/thunar-application.c   |   27 +++++++++------------------
 thunar/thunar-standard-view.c |   41 ++++++++++++++++++++++++++++++-----------
 thunar/thunar-tree-view.c     |   22 +++++++++++-----------
 3 files changed, 50 insertions(+), 40 deletions(-)

diff --git a/thunar/thunar-application.c b/thunar/thunar-application.c
index b619bbe..c6dc674 100644
--- a/thunar/thunar-application.c
+++ b/thunar/thunar-application.c
@@ -1689,9 +1689,7 @@ unlink_stub (GList *source_path_list,
  * @application : a #ThunarApplication.
  * @parent      : a #GdkScreen, a #GtkWidget or %NULL.
  * @file_list   : the list of #ThunarFile<!---->s that should be deleted.
- * @permanently : whether to unlink the files permanently. Even if this is set to
- *                FALSE, the files may be erased permanently if the SHIFT key
- *                is pressed at the time the function is called.
+ * @permanently : whether to unlink the files permanently.
  *
  * Deletes all files in the @file_list and takes care of all user interaction.
  *
@@ -1705,25 +1703,18 @@ thunar_application_unlink_files (ThunarApplication *application,
                                  GList             *file_list,
                                  gboolean           permanently)
 {
-  GdkModifierType state;
-  GtkWidget      *dialog;
-  GtkWindow      *window;
-  GdkScreen      *screen;
-  GList          *path_list = NULL;
-  GList          *lp;
-  gchar          *message;      
-  guint           n_path_list = 0;
-  gint            response;
+  GtkWidget *dialog;
+  GtkWindow *window;
+  GdkScreen *screen;
+  GList     *path_list = NULL;
+  GList     *lp;
+  gchar     *message;
+  guint      n_path_list = 0;
+  gint       response;
 
   _thunar_return_if_fail (parent == NULL || GDK_IS_SCREEN (parent) || GTK_IS_WIDGET (parent));
   _thunar_return_if_fail (THUNAR_IS_APPLICATION (application));
 
-  if (!permanently)
-    {
-      /* check if we should permanently delete the files (user holds shift) */
-      permanently = (gtk_get_current_event_state (&state) && (state & GDK_SHIFT_MASK) != 0);
-    }
-
   /* determine the paths for the files */
   for (lp = g_list_last (file_list); lp != NULL; lp = lp->prev, ++n_path_list)
     {
diff --git a/thunar/thunar-standard-view.c b/thunar/thunar-standard-view.c
index 18ac5cb..7d2d5c0 100644
--- a/thunar/thunar-standard-view.c
+++ b/thunar/thunar-standard-view.c
@@ -1546,20 +1546,21 @@ thunar_standard_view_delete_selected_files (ThunarStandardView *standard_view)
   GtkAction       *action = GTK_ACTION (standard_view->priv->action_delete);
   const gchar     *accel_path;
   GtkAccelKey      key;
-  GdkModifierType  state;
-  gboolean         permanently;
 
   _thunar_return_val_if_fail (THUNAR_IS_STANDARD_VIEW (standard_view), FALSE);
 
-  /* if this looks like a permanently delete */
-  permanently = (gtk_get_current_event_state (&state) && (state & GDK_SHIFT_MASK) != 0);
-
-  /* check if the user defined a custom accelerator and is not holding the
-   * shift button. if he or she has, we don't response to the predefined key
-   * bindings (bug #4173) */
+  /* Check if there is a user defined accelerator for the delete action,
+   * if there is, skip events from the hard-coded keys which are set in
+   * the class of the standard view. See bug #4173.
+   *
+   * The trick here is that if a custom accelerator is set by the user,
+   * this function is never called. If a hardcoded key combination is
+   * pressed and a custom accelerator is set, accel_key || accel_mods
+   * are no 0. */
   accel_path = gtk_action_get_accel_path (action);
-  if (accel_path != NULL && gtk_accel_map_lookup_entry (accel_path, &key)
-      && key.accel_key != 0 && key.accel_mods != 0 && permanently == FALSE)
+  if (accel_path != NULL
+      && gtk_accel_map_lookup_entry (accel_path, &key)
+      && (key.accel_key != 0 || key.accel_mods != 0))
     return FALSE;
 
   /* just emit the "activate" signal on the "delete" action */
@@ -2062,13 +2063,31 @@ thunar_standard_view_action_delete (GtkAction          *action,
                                     ThunarStandardView *standard_view)
 {
   ThunarApplication *application;
+  gboolean           permanently;
+  GdkModifierType    state;
+  const gchar       *accel_path;
+  GtkAccelKey        key;
 
   _thunar_return_if_fail (GTK_IS_ACTION (action));
   _thunar_return_if_fail (THUNAR_IS_STANDARD_VIEW (standard_view));
 
+  /* check if we should permanently delete the files (user holds shift) */
+  permanently = (gtk_get_current_event_state (&state) && (state & GDK_SHIFT_MASK) != 0);
+  if (permanently)
+    {
+      /* look if the user has set a custom accelerator (accel_key != 0)
+       * that contains a shift modifier */
+      accel_path = gtk_action_get_accel_path (action);
+      if (accel_path != NULL
+          && gtk_accel_map_lookup_entry (accel_path, &key)
+          && key.accel_key != 0
+          && (key.accel_mods & GDK_SHIFT_MASK) != 0)
+        permanently = FALSE;
+    }
+
   /* delete the selected files */
   application = thunar_application_get ();
-  thunar_application_unlink_files (application, GTK_WIDGET (standard_view), standard_view->priv->selected_files, FALSE);
+  thunar_application_unlink_files (application, GTK_WIDGET (standard_view), standard_view->priv->selected_files, permanently);
   g_object_unref (G_OBJECT (application));
 }
 
diff --git a/thunar/thunar-tree-view.c b/thunar/thunar-tree-view.c
index 5b01d35..5f21349 100644
--- a/thunar/thunar-tree-view.c
+++ b/thunar/thunar-tree-view.c
@@ -1037,20 +1037,15 @@ thunar_tree_view_row_collapsed (GtkTreeView *tree_view,
 static gboolean
 thunar_tree_view_delete_selected_files (ThunarTreeView *view)
 {
-  GtkAccelKey     key;
-  GdkModifierType state;
-  gboolean        permanently;
+  GtkAccelKey key;
 
   _thunar_return_val_if_fail (THUNAR_IS_TREE_VIEW (view), FALSE);
 
-  /* if this looks like a permanently delete */
-  permanently = (gtk_get_current_event_state (&state) && (state & GDK_SHIFT_MASK) != 0);
-
-  /* check if the user defined a custom accelerator and is not holding the
-   * shift button. if he or she has, we don't response to the predefined key 
-   * bindings (bug #4173) */
+  /* Check if there is a user defined accelerator for the delete action,
+   * if there is, skip events from the hard-coded keys which are set in
+   * the class of the standard view. See bug #4173. */
   if (gtk_accel_map_lookup_entry ("<Actions>/ThunarStandardView/delete", &key)
-      && key.accel_key != 0 && key.accel_mods != 0 && permanently == FALSE)
+      && (key.accel_key != 0 || key.accel_mods != 0))
     return FALSE;
 
   /* ask the user whether to delete the folder... */
@@ -1629,6 +1624,8 @@ thunar_tree_view_action_delete (ThunarTreeView *view)
   ThunarApplication *application;
   ThunarFile        *file;
   GList              file_list;
+  gboolean           permanently;
+  GdkModifierType    state;
 
   _thunar_return_if_fail (THUNAR_IS_TREE_VIEW (view));
 
@@ -1641,9 +1638,12 @@ thunar_tree_view_action_delete (ThunarTreeView *view)
       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, FALSE);
+      thunar_application_unlink_files (application, GTK_WIDGET (view), &file_list, permanently);
       g_object_unref (G_OBJECT (application));
 
       /* release the file */


More information about the Xfce4-commits mailing list