[nautilus: 2/3] list-view: Make list view selection consistent
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus: 2/3] list-view: Make list view selection consistent
- Date: Wed, 21 Mar 2018 22:07:56 +0000 (UTC)
commit 315d14585bf40188780d9433887a7b3681d28eb4
Author: Alexandru Fazakas <alex fazakas97 yahoo com>
Date: Tue Mar 20 21:02:49 2018 +0200
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.
meson.build | 2 +-
src/nautilus-list-view.c | 47 +++++++++++++++++++++++++++++++++++++++++++----
2 files changed, 44 insertions(+), 5 deletions(-)
---
diff --git a/meson.build b/meson.build
index 99126aadb..cd3006932 100644
--- a/meson.build
+++ b/meson.build
@@ -79,7 +79,7 @@ glib = dependency('glib-2.0', version: glib_ver)
gmodule = dependency('gmodule-no-export-2.0', version: glib_ver)
gnome_autoar = dependency('gnome-autoar-0', version: '>= 0.2.1')
gnome_desktop = dependency('gnome-desktop-3.0', version: '>= 3.0.0')
-gtk = dependency('gtk+-3.0', version: '>= 3.22.26')
+gtk = dependency('gtk+-3.0', version: '>= 3.22.27')
selinux = []
if get_option('selinux')
selinux = dependency('libselinux', version: '>= 2.0')
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);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]