summaryrefslogtreecommitdiff
path: root/src/nautilus-list-view.c
diff options
context:
space:
mode:
authorAlexandru Fazakas <alex.fazakas97@yahoo.com>2018-03-20 21:02:49 +0200
committerAlexandru Fazakas <alex.fazakas97@yahoo.com>2018-03-21 23:57:56 +0200
commit315d14585bf40188780d9433887a7b3681d28eb4 (patch)
tree02ba812b1b7f46508052d8179a81125102bc89dd /src/nautilus-list-view.c
parente3c01df382ac41ed4657463b9d4d60a7e7dff4a3 (diff)
downloadnautilus-315d14585bf40188780d9433887a7b3681d28eb4.tar.gz
list-view: Make list view selection consistent
Selecting rows using CTRL/SHIFT with left click is different to right click as GtkTreeView's default code does not support SHIFT+CTRL selection. We want consistency between the two behaviours. We fixed this by replicating the left click behaviour in the right click case. The GTK dependency is also bumped in order to use GtkTreePath autocleanup.
Diffstat (limited to 'src/nautilus-list-view.c')
-rw-r--r--src/nautilus-list-view.c47
1 files changed, 43 insertions, 4 deletions
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index 30308aded..d8a4e9104 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -678,6 +678,8 @@ button_press_callback (GtkWidget *widget,
}
else
{
+ g_autoptr (GtkTreePath) cursor = NULL;
+ GList *selected_rows = NULL;
if (event->button == GDK_BUTTON_SECONDARY)
{
if (path_selected)
@@ -690,6 +692,45 @@ button_press_callback (GtkWidget *widget,
*/
call_parent = FALSE;
}
+ else if ((event->state & GDK_CONTROL_MASK) != 0)
+ {
+ /* If CTRL is pressed, we don't allow the parent
+ * class to handle it, since GtkTreeView doesn't
+ * do it as intended currently.
+ */
+ call_parent = FALSE;
+ if ((event->state & GDK_SHIFT_MASK) != 0)
+ {
+ /* This is the CTRL+SHIFT selection mode which
+ * we handleourselves, as the parent class would
+ * otherwise do an unexpected selection.
+ */
+ gtk_tree_view_get_cursor (tree_view, &cursor, NULL);
+ if (cursor != NULL)
+ {
+ gtk_tree_selection_select_range (selection, cursor, path);
+ }
+ else
+ {
+ gtk_tree_selection_select_path (selection, path);
+ }
+ }
+ else
+ {
+ gtk_tree_selection_select_path (selection, path);
+ }
+ selected_rows = gtk_tree_selection_get_selected_rows (selection, NULL);
+
+ /* This unselects everything */
+ gtk_tree_view_set_cursor (tree_view, path, NULL, FALSE);
+
+ /* So select it again */
+ for (GList *l = selected_rows; l != NULL; l = l->next)
+ {
+ gtk_tree_selection_select_path (selection, l->data);
+ }
+ g_list_free_full (selected_rows, (GDestroyNotify) gtk_tree_path_free);
+ }
else if (on_expander)
{
/* If the right click happened on an expander, we should
@@ -698,6 +739,7 @@ button_press_callback (GtkWidget *widget,
gtk_tree_view_set_cursor (tree_view, path, NULL, FALSE);
}
}
+
if ((event->button == GDK_BUTTON_PRIMARY || event->button == GDK_BUTTON_MIDDLE) &&
((event->state & GDK_CONTROL_MASK) != 0 || (event->state & GDK_SHIFT_MASK) == 0))
{
@@ -710,12 +752,9 @@ button_press_callback (GtkWidget *widget,
}
else if ((event->state & GDK_CONTROL_MASK) != 0)
{
- GList *selected_rows, *l;
-
call_parent = FALSE;
if ((event->state & GDK_SHIFT_MASK) != 0)
{
- GtkTreePath *cursor;
gtk_tree_view_get_cursor (tree_view, &cursor, NULL);
if (cursor != NULL)
{
@@ -736,7 +775,7 @@ button_press_callback (GtkWidget *widget,
gtk_tree_view_set_cursor (tree_view, path, NULL, FALSE);
/* So select it again */
- for (l = selected_rows; l != NULL; l = l->next)
+ for (GList *l = selected_rows; l != NULL; l = l->next)
{
gtk_tree_selection_select_path (selection, l->data);
}