From 8f2aa047dadcc353f82471719ecb05b2ecd0fc1a Mon Sep 17 00:00:00 2001 From: Harald Judt Date: Thu, 15 Jan 2015 14:41:22 +0100 Subject: Allow + middle click in shortcut and treeview panes Currently, only middle click is possible, without any modifiers. This patch enables + middle click, enabling the user to quickly switch (for that action only) the behaviour of opening folders to either "open in new window" or "open in new tab". This makes this behaviour equal to that of the icons/list/details views. --- thunar/thunar-shortcuts-view.c | 16 +++++++++++++--- thunar/thunar-tree-view.c | 7 +++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/thunar/thunar-shortcuts-view.c b/thunar/thunar-shortcuts-view.c index 7de04b1..b8f49d0 100644 --- a/thunar/thunar-shortcuts-view.c +++ b/thunar/thunar-shortcuts-view.c @@ -443,8 +443,7 @@ thunar_shortcuts_view_button_press_event (GtkWidget *widget, } } else if ((event->button == 1 || event->button == 2) - && event->type == GDK_BUTTON_PRESS - && (event->state & gtk_accelerator_get_default_mod_mask ()) == 0) + && event->type == GDK_BUTTON_PRESS) { /* check if we clicked the eject button area */ column_width = gtk_tree_view_column_get_width (gtk_tree_view_get_column (GTK_TREE_VIEW (view), 0)); @@ -484,6 +483,7 @@ thunar_shortcuts_view_button_release_event (GtkWidget *widget, GdkEventButton *event) { ThunarShortcutsView *view = THUNAR_SHORTCUTS_VIEW (widget); + GtkTreePath *path; gboolean in_tab; /* check if we have an event matching the pressed button state */ @@ -503,7 +503,17 @@ thunar_shortcuts_view_button_release_event (GtkWidget *widget, { /* button 2 opens in a new window or tab */ g_object_get (view->preferences, "misc-middle-click-in-tab", &in_tab, NULL); - thunar_shortcuts_view_open (view, in_tab ? OPEN_IN_TAB : OPEN_IN_WINDOW); + + /* holding ctrl inverts the action */ + if ((event->state & GDK_CONTROL_MASK) != 0) + in_tab = !in_tab; + + if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget), event->x, event->y, &path, NULL, NULL, NULL)) + { + gtk_tree_view_set_cursor (GTK_TREE_VIEW (widget), path, NULL, FALSE); + gtk_tree_path_free (path); + thunar_shortcuts_view_open (view, in_tab ? OPEN_IN_TAB : OPEN_IN_WINDOW); + } } } diff --git a/thunar/thunar-tree-view.c b/thunar/thunar-tree-view.c index e4661b0..f987dfc 100644 --- a/thunar/thunar-tree-view.c +++ b/thunar/thunar-tree-view.c @@ -715,8 +715,7 @@ thunar_tree_view_button_press_event (GtkWidget *widget, } } else if ((event->button == 1 || event->button == 2) - && event->type == GDK_BUTTON_PRESS - && (event->state & gtk_accelerator_get_default_mod_mask ()) == 0) + && event->type == GDK_BUTTON_PRESS) { /* remember the button as pressed and handled it in the release handler */ view->pressed_button = event->button; @@ -749,6 +748,10 @@ thunar_tree_view_button_release_event (GtkWidget *widget, else if (G_UNLIKELY (event->button == 2)) { g_object_get (view->preferences, "misc-middle-click-in-tab", &in_tab, NULL); + /* holding ctrl inverts the action */ + if ((event->state & GDK_CONTROL_MASK) != 0) + in_tab = !in_tab; + if (in_tab) thunar_tree_view_action_open_in_new_tab (view); else -- 2.3.0