[Xfce4-commits] [xfce/thunar] 12/13: Allow opening by middle-click in tree view only for mounted devices and resources

noreply at xfce.org noreply at xfce.org
Tue May 12 09:58:25 CEST 2015


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

hjudt pushed a commit to branch master
in repository xfce/thunar.

commit 9825e468fe3bf289dfec79c83500823aebd8203b
Author: Harald Judt <h.judt at gmx.at>
Date:   Mon May 11 18:05:11 2015 +0200

    Allow opening by middle-click in tree view only for mounted devices and resources
    
    It is complicated to make this working properly for unmounted resources;
    The new view will not show the correct location. So let's simply do nothing
    when the user clicks on an unmounted resource; the user can click on the
    item with the left mouse button to mount it, then middle-click it to open
    it in a new tab or window.
---
 thunar/thunar-tree-view.c |   35 +++++++++++++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)

diff --git a/thunar/thunar-tree-view.c b/thunar/thunar-tree-view.c
index 8d87f6e..de56a63 100644
--- a/thunar/thunar-tree-view.c
+++ b/thunar/thunar-tree-view.c
@@ -700,6 +700,8 @@ thunar_tree_view_button_press_event (GtkWidget      *widget,
                                      GdkEventButton *event)
 {
   ThunarTreeView    *view = THUNAR_TREE_VIEW (widget);
+  ThunarDevice      *device;
+  ThunarFile        *file;
   GtkTreeViewColumn *column;
   GtkTreePath       *path;
   GtkTreeIter        iter;
@@ -722,11 +724,15 @@ thunar_tree_view_button_press_event (GtkWidget      *widget,
   /* let the widget process the event first (handles focussing and scrolling) */
   result = (*GTK_WIDGET_CLASS (thunar_tree_view_parent_class)->button_press_event) (widget, event);
 
+  /* for the following part, we'll only handle single button presses */
+  if (event->type != GDK_BUTTON_PRESS)
+    return result;
+
   /* resolve the path at the cursor position */
   if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget), event->x, event->y, &path, &column, NULL, NULL))
     {
       /* check if we should popup the context menu */
-      if (G_UNLIKELY (event->button == 3 && event->type == GDK_BUTTON_PRESS))
+      if (G_UNLIKELY (event->button == 3))
         {
           /* determine the iterator for the path */
           if (gtk_tree_model_get_iter (GTK_TREE_MODEL (view->model), &iter, path))
@@ -738,7 +744,7 @@ thunar_tree_view_button_press_event (GtkWidget      *widget,
               result = TRUE;
             }
         }
-      else if ((event->button == 1 || event->button == 2) && event->type == GDK_BUTTON_PRESS)
+      else if (event->button == 1)
         {
           GdkRectangle rect;
           gtk_tree_view_get_cell_area (GTK_TREE_VIEW (widget), path, column, &rect);
@@ -750,6 +756,31 @@ thunar_tree_view_button_press_event (GtkWidget      *widget,
           /* remember the button as pressed and handle it in the release handler */
           view->pressed_button = event->button;
         }
+      else if (event->button == 2)
+        {
+          /* only open the item if it is mounted (otherwise opening and selecting it won't work correctly) */
+          gtk_tree_path_free (path);
+          gtk_tree_view_get_cursor (GTK_TREE_VIEW (view), &path, NULL);
+          if (path != NULL && gtk_tree_model_get_iter (GTK_TREE_MODEL (view->model), &iter, path))
+            gtk_tree_model_get (GTK_TREE_MODEL (view->model), &iter,
+                                THUNAR_TREE_MODEL_COLUMN_FILE, &file,
+                                THUNAR_TREE_MODEL_COLUMN_DEVICE, &device, -1);
+
+          if ((device != NULL && thunar_device_is_mounted (device)) ||
+              (file != NULL && thunar_file_is_mounted (file)))
+            {
+              view->pressed_button = event->button;
+            }
+          else
+            {
+              gtk_tree_path_free (view->select_path);
+              view->select_path = NULL;
+            }
+          if (device)
+            g_object_unref (device);
+          if (file)
+            g_object_unref (file);
+        }
 
       /* release the path */
       gtk_tree_path_free (path);

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


More information about the Xfce4-commits mailing list