[PATCH] gnome-terminal: wrap when navigating next/prev tab

This patch adds tab wrapping when navigating with "Previous Tab" and "Next
Tab" which makes it consistent to how tabs work with Konsole, Firefox, and
most other applications.

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
---

 terminal-window.c |   31 +++++++++++++++++++++++++------
 1 files changed, 25 insertions(+), 6 deletions(-)

Index: gnome-terminal/src/terminal-window.c
===================================================================
--- gnome-terminal.orig/src/terminal-window.c
+++ gnome-terminal/src/terminal-window.c
@@ -1341,8 +1341,7 @@ update_tab_sensitivity (TerminalWindow *
   notebook = window->priv->notebook;
   page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
   
-  gtk_widget_set_sensitive (window->priv->previous_tab_menuitem,
-                            page_num > 0);
+  gtk_widget_set_sensitive (window->priv->previous_tab_menuitem, TRUE);
 
 
   /* FIXME
@@ -1357,8 +1356,7 @@ update_tab_sensitivity (TerminalWindow *
   else
     gtk_widget_set_sensitive (window->priv->close_tab_menuitem, TRUE);
   
-  gtk_widget_set_sensitive (window->priv->next_tab_menuitem,
-                            !on_last_page);
+  gtk_widget_set_sensitive (window->priv->next_tab_menuitem, TRUE);
 }
 
 static void
@@ -2678,14 +2676,35 @@ static void
 next_tab_callback(GtkWidget      *menuitem,
                   TerminalWindow *window)
 {
-  gtk_notebook_next_page (GTK_NOTEBOOK (window->priv->notebook));
+  GtkWidget *notebook = window->priv->notebook;
+  int page_num;
+  gboolean on_last_page;
+
+  page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
+  on_last_page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook),
+                                            page_num + 1) == NULL;
+
+  if (on_last_page)
+    gtk_notebook_set_page (GTK_NOTEBOOK (notebook), 0);
+  else
+    gtk_notebook_next_page (GTK_NOTEBOOK (notebook));
 }
 
 static void
 previous_tab_callback (GtkWidget      *menuitem,
                        TerminalWindow *window)
 {
-  gtk_notebook_prev_page (GTK_NOTEBOOK (window->priv->notebook));
+  GtkWidget *notebook = window->priv->notebook;
+  int page_num;
+  gboolean on_first_page;
+
+  page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
+  on_first_page = page_num == 0;
+
+  if (on_first_page)
+    gtk_notebook_set_page (GTK_NOTEBOOK (notebook), -1);
+  else
+    gtk_notebook_prev_page (GTK_NOTEBOOK (notebook));
 }
 
 static void
