[nautilus] Files-view: Rely on GTK default item activation shortcuts
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] Files-view: Rely on GTK default item activation shortcuts
- Date: Sat, 11 Jun 2022 23:27:38 +0000 (UTC)
commit 63c61efaebfcce4cf0f6e9ae2cd464d51695eee9
Author: vanadiae <vanadiae35 gmail com>
Date: Sun May 29 19:03:13 2022 +0200
Files-view: Rely on GTK default item activation shortcuts
Currently it is not possible to activate any UI element with Enter on
the keyboard, because it always activates either the selected file in
the files view, or it activates the secondary menu next to the path.
This is because a) NautilusFilesView registers a global application
accelerator for Enter/Return, to activate the selected files, b) it
should really not have registered a custom shortcut for that to begin
with, instead it should use the grid view or list view's
"(row-)activate(d)" signals, which is already the case for the later.
Hence drops this Enter/Return global accelerator, and hooks up the
NautilusIconViewController to its grid view's "activated" signal.
Fixes https://gitlab.gnome.org/GNOME/nautilus/-/issues/2225
src/nautilus-files-view.c | 2 --
src/nautilus-view-icon-controller.c | 29 ++++++++++++++++++++++++++---
2 files changed, 26 insertions(+), 5 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 7aeaed6d5..4cf5290a9 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -9341,8 +9341,6 @@ nautilus_files_view_init (NautilusFilesView *view)
GApplication *app;
const gchar *open_accels[] =
{
- "Return",
- "KP_Enter",
"<control>o",
"<alt>Down",
NULL
diff --git a/src/nautilus-view-icon-controller.c b/src/nautilus-view-icon-controller.c
index 43c710ece..94feef1bc 100644
--- a/src/nautilus-view-icon-controller.c
+++ b/src/nautilus-view-icon-controller.c
@@ -786,6 +786,24 @@ activate_selection_on_click (NautilusViewIconController *self,
nautilus_files_view_activate_files (files_view, selection, flags, TRUE);
}
+/* We only care about the keyboard activation part that GtkGridView provides,
+ * but we don't need any special filtering here. Indeed, we ask GtkGridView
+ * to not activate on single click, and we get to handle double clicks before
+ * GtkGridView does (as one of widget subclassing's goal is to modify the parent
+ * class's behavior), while claiming the click gestures, so it means GtkGridView
+ * will never react to a click event to emit this signal. So we should be pretty
+ * safe here with regards to our custom item click handling.
+ */
+static void
+on_grid_view_item_activated (GtkGridView *grid_view,
+ guint position,
+ gpointer user_data)
+{
+ NautilusViewIconController *self = NAUTILUS_VIEW_ICON_CONTROLLER (user_data);
+
+ nautilus_files_view_activate_selection (NAUTILUS_FILES_VIEW (self));
+}
+
static void
on_item_click_pressed (GtkGestureClick *gesture,
gint n_press,
@@ -1490,9 +1508,9 @@ create_view_ui (NautilusViewIconController *self)
gtk_widget_set_focusable (widget, TRUE);
gtk_widget_set_valign (widget, GTK_ALIGN_START);
- /* We don't use the built-in child activation feature because it doesn't
- * fill all our needs nor does it match our expected behavior. Instead, we
- * roll our own event handling and double/single click mode.
+ /* We don't use the built-in child activation feature for clicks because it
+ * doesn't fill all our needs nor does it match our expected behavior.
+ * Instead, we roll our own event handling and double/single click mode.
* However, GtkGridView:single-click-activate has other effects besides
* activation, as it affects the selection behavior as well (e.g. selects on
* hover). Setting it to FALSE gives us the expected behavior. */
@@ -1500,6 +1518,11 @@ create_view_ui (NautilusViewIconController *self)
gtk_grid_view_set_max_columns (GTK_GRID_VIEW (widget), 20);
gtk_grid_view_set_enable_rubberband (GTK_GRID_VIEW (widget), TRUE);
+ /* While we don't want to use GTK's click activation, we'll let it handle
+ * the key activation part (with Enter).
+ */
+ g_signal_connect (widget, "activate", G_CALLBACK (on_grid_view_item_activated), self);
+
return GTK_GRID_VIEW (widget);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]