[devhelp] accels: add support for ctrl+pgup/pgdown to switch between tabs



commit 6f3ceaf3f86c48e48e97fe2bc018ecb62d864b8b
Author: Nirbheek Chauhan <nirbheek centricular com>
Date:   Tue Oct 27 16:32:13 2015 +0530

    accels: add support for ctrl+pgup/pgdown to switch between tabs
    
    The switching wraps because that's how Terminal and Epiphany do things.
    The code is modified from Epiphany's code to wrap while switching.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=757177

 src/dh-app.c    |    6 ++++++
 src/dh-window.c |   49 ++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 54 insertions(+), 1 deletions(-)
---
diff --git a/src/dh-app.c b/src/dh-app.c
index a7d9985..876f3f9 100644
--- a/src/dh-app.c
+++ b/src/dh-app.c
@@ -375,6 +375,12 @@ setup_accelerators (DhApp *self)
         accels[0] = "<Primary>t";
         gtk_application_set_accels_for_action (GTK_APPLICATION (self), "win.new-tab", accels);
 
+        accels[0] = "<Primary>Page_Down";
+        gtk_application_set_accels_for_action (GTK_APPLICATION (self), "win.next-tab", accels);
+
+        accels[0] = "<Primary>Page_Up";
+        gtk_application_set_accels_for_action (GTK_APPLICATION (self), "win.prev-tab", accels);
+
         accels[0] = "F9";
         gtk_application_set_accels_for_action (GTK_APPLICATION (self), "win.show-sidebar", accels);
 
diff --git a/src/dh-window.c b/src/dh-window.c
index de96572..be876c1 100644
--- a/src/dh-window.c
+++ b/src/dh-window.c
@@ -145,6 +145,51 @@ new_tab_cb (GSimpleAction *action,
 }
 
 static void
+next_tab_cb (GSimpleAction *action,
+             GVariant      *parameter,
+             gpointer       user_data)
+{
+        gint current_page, n_pages;
+        GtkNotebook *notebook;
+        DhWindowPrivate *priv;
+        DhWindow *window = user_data;
+
+        priv = dh_window_get_instance_private (window);
+        notebook = GTK_NOTEBOOK (priv->notebook);
+
+        current_page = gtk_notebook_get_current_page (notebook);
+        n_pages = gtk_notebook_get_n_pages (notebook);
+
+        if (current_page < n_pages - 1)
+                gtk_notebook_next_page (notebook);
+        else
+                /* Wrap around to the first tab */
+                gtk_notebook_set_current_page (notebook, 0);
+}
+
+static void
+prev_tab_cb (GSimpleAction *action,
+             GVariant      *parameter,
+             gpointer       user_data)
+{
+        gint current_page;
+        GtkNotebook *notebook;
+        DhWindowPrivate *priv;
+        DhWindow *window = user_data;
+
+        priv = dh_window_get_instance_private (window);
+        notebook = GTK_NOTEBOOK (priv->notebook);
+
+        current_page = gtk_notebook_get_current_page (notebook);
+
+        if (current_page > 0)
+                gtk_notebook_prev_page (notebook);
+        else
+                /* Wrap around to the last tab */
+                gtk_notebook_set_current_page (notebook, -1);
+}
+
+static void
 print_cb (GSimpleAction *action,
           GVariant      *parameter,
           gpointer       user_data)
@@ -466,8 +511,10 @@ dh_window_open_link (DhWindow        *window,
 }
 
 static GActionEntry win_entries[] = {
-        /* file */
+        /* tabs */
         { "new-tab",          new_tab_cb },
+        { "next-tab",         next_tab_cb,         NULL, NULL, NULL },
+        { "prev-tab",         prev_tab_cb,         NULL, NULL, NULL },
         { "print",            print_cb },
         { "close",            close_cb },
 


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