From 1c3cebfbbb98ec7194ffe23198ddb625379b0ca3 Mon Sep 17 00:00:00 2001 From: Theo Linkspfeifer Date: Sun, 12 Apr 2020 15:30:37 +0100 Subject: [PATCH] Allow drag-and-drop of multiple files in icon view (Bug #2487) Fixes a bug introduced by commit 9801a67b3a165fc1be81b520ec28b5529a9ab822 which broke multiple file drag-and-drop in icon and compact view. Co-authored-by: Reuben Green --- thunar/thunar-abstract-icon-view.c | 32 ++++++++++++++++++------------ thunar/thunar-details-view.c | 16 +++++++++++++++ 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/thunar/thunar-abstract-icon-view.c b/thunar/thunar-abstract-icon-view.c index f8c9c350..bb72f6b5 100644 --- a/thunar/thunar-abstract-icon-view.c +++ b/thunar/thunar-abstract-icon-view.c @@ -106,6 +106,8 @@ struct _ThunarAbstractIconViewPrivate gulong gesture_expose_id; gulong gesture_motion_id; gulong gesture_release_id; + + gboolean button_pressed; }; @@ -204,8 +206,7 @@ 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 (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); @@ -496,14 +497,9 @@ thunar_abstract_icon_view_button_press_event (ExoIconView *view, gboolean in_tab; const gchar *action_name; - 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) + abstract_icon_view->priv->button_pressed = TRUE; + + 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)) @@ -702,6 +698,8 @@ thunar_abstract_icon_view_key_press_event (ExoIconView *view, GdkEventKey *event, ThunarAbstractIconView *abstract_icon_view) { + abstract_icon_view->priv->button_pressed = FALSE; + /* popup context menu if "Menu" or "F10" is pressed */ if (event->keyval == GDK_KEY_Menu || ((event->state & GDK_SHIFT_MASK) != 0 && event->keyval == GDK_KEY_F10)) { @@ -761,6 +759,13 @@ 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 clicked item selected */ + if (abstract_icon_view->priv->button_pressed) + { + 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"); @@ -780,10 +785,11 @@ thunar_abstract_icon_view_activate_cursor_item (ExoIconView *view, _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 */ + /* ensure that the cursor in the exo_icon_view is set so that any selected items do get activated */ + // TODO probably fixed by https://git.xfce.org/xfce/exo/commit/?id=dba8f14 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); + if (selected_items != NULL) + exo_icon_view_set_cursor (view, selected_items->data, NULL, FALSE); return TRUE; } diff --git a/thunar/thunar-details-view.c b/thunar/thunar-details-view.c index 9967b090..68729828 100644 --- a/thunar/thunar-details-view.c +++ b/thunar/thunar-details-view.c @@ -131,6 +131,9 @@ struct _ThunarDetailsView /* the UI manager merge id for the details view */ guint ui_merge_id; + + /* whether the most recent item activation used a mouse button press */ + gboolean button_pressed; }; @@ -700,6 +703,8 @@ thunar_details_view_button_press_event (GtkTreeView *tree_view, { GtkTreePath *cursor_path; + details_view->button_pressed = TRUE; + /* grab the tree view */ gtk_widget_grab_focus (GTK_WIDGET (tree_view)); @@ -819,6 +824,8 @@ thunar_details_view_key_press_event (GtkTreeView *tree_view, GdkEventKey *event, ThunarDetailsView *details_view) { + details_view->button_pressed = FALSE; + /* popup context menu if "Menu" or "F10" is pressed */ if (event->keyval == GDK_KEY_Menu || ((event->state & GDK_SHIFT_MASK) != 0 && event->keyval == GDK_KEY_F10)) { @@ -837,10 +844,19 @@ thunar_details_view_row_activated (GtkTreeView *tree_view, GtkTreeViewColumn *column, ThunarDetailsView *details_view) { + GtkTreeSelection *selection; GtkAction *action; _thunar_return_if_fail (THUNAR_IS_DETAILS_VIEW (details_view)); + /* be sure to have only the clicked item selected */ + if (details_view->button_pressed) + { + 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"); -- 2.25.1