Commit 617e83a0 authored by Reuben Green's avatar Reuben Green

Reduce selection to just clicked file in icon and compact views

Fix multiple file selection in thunar-abstract-icon-view so that
when one file from a multiple selection is clicked, the selection
is reduced to just that file. This makes the behaviour consistent
with details view. This is a work around for issue exo#39.
parent ee3301a2
......@@ -107,9 +107,9 @@ struct _ThunarAbstractIconViewPrivate
gint gesture_current_y;
gulong gesture_expose_id;
gulong gesture_motion_id;
gulong gesture_release_id;
gboolean button_pressed;
gboolean move_since_button_press;
};
......@@ -202,6 +202,7 @@ thunar_abstract_icon_view_init (ThunarAbstractIconView *abstract_icon_view)
view = exo_icon_view_new ();
g_signal_connect (G_OBJECT (view), "notify::model", G_CALLBACK (thunar_abstract_icon_view_notify_model), 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), "button-release-event", G_CALLBACK (thunar_abstract_icon_view_button_release_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_swapped (G_OBJECT (view), "selection-changed", G_CALLBACK (thunar_standard_view_selection_changed), abstract_icon_view);
......@@ -583,6 +584,7 @@ thunar_abstract_icon_view_button_press_event (ExoIconView *view,
GtkTreePath *path;
abstract_icon_view->priv->button_pressed = TRUE;
abstract_icon_view->priv->move_since_button_press = FALSE;
if (event->type == GDK_BUTTON_PRESS && event->button == 3)
{
......@@ -642,9 +644,6 @@ thunar_abstract_icon_view_button_press_event (ExoIconView *view,
abstract_icon_view->priv->gesture_motion_id = g_signal_connect (G_OBJECT (view), "motion-notify-event",
G_CALLBACK (thunar_abstract_icon_view_motion_notify_event),
G_OBJECT (abstract_icon_view));
abstract_icon_view->priv->gesture_release_id = g_signal_connect (G_OBJECT (view), "button-release-event",
G_CALLBACK (thunar_abstract_icon_view_button_release_event),
G_OBJECT (abstract_icon_view));
}
/* don't run the default handler here */
......@@ -661,36 +660,50 @@ thunar_abstract_icon_view_button_release_event (ExoIconView *view,
GdkEventButton *event,
ThunarAbstractIconView *abstract_icon_view)
{
const XfceGtkActionEntry *action_entry;
GtkWidget *window;
_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);
_thunar_return_val_if_fail (abstract_icon_view->priv->gesture_expose_id > 0, FALSE);
_thunar_return_val_if_fail (abstract_icon_view->priv->gesture_motion_id > 0, FALSE);
_thunar_return_val_if_fail (abstract_icon_view->priv->gesture_release_id > 0, FALSE);
window = gtk_widget_get_toplevel (GTK_WIDGET (abstract_icon_view));
/* if we are doing a gesture, execute it */
if (abstract_icon_view->priv->gesture_expose_id > 0)
{
const XfceGtkActionEntry *action_entry;
GtkWidget *window;
/* execute the related callback (if any) */
action_entry = thunar_abstract_icon_view_gesture_action (abstract_icon_view);
if (G_LIKELY (action_entry != NULL))
((void(*)(GtkWindow*))action_entry->callback)(GTK_WINDOW (window));
_thunar_return_val_if_fail (abstract_icon_view->priv->gesture_motion_id > 0, FALSE);
window = gtk_widget_get_toplevel (GTK_WIDGET (abstract_icon_view));
/* unregister the "expose-event" handler */
g_signal_handler_disconnect (G_OBJECT (view), abstract_icon_view->priv->gesture_expose_id);
abstract_icon_view->priv->gesture_expose_id = 0;
/* execute the related callback (if any) */
action_entry = thunar_abstract_icon_view_gesture_action (abstract_icon_view);
if (G_LIKELY (action_entry != NULL))
((void(*)(GtkWindow*))action_entry->callback)(GTK_WINDOW (window));
/* unregister the "motion-notify-event" handler */
g_signal_handler_disconnect (G_OBJECT (view), abstract_icon_view->priv->gesture_motion_id);
abstract_icon_view->priv->gesture_motion_id = 0;
/* unregister the "expose-event" handler */
g_signal_handler_disconnect (G_OBJECT (view), abstract_icon_view->priv->gesture_expose_id);
abstract_icon_view->priv->gesture_expose_id = 0;
/* unregister the "button-release-event" handler */
g_signal_handler_disconnect (G_OBJECT (view), abstract_icon_view->priv->gesture_release_id);
abstract_icon_view->priv->gesture_release_id = 0;
/* unregister the "motion-notify-event" handler */
g_signal_handler_disconnect (G_OBJECT (view), abstract_icon_view->priv->gesture_motion_id);
abstract_icon_view->priv->gesture_motion_id = 0;
/* redraw the abstract_icon view */
gtk_widget_queue_draw (GTK_WIDGET (view));
}
/* if we are not doing a gesture and the user has left-clicked and released an item with no modifier
* keys pressed, reduce the selection to just that item */
else if (event->button == 1 && !abstract_icon_view->priv->move_since_button_press &&
(event->state & GDK_CONTROL_MASK) == 0 && (event->state & GDK_SHIFT_MASK) == 0)
{
GtkTreePath *path;
/* redraw the abstract_icon view */
gtk_widget_queue_draw (GTK_WIDGET (view));
/* if an item was clicked, reduce the selection to just that item */
if (exo_icon_view_get_item_at_pos (view, event->x, event->y, &path, NULL))
{
exo_icon_view_unselect_all (view);
exo_icon_view_select_path (view, path);
gtk_tree_path_free (path);
}
}
return FALSE;
}
......@@ -710,7 +723,6 @@ thunar_abstract_icon_view_draw (ExoIconView *view,
_thunar_return_val_if_fail (THUNAR_IS_ABSTRACT_ICON_VIEW (abstract_icon_view), FALSE);
_thunar_return_val_if_fail (abstract_icon_view->priv->gesture_expose_id > 0, FALSE);
_thunar_return_val_if_fail (abstract_icon_view->priv->gesture_motion_id > 0, FALSE);
_thunar_return_val_if_fail (abstract_icon_view->priv->gesture_release_id > 0, FALSE);
/* shade the abstract_icon view content while performing mouse gestures */
cairo_set_source_rgba (cr, 1, 1, 1, 0.7);
......@@ -779,7 +791,6 @@ thunar_abstract_icon_view_motion_notify_event (ExoIconView *view,
_thunar_return_val_if_fail (THUNAR_IS_ABSTRACT_ICON_VIEW (abstract_icon_view), FALSE);
_thunar_return_val_if_fail (abstract_icon_view->priv->gesture_expose_id > 0, FALSE);
_thunar_return_val_if_fail (abstract_icon_view->priv->gesture_motion_id > 0, FALSE);
_thunar_return_val_if_fail (abstract_icon_view->priv->gesture_release_id > 0, FALSE);
/* schedule a complete redraw on the first motion event */
if (abstract_icon_view->priv->gesture_current_x == abstract_icon_view->priv->gesture_start_x
......@@ -800,6 +811,9 @@ thunar_abstract_icon_view_motion_notify_event (ExoIconView *view,
abstract_icon_view->priv->gesture_current_x = event->x;
abstract_icon_view->priv->gesture_current_y = event->y;
/* record that there has been a motion since the last button press */
abstract_icon_view->priv->move_since_button_press = TRUE;
/* don't execute the default motion notify handler */
return TRUE;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment