Index: src/terminal-notebook.c
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal-notebook.c,v
retrieving revision 1.8
diff -u -p -r1.8 terminal-notebook.c
--- src/terminal-notebook.c	30 Jan 2006 04:15:18 -0000	1.8
+++ src/terminal-notebook.c	7 Mar 2006 14:17:06 -0000
@@ -54,7 +54,8 @@ static void move_tab_to_another_notebook
                                               int               dest_position);
 static void move_tab                         (TerminalNotebook *notebook,
                                               int               dest_position);
-          
+static void notebook_pages_recalc_titles         (TerminalNotebook *notebook);
+
 /* Local variables */
 static GdkCursor *cursor = NULL;
 
@@ -282,6 +283,8 @@ terminal_notebook_move_tab (TerminalNote
         {
           g_signal_emit (G_OBJECT (src), signals[TABS_REORDERED], 0);
         }
+
+      notebook_pages_recalc_titles (src);
     }
   else
     {
@@ -304,7 +307,11 @@ terminal_notebook_move_tab (TerminalNote
    
       terminal_notebook_add_tab (dest, screen, dest_position, TRUE);
       g_object_unref (screen);
+      
+      notebook_pages_recalc_titles (src);
+      notebook_pages_recalc_titles (dest);
     }
+
 }
 
 static void
@@ -811,6 +818,8 @@ terminal_notebook_add_tab (TerminalNoteb
                          GINT_TO_POINTER (jump_to));
 
     }
+
+  notebook_pages_recalc_titles (nb);
 }
 
 void
@@ -840,8 +849,31 @@ terminal_notebook_remove_tab (TerminalNo
   gtk_notebook_remove_page (GTK_NOTEBOOK (nb), position);
 
   update_tabs_visibility (nb, FALSE);
+  notebook_pages_recalc_titles (nb);
 
   g_signal_emit (G_OBJECT (nb), signals[TAB_REMOVED], 0, screen);
 
   g_object_unref (screen);
+}
+
+gint
+terminal_notebook_page_number (TerminalNotebook *notebook,
+                               TerminalScreen *screen)
+{
+  return gtk_notebook_page_num (GTK_NOTEBOOK (notebook),
+                                GTK_WIDGET (screen));
+}
+
+static void
+notebook_pages_recalc_titles (TerminalNotebook *notebook)
+{
+  guint i = 0;
+  GtkNotebook *nb = GTK_NOTEBOOK (notebook);
+  GtkWidget *page; 
+ 
+  /* Just tell all the notebook's pages to recalc their titles. */ 
+  while ((page = gtk_notebook_get_nth_page (nb, i++)))
+    {
+      terminal_screen_recalc_title (TERMINAL_SCREEN (page));
+    }
 }
Index: src/terminal-notebook.h
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal-notebook.h,v
retrieving revision 1.1
diff -u -p -r1.1 terminal-notebook.h
--- src/terminal-notebook.h	20 Nov 2005 19:13:35 -0000	1.1
+++ src/terminal-notebook.h	7 Mar 2006 14:17:06 -0000
@@ -86,6 +86,9 @@ void            terminal_notebook_move_t
 void            terminal_notebook_set_show_tabs  (TerminalNotebook *nb,
                                                   gboolean          show_tabs);
 
+gint            terminal_notebook_page_number    (TerminalNotebook *notebook,
+                                                  TerminalScreen   *screen);
+
 G_END_DECLS
 
 #endif /* TERMINAL_NOTEBOOK_H */
Index: src/terminal-screen.c
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal-screen.c,v
retrieving revision 1.122
diff -u -p -r1.122 terminal-screen.c
--- src/terminal-screen.c	2 Feb 2006 18:32:11 -0000	1.122
+++ src/terminal-screen.c	7 Mar 2006 14:17:07 -0000
@@ -32,6 +32,7 @@
 #include "terminal-window.h"
 #include "terminal-widget.h"
 #include "terminal-profile.h"
+#include "terminal-notebook.h"
 #include "terminal.h"
 #include "skey-popup.h"
 #include <libgnome/gnome-util.h> /* gnome_util_user_shell */
@@ -322,6 +323,7 @@ terminal_screen_init (TerminalScreen *sc
                     screen);
 
   screen->priv->user_title = FALSE;
+  
   terminal_widget_connect_title_changed (screen->priv->term,
                                          G_CALLBACK (terminal_screen_widget_title_changed),
                                          screen);
@@ -521,6 +523,17 @@ terminal_screen_get_icon_title_set (Term
   return screen->priv->icon_title_set;
 }
 
+void
+terminal_screen_recalc_title (TerminalScreen *screen)
+{
+  if (screen->priv->cooked_title)
+    {
+      g_free (screen->priv->cooked_title);
+      screen->priv->cooked_title = NULL;
+      terminal_screen_cook_title (screen);
+    }
+}
+
 static void
 reread_profile (TerminalScreen *screen)
 {
@@ -631,6 +644,8 @@ cook_title  (TerminalScreen *screen, con
 {
   TerminalTitleMode mode;
   char *new_cooked_title = NULL;
+  char *percent = NULL;
+  int index_into_title = 0;
 
   g_return_val_if_fail (old_cooked_title != NULL, FALSE);
 
@@ -666,6 +681,62 @@ cook_title  (TerminalScreen *screen, con
     /* no default so we get missing cases statically */
     }
 
+  /* Replace %-sequences. */
+  while ((percent = strchr(new_cooked_title+index_into_title, '%')))
+    {
+      char *tmp;
+       
+      index_into_title = percent - new_cooked_title;
+       
+      switch(*(percent+1)) {
+        case '%':
+          *percent = 0;
+          tmp = g_strconcat (new_cooked_title,
+                             "%",
+                             percent+2,
+                             NULL);
+          g_free (new_cooked_title);
+          new_cooked_title = tmp;
+          ++index_into_title;
+          break;
+
+        case 'd':
+          {
+            gint value = 0;
+
+            if (screen->priv->window)
+              {
+                GtkWidget *nb = terminal_window_get_notebook (TERMINAL_WINDOW (screen->priv->window) );
+                value = terminal_notebook_page_number (TERMINAL_NOTEBOOK (nb), screen);
+              }
+            
+            *percent = 0;
+            tmp = g_strdup_printf ("%s%d%s",
+                                   new_cooked_title,
+                                   value+1,
+                                   percent+2);
+            g_free (new_cooked_title);
+            new_cooked_title = tmp;
+
+            /* don't bother adjusting index_into_title:
+             * the characters we'd have to skip past are
+             * all numeric, anyway, and finding '%'s would be
+             * impossible.
+             */
+          }
+          break;
+
+        case 0:
+          /* trailing %; ignore it */
+          index_into_title++;
+          break;
+
+        default:
+          /* ignore unknown sequences */
+          index_into_title += 2;
+      }
+  }
+       
   if (*old_cooked_title == NULL || strcmp (new_cooked_title, *old_cooked_title) != 0)
     {
       g_free (*old_cooked_title);
Index: src/terminal-screen.h
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal-screen.h,v
retrieving revision 1.14
diff -u -p -r1.14 terminal-screen.h
--- src/terminal-screen.h	20 Jan 2006 18:05:42 -0000	1.14
+++ src/terminal-screen.h	7 Mar 2006 14:17:07 -0000
@@ -115,6 +115,8 @@ double      terminal_screen_get_font_sca
 
 void terminal_screen_update_scrollbar (TerminalScreen *screen);
 
+void        terminal_screen_recalc_title     (TerminalScreen *screen);
+
 /* Allow scales a bit smaller and a bit larger than the usual pango ranges */
 #define TERMINAL_SCALE_XXX_SMALL   (PANGO_SCALE_XX_SMALL/1.2)
 #define TERMINAL_SCALE_XXXX_SMALL  (TERMINAL_SCALE_XXX_SMALL/1.2)
