[nautilus/wip/antoniof/make-sushi-work-again: 89/90] files-view: Make spacebar actually preview




commit 6bd3b8cd59c545ebda663b085935fac918f090fb
Author: António Fernandes <antoniof gnome org>
Date:   Mon Aug 15 20:11:44 2022 +0100

    files-view: Make spacebar actually preview
    
    We set spacebar as an action keybinding for previewing a file in sushi.
    
    But this keybinding gets overriden by GtkListItemWidget for its own
    `|listitem.select` action.
    
    Maybe we shouldn't use the spacebar as previewer shortcut in the first
    place, but that's how it's been so far. Also, we haven't been using
    it for selection in previous versions either.
    
    So, use a custom shortcut controller as a workaround.

 src/nautilus-files-view.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 9ddc1e1f3..14c2a1e59 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -9655,7 +9655,6 @@ nautilus_files_view_class_init (NautilusFilesViewClass *klass)
     gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Return, GDK_ALT_MASK, "view.properties", 
NULL);
     gtk_widget_class_add_binding_action (widget_class, GDK_KEY_a, GDK_CONTROL_MASK, "view.select-all", NULL);
     gtk_widget_class_add_binding_action (widget_class, GDK_KEY_i, GDK_CONTROL_MASK | GDK_SHIFT_MASK, 
"view.invert-selection", NULL);
-    gtk_widget_class_add_binding_action (widget_class, GDK_KEY_space, 0, "view.preview-selection", NULL);
     gtk_widget_class_add_binding_action (widget_class, GDK_KEY_m, GDK_CONTROL_MASK, "view.create-link", 
NULL);
     gtk_widget_class_add_binding_action (widget_class, GDK_KEY_m, GDK_CONTROL_MASK, 
"view.create-link-shortcut", NULL);
     gtk_widget_class_add_binding_action (widget_class, GDK_KEY_m, GDK_CONTROL_MASK | GDK_SHIFT_MASK, 
"view.create-link-in-place", NULL);
@@ -9675,6 +9674,7 @@ nautilus_files_view_init (NautilusFilesView *view)
     NautilusDirectory *scripts_directory;
     NautilusDirectory *templates_directory;
     GtkEventController *controller;
+    GtkShortcut *shortcut;
     gchar *templates_uri;
     GdkClipboard *clipboard;
     GApplication *app;
@@ -9835,6 +9835,23 @@ nautilus_files_view_init (NautilusFilesView *view)
     nautilus_application_set_accelerator (app, "view.select-pattern", "<control>s");
     nautilus_application_set_accelerators (app, "view.zoom-standard", zoom_standard_accels);
 
+    /* This one should have been a keybinding, because it should trigger only
+     * when the view is focused. Unfortunately, children can override bindings,
+     * and such is the case of GtkListItemWidget which binds the spacebar to its
+     * `|listitem.select` action.
+     *
+     * So, we make it a local shortcut (like keybindings are), but using the
+     * capture phase instead, to trigger it first (keybindings use bubble phase).
+     */
+    shortcut = gtk_shortcut_new (gtk_keyval_trigger_new (GDK_KEY_space, 0),
+                                 gtk_named_action_new ("view.preview-selection"));
+
+    controller = gtk_shortcut_controller_new ();
+    gtk_widget_add_controller (GTK_WIDGET (view), controller);
+    /* By default, :scope is GTK_SHORTCUT_SCOPE_LOCAL, so no need to set it. */
+    gtk_event_controller_set_propagation_phase (controller, GTK_PHASE_CAPTURE);
+    gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller), shortcut);
+
     priv->starred_cancellable = g_cancellable_new ();
 
     priv->rename_file_controller = nautilus_rename_file_popover_controller_new (GTK_WIDGET (view));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]