[epiphany] Add Alt+0 hotkey to toggle between last tabs



commit cc9535c7cb59eaaf1003e4cdd254fc082ccdb752
Author: Jan-Michael Brummer <jan brummer tabos org>
Date:   Sun Sep 27 16:02:33 2020 +0200

    Add Alt+0 hotkey to toggle between last tabs
    
    Fixes: https://gitlab.gnome.org/GNOME/epiphany/-/issues/1050

 src/ephy-notebook.c | 21 +++++++++++++++++++++
 src/ephy-notebook.h |  2 ++
 src/ephy-window.c   | 24 +++++++++++++++++++++++-
 3 files changed, 46 insertions(+), 1 deletion(-)
---
diff --git a/src/ephy-notebook.c b/src/ephy-notebook.c
index fb0e6aeaa..3526e4205 100644
--- a/src/ephy-notebook.c
+++ b/src/ephy-notebook.c
@@ -1162,3 +1162,24 @@ ephy_notebook_tab_is_pinned (EphyNotebook *notebook,
 
   return ephy_tab_label_is_pinned (tab_label);
 }
+
+void
+ephy_notebook_switch_to_last_tab (EphyNotebook *notebook)
+{
+  GList *l;
+  GtkWidget *child;
+  int page_num;
+
+  if (!notebook->focused_pages)
+    return;
+
+  l = g_list_last (notebook->focused_pages);
+  if (!l->prev)
+    return;
+
+  child = GTK_WIDGET (l->prev->data);
+  page_num = gtk_notebook_page_num (GTK_NOTEBOOK (notebook),
+                                    child);
+  gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook),
+                                 page_num);
+}
diff --git a/src/ephy-notebook.h b/src/ephy-notebook.h
index 46af51464..6f6c9f355 100644
--- a/src/ephy-notebook.h
+++ b/src/ephy-notebook.h
@@ -57,4 +57,6 @@ void           ephy_notebook_tab_set_pinned    (EphyNotebook *notebook,
 gboolean       ephy_notebook_tab_is_pinned     (EphyNotebook *notebook,
                                                 EphyEmbed    *embed);
 
+void           ephy_notebook_switch_to_last_tab (EphyNotebook *notebook);
+
 G_END_DECLS
diff --git a/src/ephy-window.c b/src/ephy-window.c
index a12057048..1711816fe 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -2637,6 +2637,17 @@ accel_cb_tabs_next (GtkWidget *widget,
   window_cmd_tabs_next (NULL, NULL, user_data);
 }
 
+static void
+last_tab_accel_activate (GSimpleAction *action,
+                         GVariant      *parameter,
+                         gpointer       user_data)
+{
+  EphyWindow *window = EPHY_WINDOW (user_data);
+  EphyNotebook *notebook = EPHY_NOTEBOOK (window->notebook);
+
+  ephy_notebook_switch_to_last_tab (notebook);
+}
+
 #define TAB_ACCELS_N 10
 
 static void
@@ -2646,11 +2657,12 @@ setup_tab_accels (EphyWindow *window)
   GApplication *app;
   guint i;
   DzlShortcutController *controller = dzl_shortcut_controller_find (GTK_WIDGET (window));
+  GSimpleAction *last_tab_action;
 
   action_group = gtk_widget_get_action_group (GTK_WIDGET (window), "tab");
   app = g_application_get_default ();
 
-  for (i = 0; i < TAB_ACCELS_N; i++) {
+  for (i = 0; i < TAB_ACCELS_N - 1; i++) {
     GSimpleAction *simple_action;
     char *action_name;
     char *action_name_with_tab;
@@ -2676,6 +2688,16 @@ setup_tab_accels (EphyWindow *window)
     g_free (action_name_with_tab);
   }
 
+  last_tab_action = g_simple_action_new ("switch-to-last-tab", NULL);
+  g_action_map_add_action (G_ACTION_MAP (action_group), G_ACTION (last_tab_action));
+  gtk_application_set_accels_for_action (GTK_APPLICATION (app),
+                                         "tab.switch-to-last-tab",
+                                         (const gchar *[]) {"<alt>0", NULL});
+
+  g_signal_connect (G_ACTION (last_tab_action), "activate",
+                    G_CALLBACK (last_tab_accel_activate), window);
+  g_object_unref (last_tab_action);
+
   /* We have to setup the Ctrl + Tab shortcut in the window's ShortcutController
    * because otherwise libdazzle would handle this shortcut by changing
    * the focused widget instead of switching between the browser tabs


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