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




commit 3d1c2e940c465ca84a66a5dc537aa7fce9472727
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 | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 32f08cce6..6699f4219 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -9606,7 +9606,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);
@@ -9626,6 +9625,7 @@ nautilus_files_view_init (NautilusFilesView *view)
     NautilusDirectory *scripts_directory;
     NautilusDirectory *templates_directory;
     GtkEventController *controller;
+    GtkShortcut *shortcut;
     gchar *templates_uri;
     GdkClipboard *clipboard;
     GApplication *app;
@@ -9786,6 +9786,22 @@ 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 shortcuts here, but use
+     * the capture phase to trigger before keybindings (which 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);
+    gtk_shortcut_controller_set_scope (GTK_SHORTCUT_CONTROLLER (controller),
+                                       GTK_SHORTCUT_SCOPE_LOCAL);
+    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]