Backspace FIles in Gnome 47 fedora 41

In fedora with gnome 39-46 i use this script in python for use key backspace go to back/parent directory, and it’s working

#!/usr/bin/env python
# created by linuxitos
import gi

gi.require_version('Nautilus', '4.0')
gi.require_version('Gtk', '4.0')
from gi.repository import GObject, Nautilus, Gtk, GLib

def idle_callback(*args):
    app = Gtk.Application.get_default()
    app.set_accels_for_action("win.up", ["BackSpace"])
    return False

def window_added(*args):
    GLib.idle_add(idle_callback, None)

class BackspaceBack(GObject.GObject, Nautilus.ColumnProvider):
        app = Gtk.Application.get_default()
        app.set_accels_for_action("win.up", ["BackSpace"])
        app.connect("window-added", window_added)

But in gnome 47 with fedora 41 beta, not working.

Can someone please help me?

A year ago, it helped me @coreyberla in gitlab gnome Is possible add shortcut with accels use backspace key for win.up? (#2545) · Issues · GNOME / Files · GitLab

It was changed from a window action to a slot action. Now it’s slot.up instead of win.up.

I changed and now It’s work, thanks.

1 Like

@reckor this script it’s working Linuxitos Inc / Backspace Nautilus · GitLab

This script does work partially, today I discovered that when I delete in the search bar, it does not work.

Is there any way to validate that it only works or capture the backspace inside the content of the folders and not in the browser?

Thank you very much.

I delete in the search bar, it does not work.

What does that mean? When press backspace to delete text? Or clicking backspace after clearing everything and closing the search bar?

Hello, thank you for your help.

I will try to explain:

The python script, adds the functionality to use the backspace key to go back to the previous directory.

However, when the browser is enabled, the backspace key is not enabled for text deletion, but still with the functionality to go back to the previous directory. The same happens when creating a new folder and trying to delete within the text field of the new folder name.

It is possible to add a condition that detects if the browser, or new folder is being added. Or, only apply the rollback when over the column.

Can you send me or tell me where I can find the actual documentation, or actual properties of nautilus 47?

Please, thank you.

I modifified code to this:

import gi

gi.require_version('Nautilus', '4.0')
gi.require_version('Gtk', '4.0')
from gi.repository import GObject, Nautilus, Gtk, GLib, Gdk

class BackspaceNavigation(GObject.GObject, Nautilus.MenuProvider):
    def __init__(self):
        super().__init__()
        app = Gtk.Application.get_default()
        if app:
            # Asignar la tecla "Retroceso" a la acción "slot.up" para todas las ventanas de Nautilus
            app.set_accels_for_action("slot.up", ["BackSpace"])
            app.connect("window-added", self.on_window_added)

    def on_window_added(self, app, window):
        if isinstance(window, Gtk.ApplicationWindow):
            window.connect("key-press-event", self.on_key_press)

    def on_key_press(self, widget, event):
        # Detectar si se presionó la tecla "BackSpace"
        if event.keyval == Gdk.KEY_BackSpace:
            focus_widget = widget.get_focus()

            # Si el foco está en un campo de texto, permitir el comportamiento normal
            if isinstance(focus_widget, (Gtk.Entry, Gtk.TextView, Gtk.SearchEntry)):
                return False  # Permitir el comportamiento estándar de borrado de texto

            # Si el foco no está en un campo de texto, manejar el evento y realizar la navegación hacia atrás
            return True  # Indicar que el evento ha sido manejado para evitar el comportamiento predeterminado

        return False  # Dejar otros eventos sin modificar

def init():
    return BackspaceNavigation()

But not working, how name widget, or entry search in new version?

Don’t think your extension will work without changing the code inside nautilus itself to claim the event because you’re using the app to register the event.

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.