From 0affbedf988b00cc0c37e081f65e9a8cecb1c079 Mon Sep 17 00:00:00 2001 From: Reuben Green Date: Tue, 18 Feb 2020 13:53:58 +0000 Subject: [PATCH] Allow opening of multiple file selections (bug #2487) Allow multiple file selections to be opened by pressing enter, space, or Ctrl^O. Fixes bug #2487 --- thunar/thunar-abstract-icon-view.c | 36 +++++++++++++++++++++++---- thunar/thunar-details-view.c | 39 +++++++++++++++++++++++++++--- 2 files changed, 66 insertions(+), 9 deletions(-) diff --git a/thunar/thunar-abstract-icon-view.c b/thunar/thunar-abstract-icon-view.c index 91ee300a..f8c9c350 100644 --- a/thunar/thunar-abstract-icon-view.c +++ b/thunar/thunar-abstract-icon-view.c @@ -85,6 +85,8 @@ static gboolean thunar_abstract_icon_view_motion_notify_event (ExoIconView static void thunar_abstract_icon_view_item_activated (ExoIconView *view, GtkTreePath *path, ThunarAbstractIconView *abstract_icon_view); +static gboolean thunar_abstract_icon_view_activate_cursor_item (ExoIconView *view, + ThunarAbstractIconView *abstract_icon_view); static void thunar_abstract_icon_view_sort_column_changed (GtkTreeSortable *sortable, ThunarAbstractIconView *abstract_icon_view); static void thunar_abstract_icon_view_zoom_level_changed (ThunarAbstractIconView *abstract_icon_view); @@ -202,6 +204,8 @@ thunar_abstract_icon_view_init (ThunarAbstractIconView *abstract_icon_view) g_signal_connect (G_OBJECT (view), "button-press-event", G_CALLBACK (thunar_abstract_icon_view_button_press_event), abstract_icon_view); g_signal_connect (G_OBJECT (view), "key-press-event", G_CALLBACK (thunar_abstract_icon_view_key_press_event), abstract_icon_view); g_signal_connect (G_OBJECT (view), "item-activated", G_CALLBACK (thunar_abstract_icon_view_item_activated), abstract_icon_view); + g_signal_connect (G_OBJECT (view), "activate-cursor-item", G_CALLBACK (thunar_abstract_icon_view_activate_cursor_item), + abstract_icon_view); g_signal_connect_swapped (G_OBJECT (view), "selection-changed", G_CALLBACK (thunar_standard_view_selection_changed), abstract_icon_view); gtk_container_add (GTK_CONTAINER (abstract_icon_view), view); gtk_widget_show (view); @@ -492,7 +496,14 @@ thunar_abstract_icon_view_button_press_event (ExoIconView *view, gboolean in_tab; const gchar *action_name; - if (event->type == GDK_BUTTON_PRESS && event->button == 3) + if (event->type == GDK_BUTTON_PRESS && event->button == 1) + { + /* we don't unselect all other items if Control or Shift is active */ + if ((event->state & GDK_CONTROL_MASK) == 0 && (event->state & GDK_SHIFT_MASK) == 0) + exo_icon_view_unselect_all (view); + return FALSE; + } + else if (event->type == GDK_BUTTON_PRESS && event->button == 3) { /* open the context menu on right clicks */ if (exo_icon_view_get_item_at_pos (view, event->x, event->y, &path, NULL)) @@ -750,10 +761,6 @@ thunar_abstract_icon_view_item_activated (ExoIconView *view, _thunar_return_if_fail (THUNAR_IS_ABSTRACT_ICON_VIEW (abstract_icon_view)); - /* be sure to have only the double clicked item selected */ - exo_icon_view_unselect_all (view); - exo_icon_view_select_path (view, path); - G_GNUC_BEGIN_IGNORE_DEPRECATIONS /* emit the "open" action */ action = thunar_gtk_ui_manager_get_action_by_name (THUNAR_STANDARD_VIEW (abstract_icon_view)->ui_manager, "open"); @@ -764,6 +771,25 @@ G_GNUC_END_IGNORE_DEPRECATIONS +static gboolean +thunar_abstract_icon_view_activate_cursor_item (ExoIconView *view, + ThunarAbstractIconView *abstract_icon_view) +{ + GList *selected_items; + + _thunar_return_val_if_fail (EXO_IS_ICON_VIEW (view), FALSE); + _thunar_return_val_if_fail (THUNAR_IS_ABSTRACT_ICON_VIEW (abstract_icon_view), FALSE); + + /* ensure that the cursor in the exo_icon_view so that any selected items do get activated */ + selected_items = thunar_abstract_icon_view_get_selected_items (THUNAR_STANDARD_VIEW (abstract_icon_view)); + if(selected_items != NULL) + exo_icon_view_set_cursor (view,selected_items->data, NULL, FALSE); + + return TRUE; +} + + + static void thunar_abstract_icon_view_sort_column_changed (GtkTreeSortable *sortable, ThunarAbstractIconView *abstract_icon_view) diff --git a/thunar/thunar-details-view.c b/thunar/thunar-details-view.c index 9409663a..7cf634a2 100644 --- a/thunar/thunar-details-view.c +++ b/thunar/thunar-details-view.c @@ -93,6 +93,9 @@ static void thunar_details_view_row_activated (GtkTreeView GtkTreePath *path, GtkTreeViewColumn *column, ThunarDetailsView *details_view); +static gboolean thunar_details_view_select_cursor_row (GtkTreeView *tree_view, + gboolean editing, + ThunarDetailsView *details_view); static void thunar_details_view_row_changed (GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, @@ -221,6 +224,8 @@ G_GNUC_END_IGNORE_DEPRECATIONS G_CALLBACK (thunar_details_view_key_press_event), details_view); g_signal_connect (G_OBJECT (tree_view), "row-activated", G_CALLBACK (thunar_details_view_row_activated), details_view); + g_signal_connect (G_OBJECT (tree_view), "select-cursor-row", + G_CALLBACK (thunar_details_view_select_cursor_row), details_view); gtk_container_add (GTK_CONTAINER (details_view), tree_view); gtk_widget_show (tree_view); @@ -837,10 +842,34 @@ thunar_details_view_row_activated (GtkTreeView *tree_view, _thunar_return_if_fail (THUNAR_IS_DETAILS_VIEW (details_view)); - /* be sure to have only the double clicked item selected */ - selection = gtk_tree_view_get_selection (tree_view); - gtk_tree_selection_unselect_all (selection); - gtk_tree_selection_select_path (selection, path); +G_GNUC_BEGIN_IGNORE_DEPRECATIONS + /* emit the "open" action */ + action = thunar_gtk_ui_manager_get_action_by_name (THUNAR_STANDARD_VIEW (details_view)->ui_manager, "open"); + if (G_LIKELY (action != NULL)) + gtk_action_activate (action); +G_GNUC_END_IGNORE_DEPRECATIONS +} + + + +static gboolean +thunar_details_view_select_cursor_row (GtkTreeView *tree_view, + gboolean editing, + ThunarDetailsView *details_view) +{ + /* This function is a work-around to fix bug #2487. The default gtk handler for + * the "select-cursor-row" signal changes the selection to just the cursor row, + * which prevents multiple file selections being opened. Thus we bypass the gtk + * signal handler with g_signal_stop_emission_by_name, and emit the "open" action + * directly. A better long-term solution would be to fix exo to avoid using the + * default gtk signal handler there. + */ + + GtkAction *action; + + _thunar_return_val_if_fail (THUNAR_IS_DETAILS_VIEW (details_view), FALSE); + + g_signal_stop_emission_by_name(tree_view,"select-cursor-row"); G_GNUC_BEGIN_IGNORE_DEPRECATIONS /* emit the "open" action */ @@ -848,6 +877,8 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS if (G_LIKELY (action != NULL)) gtk_action_activate (action); G_GNUC_END_IGNORE_DEPRECATIONS + + return TRUE; } -- 2.25.0