From 45be7f05532ea6e81a60efdd7aaa5bc808b12cab Mon Sep 17 00:00:00 2001 From: Harald Judt Date: Thu, 15 Jan 2015 11:11:39 +0100 Subject: Make single middle click open files and folders (bug #10587) Regardless of the "open on single click" option, double middle click is weird and many users will not know about it. What's more, on many mice the middle mouse button is hard to press. So do away with the double middle click and only allow open with middle click for folders. --- thunar/thunar-abstract-icon-view.c | 59 ++++++++++++++---------------------- thunar/thunar-details-view.c | 62 +++++++++++++++----------------------- 2 files changed, 46 insertions(+), 75 deletions(-) diff --git a/thunar/thunar-abstract-icon-view.c b/thunar/thunar-abstract-icon-view.c index c79b747..ffaa23b 100644 --- a/thunar/thunar-abstract-icon-view.c +++ b/thunar/thunar-abstract-icon-view.c @@ -515,7 +515,7 @@ thunar_abstract_icon_view_button_press_event (ExoIconView *view, return TRUE; } - else if ((event->type == GDK_BUTTON_PRESS || event->type == GDK_2BUTTON_PRESS) && event->button == 2) + else if (event->type == GDK_BUTTON_PRESS && event->button == 2) { /* unselect all currently selected items */ exo_icon_view_unselect_all (view); @@ -526,43 +526,28 @@ thunar_abstract_icon_view_button_press_event (ExoIconView *view, /* select only the path to the item on which the user clicked */ exo_icon_view_select_path (view, path); - /* if the event was a double-click or we are in single-click mode, then - * we'll open the file or folder (folder's are opened in new windows) - */ - if (G_LIKELY (event->type == GDK_2BUTTON_PRESS || exo_icon_view_get_single_click (view))) + /* determine the file for the path */ + gtk_tree_model_get_iter (GTK_TREE_MODEL (THUNAR_STANDARD_VIEW (abstract_icon_view)->model), &iter, path); + file = thunar_list_model_get_file (THUNAR_STANDARD_VIEW (abstract_icon_view)->model, &iter); + if (G_LIKELY (file != NULL) && thunar_file_is_directory (file)) { - /* determine the file for the path */ - gtk_tree_model_get_iter (GTK_TREE_MODEL (THUNAR_STANDARD_VIEW (abstract_icon_view)->model), &iter, path); - file = thunar_list_model_get_file (THUNAR_STANDARD_VIEW (abstract_icon_view)->model, &iter); - if (G_LIKELY (file != NULL)) - { - /* determine the action to perform depending on the type of the file */ - if (thunar_file_is_directory (file)) - { - /* lookup setting if we should open in a tab or a window */ - preferences = thunar_preferences_get (); - g_object_get (preferences, "misc-middle-click-in-tab", &in_tab, NULL); - g_object_unref (preferences); - - /* holding ctrl inverts the action */ - if ((event->state & GDK_CONTROL_MASK) != 0) - in_tab = !in_tab; - - action_name = in_tab ? "open-in-new-tab" : "open-in-new-window"; - } - else - { - action_name = "open"; - } - - /* emit the action */ - action = thunar_gtk_ui_manager_get_action_by_name (THUNAR_STANDARD_VIEW (abstract_icon_view)->ui_manager, action_name); - if (G_LIKELY (action != NULL)) - gtk_action_activate (action); - - /* release the file reference */ - g_object_unref (G_OBJECT (file)); - } + /* lookup setting if we should open in a tab or a window */ + preferences = thunar_preferences_get (); + g_object_get (preferences, "misc-middle-click-in-tab", &in_tab, NULL); + g_object_unref (preferences); + + /* holding ctrl inverts the action */ + if ((event->state & GDK_CONTROL_MASK) != 0) + in_tab = !in_tab; + action_name = in_tab ? "open-in-new-tab" : "open-in-new-window"; + + /* emit the action */ + action = thunar_gtk_ui_manager_get_action_by_name (THUNAR_STANDARD_VIEW (abstract_icon_view)->ui_manager, action_name); + if (G_LIKELY (action != NULL)) + gtk_action_activate (action); + + /* release the file reference */ + g_object_unref (G_OBJECT (file)); } /* cleanup */ diff --git a/thunar/thunar-details-view.c b/thunar/thunar-details-view.c index 05a539b..3da7fdb 100644 --- a/thunar/thunar-details-view.c +++ b/thunar/thunar-details-view.c @@ -703,7 +703,7 @@ thunar_details_view_button_press_event (GtkTreeView *tree_view, return TRUE; } - else if ((event->type == GDK_BUTTON_PRESS || event->type == GDK_2BUTTON_PRESS) && event->button == 2) + else if (event->type == GDK_BUTTON_PRESS && event->button == 2) { /* determine the path to the item that was middle-clicked */ if (gtk_tree_view_get_path_at_pos (tree_view, event->x, event->y, &path, NULL, NULL, NULL)) @@ -713,44 +713,30 @@ thunar_details_view_button_press_event (GtkTreeView *tree_view, gtk_tree_selection_unselect_all (selection); gtk_tree_selection_select_path (selection, path); - /* if the event was a double-click or we are in single-click mode, then - * we'll open the file or folder (folder's are opened in new windows) - */ - if (G_LIKELY (event->type == GDK_2BUTTON_PRESS || exo_tree_view_get_single_click (EXO_TREE_VIEW (tree_view)))) + /* determine the file for the path */ + gtk_tree_model_get_iter (GTK_TREE_MODEL (THUNAR_STANDARD_VIEW (details_view)->model), &iter, path); + file = thunar_list_model_get_file (THUNAR_STANDARD_VIEW (details_view)->model, &iter); + if (G_LIKELY (file != NULL) && thunar_file_is_directory (file)) { - /* determine the file for the path */ - gtk_tree_model_get_iter (GTK_TREE_MODEL (THUNAR_STANDARD_VIEW (details_view)->model), &iter, path); - file = thunar_list_model_get_file (THUNAR_STANDARD_VIEW (details_view)->model, &iter); - if (G_LIKELY (file != NULL)) - { - /* determine the action to perform depending on the type of the file */ - if (thunar_file_is_directory (file)) - { - /* lookup setting if we should open in a tab or a window */ - preferences = thunar_preferences_get (); - g_object_get (preferences, "misc-middle-click-in-tab", &in_tab, NULL); - g_object_unref (preferences); - - /* holding ctrl inverts the action */ - if ((event->state & GDK_CONTROL_MASK) != 0) - in_tab = !in_tab; - - action_name = in_tab ? "open-in-new-tab" : "open-in-new-window"; - } - else - { - action_name = "open"; - } - - action = thunar_gtk_ui_manager_get_action_by_name (THUNAR_STANDARD_VIEW (details_view)->ui_manager, action_name); - - /* emit the action */ - if (G_LIKELY (action != NULL)) - gtk_action_activate (action); - - /* release the file reference */ - g_object_unref (G_OBJECT (file)); - } + /* lookup setting if we should open in a tab or a window */ + preferences = thunar_preferences_get (); + g_object_get (preferences, "misc-middle-click-in-tab", &in_tab, NULL); + g_object_unref (preferences); + + /* holding ctrl inverts the action */ + if ((event->state & GDK_CONTROL_MASK) != 0) + in_tab = !in_tab; + + action_name = in_tab ? "open-in-new-tab" : "open-in-new-window"; + + action = thunar_gtk_ui_manager_get_action_by_name (THUNAR_STANDARD_VIEW (details_view)->ui_manager, action_name); + + /* emit the action */ + if (G_LIKELY (action != NULL)) + gtk_action_activate (action); + + /* release the file reference */ + g_object_unref (G_OBJECT (file)); } /* cleanup */ -- 2.2.1