[nautilus/wip/antoniof/gtk4-preparation-drop-outgoing-api: 20/49] window: Set media keys as regular accels




commit 99506f1ad33fa5687b02652faa2ddf070f0306c5
Author: António Fernandes <antoniof gnome org>
Date:   Sun Aug 8 10:42:19 2021 +0100

    window: Set media keys as regular accels
    
    Media keys are handled in the ::key-press-event signal.
    
    This signal is going away in GTK4 and there is no reason not to set
    these keyboard shortcuts the same way as all other accels.

 src/nautilus-window.c | 88 +++++++++++++++++++++++----------------------------
 1 file changed, 40 insertions(+), 48 deletions(-)
---
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 1e1e16f30..ef0519db2 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -164,25 +164,6 @@ static guint signals[LAST_SIGNAL] = { 0 };
 
 G_DEFINE_TYPE (NautilusWindow, nautilus_window, HDY_TYPE_APPLICATION_WINDOW);
 
-static const struct
-{
-    unsigned int keyval;
-    const char *action;
-} extra_window_keybindings [] =
-{
-    /* Window actions */
-    { GDK_KEY_AddFavorite, "bookmark-current-location" },
-    { GDK_KEY_Go, "enter-location" },
-    { GDK_KEY_HomePage, "go-home" },
-    { GDK_KEY_OpenURL, "enter-location" },
-    { GDK_KEY_Refresh, "reload" },
-    { GDK_KEY_Reload, "reload" },
-    { GDK_KEY_Start, "go-home" },
-    { GDK_KEY_Stop, "stop" },
-    { GDK_KEY_Back, "back" },
-    { GDK_KEY_Forward, "forward" },
-};
-
 static const GtkPadActionEntry pad_actions[] =
 {
     { GTK_PAD_ACTION_BUTTON, 0, -1, N_("Parent folder"), "up" },
@@ -2054,10 +2035,44 @@ nautilus_window_initialize_actions (NautilusWindow *window)
     gchar detailed_action[80];
     gchar accel[80];
     gint i;
+    const gchar *back_accels[] =
+    {
+        "<alt>Left",
+        "Back",
+        NULL
+    };
+    const gchar *forward_accels[] =
+    {
+        "<alt>Right",
+        "Forward",
+        NULL
+    };
+    const gchar *enter_location_accels[] =
+    {
+        "<control>l",
+        "Go",
+        "OpenURL",
+        NULL
+    };
     const gchar *reload_accels[] =
     {
         "F5",
         "<ctrl>r",
+        "Refresh",
+        "Reload",
+        NULL
+    };
+    const gchar *bookmark_current_location_accels[] =
+    {
+        "<control>d",
+        "AddFavorite",
+        NULL
+    };
+    const gchar *go_home_accels[] =
+    {
+        "<alt>Home",
+        "HomePage",
+        "Start",
         NULL
     };
     const gchar *prompt_root_location_accels[] =
@@ -2078,21 +2093,22 @@ nautilus_window_initialize_actions (NautilusWindow *window)
                                      window);
 
     app = g_application_get_default ();
-    nautilus_application_set_accelerator (app, "win.back", "<alt>Left");
-    nautilus_application_set_accelerator (app, "win.forward", "<alt>Right");
-    nautilus_application_set_accelerator (app, "win.enter-location", "<control>l");
+    nautilus_application_set_accelerators (app, "win.back", back_accels);
+    nautilus_application_set_accelerators (app, "win.forward", forward_accels);
+    nautilus_application_set_accelerators (app, "win.enter-location", enter_location_accels);
     nautilus_application_set_accelerator (app, "win.new-tab", "<control>t");
     nautilus_application_set_accelerator (app, "win.close-current-view", "<control>w");
 
     /* Special case reload, since users are used to use two shortcuts instead of one */
     nautilus_application_set_accelerators (app, "win.reload", reload_accels);
+    nautilus_application_set_accelerator (app, "win.stop", "Stop");
 
     nautilus_application_set_accelerator (app, "win.undo", "<control>z");
     nautilus_application_set_accelerator (app, "win.redo", "<shift><control>z");
     /* Only accesible by shorcuts */
-    nautilus_application_set_accelerator (app, "win.bookmark-current-location", "<control>d");
+    nautilus_application_set_accelerators (app, "win.bookmark-current-location", 
bookmark_current_location_accels);
     nautilus_application_set_accelerator (app, "win.up", "<alt>Up");
-    nautilus_application_set_accelerator (app, "win.go-home", "<alt>Home");
+    nautilus_application_set_accelerators (app, "win.go-home", go_home_accels);
     nautilus_application_set_accelerator (app, "win.go-starred", "Favorites");
     nautilus_application_set_accelerator (app, "win.tab-previous", "<control>Page_Up");
     nautilus_application_set_accelerator (app, "win.tab-next", "<control>Page_Down");
@@ -2425,30 +2441,6 @@ nautilus_window_key_press_event (GtkWidget   *widget,
         }
     }
 
-    for (int i = 0; i < G_N_ELEMENTS (extra_window_keybindings); i++)
-    {
-        if (extra_window_keybindings[i].keyval == keyval)
-        {
-            GAction *action;
-
-            action = g_action_map_lookup_action (G_ACTION_MAP (window), extra_window_keybindings[i].action);
-
-            g_assert (action != NULL);
-            if (g_action_get_enabled (action))
-            {
-                g_action_activate (action, NULL);
-                return GDK_EVENT_STOP;
-            }
-
-            break;
-        }
-    }
-
-    if (GTK_WIDGET_CLASS (nautilus_window_parent_class)->key_press_event (widget, event))
-    {
-        return GDK_EVENT_STOP;
-    }
-
     if (window->active_slot != NULL &&
         nautilus_window_slot_handle_event (window->active_slot, (GdkEvent *) event))
     {


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