Index: Makefile.am
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/Makefile.am,v
retrieving revision 1.43
diff -U5 -p -r1.43 Makefile.am
--- Makefile.am	12 Jan 2006 16:46:59 -0000	1.43
+++ Makefile.am	1 Sep 2006 04:33:55 -0000
@@ -44,12 +44,10 @@ gnome_terminal_SOURCES=				\
 	terminal-screen.h			\
 	terminal-widget.h			\
 	terminal-widget-vte.c			\
 	terminal-window.c			\
 	terminal-window.h			\
-	terminal-notebook.c			\
-	terminal-notebook.h			\
 	simple-x-font-selector.c		\
 	simple-x-font-selector.h		\
 	$(EGGFILES)
 
 gnome_terminal_LDADD= $(EFENCE) @TERM_LIBS@ skey/libskey.la
Index: terminal-screen.c
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal-screen.c,v
retrieving revision 1.127
diff -U5 -p -r1.127 terminal-screen.c
--- terminal-screen.c	30 Jul 2006 21:44:22 -0000	1.127
+++ terminal-screen.c	1 Sep 2006 04:33:56 -0000
@@ -454,14 +454,50 @@ terminal_screen_finalize (GObject *objec
   g_free (screen->priv);
   
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
+static void
+parent_set_callback (TerminalScreen *screen,
+                     GtkWidget      *old_parent)
+{
+  if (GTK_WIDGET (screen)->parent == NULL)
+    {
+      screen->priv->window = NULL;
+    }
+  else
+    {
+      GtkWidget *window;
+
+      g_return_if_fail (GTK_IS_NOTEBOOK (GTK_WIDGET (screen)->parent));
+
+      window = gtk_widget_get_toplevel (GTK_WIDGET (screen)->parent);
+
+      g_return_if_fail (window != NULL);
+      g_return_if_fail (TERMINAL_IS_WINDOW (window));
+
+      screen->priv->window = gtk_widget_get_toplevel (window);
+    }
+}
+
 TerminalScreen*
 terminal_screen_new (void)
 {
-  return g_object_new (TERMINAL_TYPE_SCREEN, NULL);
+  TerminalScreen *screen = g_object_new (TERMINAL_TYPE_SCREEN, NULL);
+
+#ifdef TRACE_SIZE
+  g_signal_connect (G_OBJECT (screen), "realize", 
+                    G_CALLBACK (realize_trace), NULL);
+  g_signal_connect (G_OBJECT (screen), "unrealize", 
+                    G_CALLBACK (unrealize_trace), NULL);
+#endif
+
+  g_signal_connect (G_OBJECT (screen), "parent-set", 
+                    G_CALLBACK (parent_set_callback), 
+                    NULL);
+
+  return screen;
 }
 
 static void
 terminal_screen_map (GtkWidget *widget)
 {
@@ -897,10 +933,11 @@ terminal_screen_update_on_realize (GtkWi
 
   update_color_scheme (screen);
   
   terminal_widget_set_allow_bold (term,
                                   terminal_profile_get_allow_bold (profile));
+
   terminal_window_set_size (screen->priv->window, screen, TRUE);
 }
 
 static void
 terminal_screen_change_font (TerminalScreen *screen)
Index: terminal-window.c
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal-window.c,v
retrieving revision 1.132
diff -U5 -p -r1.132 terminal-window.c
--- terminal-window.c	26 Aug 2006 21:48:18 -0000	1.132
+++ terminal-window.c	1 Sep 2006 04:33:57 -0000
@@ -22,11 +22,10 @@
 
 #include "terminal-intl.h"
 #include "terminal-accels.h"
 #include "terminal-widget.h"
 #include "terminal-window.h"
-#include "terminal-notebook.h"
 #include "terminal.h"
 #include "encoding.h"
 #include <string.h>
 #include <stdlib.h>
 #include <libgnome/gnome-program.h>
@@ -67,10 +66,11 @@ struct _TerminalWindowPrivate
   GList *tab_menuitems;
   GList *terms;
   TerminalScreen *active_term;
   GdkPixbuf *icon;
   GtkClipboard *clipboard;
+  GtkTooltips *tooltips;
   int old_char_width;
   int old_char_height;
   void *old_geometry_widget; /* only used for pointer value as it may be freed */
   GConfClient *conf;
   guint notify_id;
@@ -86,10 +86,12 @@ struct _TerminalWindowPrivate
    */
   guint fullscreen : 1;
 
   /* Compositing manager integration */
   guint have_argb_visual : 1;
+
+  guint disposed : 1;
 };
 
 enum {
   dummy, /* remove this when you add more signals */
   LAST_SIGNAL
@@ -98,12 +100,12 @@ enum {
 static GConfClient *client = NULL;
 static guint notify;
 
 static void terminal_window_init        (TerminalWindow      *window);
 static void terminal_window_class_init  (TerminalWindowClass *klass);
+static void terminal_window_dispose     (GObject             *object);
 static void terminal_window_finalize    (GObject             *object);
-static void terminal_window_destroy     (GtkObject           *object);
 
 static gboolean terminal_window_delete_event (GtkWidget *widget,
                                               GdkEvent *event,
                                               gpointer data);
 
@@ -117,23 +119,23 @@ static TerminalScreen* find_screen (Term
 static void notebook_page_selected_callback (GtkWidget *notebook,
                                              GtkNotebookPage *useless_crap,
                                              int              page_num,
                                              TerminalWindow  *window);
 
-static void notebook_tab_added_callback     (GtkWidget       *notebook,
-                                             TerminalScreen  *screen,
-                                             TerminalWindow  *window);
-
-static void notebook_tab_detached_callback  (GtkWidget       *notebook,
+static void notebook_page_added_callback    (GtkWidget       *notebook,
                                              TerminalScreen  *screen,
+                                             guint            page_num,
                                              TerminalWindow  *window);
 
-static void notebook_tab_removed_callback   (GtkWidget       *notebook,
+static void notebook_page_removed_callback  (GtkWidget       *notebook,
                                              TerminalScreen  *screen,
+                                             guint            page_num,
                                              TerminalWindow  *window);
 
-static void notebook_tabs_reordered_callback (GtkWidget      *notebook,
+static void notebook_page_reordered_callback (GtkWidget      *notebook,
+                                              GtkWidget      *child,
+                                              guint           page_num,
                                               TerminalWindow *window);
 
 static void config_change_notify            (GConfClient *client,
                                              guint        cnxn_id,
                                              GConfEntry  *entry,
@@ -746,11 +748,13 @@ edit_menu_activate_callback (GtkMenuItem
 {
   TerminalWindow *window;
 
   window = (TerminalWindow *) user_data;
 
-  gtk_clipboard_request_text (window->priv->clipboard, (GtkClipboardTextReceivedFunc) update_edit_menu, window);
+  gtk_clipboard_request_text (window->priv->clipboard, 
+                              (GtkClipboardTextReceivedFunc) update_edit_menu, 
+                              window);
 }
 
 static void
 initialize_alpha_mode (TerminalWindow *window)
 {
@@ -794,29 +798,38 @@ terminal_window_init (TerminalWindow *wi
 
   gtk_window_set_title (GTK_WINDOW (window), _("Terminal"));
   client = gconf_client_get_default();
   
   window->priv = g_new0 (TerminalWindowPrivate, 1);
+  window->priv->disposed = FALSE;
   window->priv->terms = NULL;
   window->priv->active_term = NULL;
   window->priv->menubar = gtk_menu_bar_new ();
   window->priv->menubar_visible = FALSE;
   
   window->priv->main_vbox = gtk_vbox_new (FALSE, 0);
-  window->priv->notebook = terminal_notebook_new ();
+  window->priv->notebook = gtk_notebook_new ();
+  gtk_notebook_set_scrollable (GTK_NOTEBOOK (window->priv->notebook), TRUE);
+  gtk_notebook_set_show_border (GTK_NOTEBOOK (window->priv->notebook), FALSE);
+  gtk_notebook_set_group_id (GTK_NOTEBOOK (window->priv->notebook), 1);
   
   window->priv->old_char_width = -1;
   window->priv->old_char_height = -1;
   window->priv->old_geometry_widget = NULL;
   
   window->priv->use_mnemonics = TRUE;
   window->priv->using_mnemonics = FALSE;
 
+  window->priv->tooltips = gtk_tooltips_new ();
+  g_object_ref (window->priv->tooltips);
+  gtk_object_sink (GTK_OBJECT (window->priv->tooltips));
+
   initialize_alpha_mode (window);
 
   /* force gtk to construct its GtkClipboard; otherwise our UI is very slow the first time we need it */
-  window->priv->clipboard = gtk_clipboard_get_for_display (gtk_widget_get_display (GTK_WIDGET (window)), GDK_NONE);
+  window->priv->clipboard = gtk_clipboard_get_for_display (gtk_widget_get_display (GTK_WIDGET (window)), 
+                                                           GDK_NONE);
 
   error = NULL;
   menus_have_icons = gconf_client_get_bool (client, "/desktop/gnome/interface/menus_have_icons", &error);
   if (error)
     {
@@ -835,32 +848,27 @@ terminal_window_init (TerminalWindow *wi
   
   gtk_notebook_set_scrollable (GTK_NOTEBOOK (window->priv->notebook),
                                TRUE);                                      
   
   g_signal_connect_after (G_OBJECT (window->priv->notebook),
-                          "switch_page",
+                          "switch-page",
                           G_CALLBACK (notebook_page_selected_callback),
                           window);
 
   g_signal_connect_after (G_OBJECT (window->priv->notebook),
-                          "tab_added",
-                          G_CALLBACK (notebook_tab_added_callback),
-                          window);
-
-  g_signal_connect_after (G_OBJECT (window->priv->notebook),
-                          "tab_detached",
-                          G_CALLBACK (notebook_tab_detached_callback),
+                          "page-added",
+                          G_CALLBACK (notebook_page_added_callback),
                           window);
 
   g_signal_connect_after (G_OBJECT (window->priv->notebook),
-                          "tab_removed",
-                          G_CALLBACK (notebook_tab_removed_callback),
+                          "page-removed",
+                          G_CALLBACK (notebook_page_removed_callback),
                           window);
   
   g_signal_connect_after (G_OBJECT (window->priv->notebook),
-                          "tabs_reordered",
-                          G_CALLBACK (notebook_tabs_reordered_callback),
+                          "page-reordered",
+                          G_CALLBACK (notebook_page_reordered_callback),
                           window);
 
   gtk_container_add (GTK_CONTAINER (window),
                      window->priv->main_vbox);
 
@@ -1114,68 +1122,84 @@ terminal_window_init (TerminalWindow *wi
 
 static void
 terminal_window_class_init (TerminalWindowClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
-  GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
   
   parent_class = g_type_class_peek_parent (klass);
   
+  object_class->dispose = terminal_window_dispose;
   object_class->finalize = terminal_window_finalize;
-  gtk_object_class->destroy = terminal_window_destroy;
   widget_class->show = terminal_window_show;
 }
 
 static void
-terminal_window_finalize (GObject *object)
+terminal_window_dispose (GObject *object)
 {
   TerminalWindow *window;
 
   window = TERMINAL_WINDOW (object);
 
-  gconf_client_notify_remove (window->priv->conf,
-                              window->priv->notify_id);
+  if (window->priv->disposed)
+    {
+      return;
+    }
+
+  gconf_client_notify_remove (window->priv->conf, window->priv->notify_id);
   window->priv->notify_id = 0;
 
-  if (window->priv->conf)
-    g_object_unref (G_OBJECT (window->priv->conf));
-  
-  if (window->priv->icon)
-    g_object_unref (G_OBJECT (window->priv->icon));
+  g_signal_handlers_disconnect_by_func (window->priv->notebook,
+                                	notebook_page_selected_callback, 
+                                        window);
+  g_signal_handlers_disconnect_by_func (window->priv->notebook,
+                        		notebook_page_added_callback, 
+                                        window);
+  g_signal_handlers_disconnect_by_func (window->priv->notebook,
+                        		notebook_page_reordered_callback, 
+                                        window);
+  g_signal_handlers_disconnect_by_func (window->priv->notebook,
+		                        notebook_page_removed_callback, 
+                                        window);
 
-  g_free (window->priv->startup_id);
-  
-  g_free (window->priv);
-  
-  G_OBJECT_CLASS (parent_class)->finalize (object);
+  G_OBJECT_CLASS (parent_class)->dispose (object);
+
+  window->priv->disposed = TRUE;
 }
 
 static void
-terminal_window_destroy (GtkObject *object)
+terminal_window_finalize (GObject *object)
 {
   TerminalWindow *window;
 
   window = TERMINAL_WINDOW (object);
 
-  while (window->priv->terms)
-    terminal_window_remove_screen (window, window->priv->terms->data);
-
-  g_list_free (window->priv->tab_menuitems);
-  window->priv->tab_menuitems = NULL;
+  if (window->priv->conf)
+    {
+      g_object_unref (G_OBJECT (window->priv->conf));
+    }
   
-  /* to handle multiple destroy, FIXME some fields are missing */
-  window->priv->menubar = NULL;
-  window->priv->notebook = NULL;
-  window->priv->main_vbox = NULL;
-  window->priv->copy_menuitem = NULL;
-  window->priv->paste_menuitem = NULL;
-  window->priv->edit_config_menuitem = NULL;
-  window->priv->choose_config_menuitem = NULL;
-  window->priv->encoding_menuitem = NULL;
+  if (window->priv->icon)
+    {
+      g_object_unref (G_OBJECT (window->priv->icon));
+    }
+
+  if (window->priv->tooltips)
+    {
+      g_object_unref (G_OBJECT (window->priv->tooltips));
+    }
+
+  if (window->priv->tab_menuitems)
+    {
+      g_list_free (window->priv->tab_menuitems);
+      window->priv->tab_menuitems = NULL;
+    }
+
+  g_free (window->priv->startup_id);
+  g_free (window->priv);
   
-  GTK_OBJECT_CLASS (parent_class)->destroy (object);  
+  G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static gboolean
 terminal_window_delete_event (GtkWidget *widget,
                               GdkEvent *event,
@@ -1275,11 +1299,19 @@ terminal_window_new (GConfClient *conf)
   TerminalWindow *window;
   GError *err;
   gboolean use_mnemonics;
   
   window = g_object_new (TERMINAL_TYPE_WINDOW, NULL);
-  g_signal_connect (G_OBJECT (window), "realize", G_CALLBACK (terminal_window_realized_callback), NULL);
+  g_signal_connect (G_OBJECT (window), "realize", 
+                    G_CALLBACK (terminal_window_realized_callback), NULL);
+
+#ifdef TRACE_SIZE
+  g_signal_connect (G_OBJECT (window), "realize", 
+                    G_CALLBACK (realize_trace), NULL);
+  g_signal_connect (G_OBJECT (window), "unrealize", 
+                    G_CALLBACK (unrealize_trace), NULL);
+#endif
 
   window->priv->conf = conf;
   g_object_ref (G_OBJECT (conf));
 
   err = NULL;
@@ -1321,13 +1353,19 @@ terminal_window_new (GConfClient *conf)
 static void
 update_notebook (TerminalWindow *window)
 {
   gboolean single;
 
+  if (!window->priv->notebook)
+    {
+      return;
+    }
+
   single = g_list_length (window->priv->terms) == 1;
     
   gtk_notebook_set_show_border (GTK_NOTEBOOK (window->priv->notebook), !single);
+  gtk_notebook_set_show_tabs (GTK_NOTEBOOK (window->priv->notebook), !single);
 }
 
 static void
 profile_set_callback (TerminalScreen *screen,
                       TerminalWindow *window)
@@ -1388,10 +1426,16 @@ update_tab_sensitivity (TerminalWindow *
   GtkWidget *notebook;
   int num_pages, page_num;
   gboolean on_last_page;
 
   notebook = window->priv->notebook;
+
+  if (!notebook)
+    {
+      return;
+    }
+
   num_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook));
   page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
   
   gtk_widget_set_sensitive (window->priv->previous_tab_menuitem,
                             page_num > 0);
@@ -1425,15 +1469,103 @@ selection_changed_callback (TerminalScre
                             TerminalWindow *window)
 {
   update_copy_sensitivity (window);
 }
 
+static void
+close_button_clicked_cb (GtkWidget *widget, GtkWidget *screen)
+{
+  GtkWidget *notebook;
+  guint page_num;
+
+  notebook = gtk_widget_get_parent (GTK_WIDGET (screen));
+  page_num = gtk_notebook_page_num (GTK_NOTEBOOK (notebook), screen);
+  gtk_notebook_remove_page (GTK_NOTEBOOK (notebook), page_num);
+}
+
+static void
+sync_tab_label (TerminalScreen *screen,
+                GtkTooltips    *tooltips)
+{
+  GtkWidget *label;
+  GtkWidget *ebox;
+  const char *title;
+
+  title = terminal_screen_get_title (screen);
+
+  label = g_object_get_data (G_OBJECT (screen), "tab-label");
+  ebox = gtk_widget_get_parent (label);
+
+  gtk_label_set_text (GTK_LABEL (label), title);
+  gtk_tooltips_set_tip (tooltips, ebox, title, NULL);
+}
+
+static GtkWidget *
+contruct_tab_label (TerminalWindow *window, TerminalScreen *screen)
+{
+  const char *title;
+  GtkWidget *hbox, *label, *label_ebox, *close_button, *image;
+  GtkRcStyle *rcstyle;
+  GtkSettings *settings;
+  gint w, h;
+
+  hbox = gtk_hbox_new (FALSE, 4);
+
+  title = terminal_screen_get_title (screen);
+
+  label_ebox = gtk_event_box_new ();
+  gtk_event_box_set_visible_window (GTK_EVENT_BOX (label_ebox), FALSE);
+  gtk_tooltips_set_tip (window->priv->tooltips, label_ebox, title, NULL);
+
+  label = gtk_label_new (title);
+  gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
+  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+
+  gtk_container_add (GTK_CONTAINER (label_ebox), label);
+  gtk_box_pack_start (GTK_BOX (hbox), label_ebox, TRUE, TRUE, 0);
+
+  close_button = gtk_button_new ();
+  gtk_button_set_relief (GTK_BUTTON (close_button), GTK_RELIEF_NONE);
+  gtk_button_set_focus_on_click (GTK_BUTTON (close_button), FALSE);
+  gtk_button_set_relief (GTK_BUTTON (close_button), GTK_RELIEF_NONE);
+
+  rcstyle = gtk_rc_style_new ();
+  rcstyle->xthickness = rcstyle->ythickness = 0;
+  gtk_widget_modify_style (close_button, rcstyle);
+  gtk_rc_style_unref (rcstyle);
+
+  settings = gtk_widget_get_settings (GTK_WIDGET (label));
+  gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU, &w, &h);
+  gtk_widget_set_size_request (close_button, w + 2, h + 2);
+
+  image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
+  gtk_container_add (GTK_CONTAINER (close_button), image);
+  gtk_box_pack_start (GTK_BOX (hbox), close_button, FALSE, FALSE, 0);
+
+  gtk_tooltips_set_tip (window->priv->tooltips, close_button, _("Close tab"), NULL);
+
+  g_signal_connect (G_OBJECT (close_button), "clicked",
+		    G_CALLBACK (close_button_clicked_cb),
+		    screen);
+
+  g_object_set_data (G_OBJECT (screen), "tab-label", label);
+  g_signal_connect (G_OBJECT (screen),
+                    "title-changed",
+                    G_CALLBACK (sync_tab_label),
+                    window->priv->tooltips);
+
+  gtk_widget_show_all (hbox);
+
+  return hbox;
+}
+
 void
 terminal_window_add_screen (TerminalWindow *window,
                             TerminalScreen *screen)
 {
   TerminalWindow *old;
+  GtkWidget *tab_label;
  
   old = terminal_screen_get_window (screen);
 
   if (old == window)
     return;  
@@ -1451,28 +1583,49 @@ terminal_window_add_screen (TerminalWind
 
   terminal_screen_set_window (screen, window);
 
   gtk_widget_show_all (GTK_WIDGET (screen));
 
-  terminal_notebook_add_tab (TERMINAL_NOTEBOOK (window->priv->notebook),
-                             screen,
-                             -1,
-                             FALSE);
+  tab_label = contruct_tab_label (window, screen);
+  gtk_notebook_append_page (GTK_NOTEBOOK (window->priv->notebook),
+                            GTK_WIDGET (screen),
+                            tab_label);
+  gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (window->priv->notebook),
+                                      GTK_WIDGET (screen),
+                                      TRUE, TRUE, GTK_PACK_START);
+  gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (window->priv->notebook),
+                                    GTK_WIDGET (screen),
+                                    TRUE);
+  gtk_notebook_set_tab_detachable (GTK_NOTEBOOK (window->priv->notebook),
+                                   GTK_WIDGET (screen),
+                                   TRUE);
 }
 
 void
 terminal_window_remove_screen (TerminalWindow *window,
                                TerminalScreen *screen)
 {
+  guint num_page;
+
   g_return_if_fail (terminal_screen_get_window (screen) == window);
 
   window->priv->terms = g_list_remove (window->priv->terms, screen);
   
   terminal_screen_set_window (screen, NULL);
   
-  terminal_notebook_remove_tab (TERMINAL_NOTEBOOK (window->priv->notebook),
-                                screen);
+  num_page = gtk_notebook_page_num (GTK_NOTEBOOK (window->priv->notebook), GTK_WIDGET (screen));
+  gtk_notebook_remove_page (GTK_NOTEBOOK (window->priv->notebook), num_page);
+}
+
+void 
+terminal_window_adopt_screen (TerminalWindow *window,
+                              TerminalWindow *orig_window,
+                              TerminalScreen *screen,
+                              guint           dest_position)
+{
+  /* Do we even need this? */
+  g_printerr ("FIXME: terminal_window_adopt_screen\n");
 }
 
 GList*
 terminal_window_list_screens (TerminalWindow *window)
 {
@@ -1610,10 +1763,11 @@ void
 terminal_window_set_active (TerminalWindow *window,
                             TerminalScreen *screen)
 {
   GtkWidget *widget;
   TerminalProfile *profile;
+  guint page_num;
   
   if (window->priv->active_term == screen)
     return;
   
   widget = terminal_screen_get_widget (screen);
@@ -1638,13 +1792,12 @@ terminal_window_set_active (TerminalWind
     }
 
   gdk_window_set_icon_name (GTK_WIDGET (window)->window, terminal_screen_get_icon_title (screen));
   gtk_window_set_title (GTK_WINDOW (window), terminal_screen_get_title (screen));
 
-  gtk_notebook_set_current_page (GTK_NOTEBOOK (window->priv->notebook),
-                                 gtk_notebook_page_num (GTK_NOTEBOOK (window->priv->notebook),
-                                                        GTK_WIDGET (screen)));
+  page_num = gtk_notebook_page_num (GTK_NOTEBOOK (window->priv->notebook), GTK_WIDGET (screen));
+  gtk_notebook_set_current_page (GTK_NOTEBOOK (window->priv->notebook), page_num);
 
   /* set size of window to current grid size */
 #ifdef DEBUG_GEOMETRY
   g_fprintf (stderr,"setting size after flipping notebook pages\n");
 #endif
@@ -1747,28 +1900,32 @@ notebook_page_selected_callback (GtkWidg
     gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item),
                                     TRUE);
 }
 
 static void
-notebook_tab_added_callback (GtkWidget       *notebook,
-                               TerminalScreen  *screen,
-                               TerminalWindow  *window)
+notebook_page_added_callback (GtkWidget       *notebook,
+                              TerminalScreen  *screen,
+                              guint            page_num,
+                              TerminalWindow  *window)
 {
   GtkWidget *term;
 
+  g_printerr ("page_added: screen: %p; window: %p\n", screen, window);
   /* Moved from another window */
-  if (find_screen (window, screen) == NULL) {
-    g_object_ref (G_OBJECT (screen)); /* make our own new refcount */
-  
-    /* keep this list in same order as tabs in notebook,
-     * so that terminal_window_list_screens() returns screens
-     * in tab order
-     */
-    window->priv->terms = g_list_append (window->priv->terms, screen);
-  
-    terminal_screen_set_window (screen, window);
-  }
+  if (find_screen (window, screen) == NULL) 
+    {
+      g_printerr ("notebook_page_added_callback from another window!\n");
+      g_object_ref (G_OBJECT (screen)); /* make our own new refcount */
+    
+      /* keep this list in same order as tabs in notebook,
+       * so that terminal_window_list_screens() returns screens
+       * in tab order
+       */
+      window->priv->terms = g_list_append (window->priv->terms, screen);
+    
+      terminal_screen_set_window (screen, window);
+    }
   
   g_signal_connect (G_OBJECT (screen),
                     "profile_set",
                     G_CALLBACK (profile_set_callback),
                     window);
@@ -1821,51 +1978,34 @@ notebook_tab_added_callback (GtkWidget  
   if (window->priv->active_term == NULL)
     terminal_window_set_active (window, screen);
 }
 
 static void
-notebook_tab_detached_callback (GtkWidget       *notebook,
+notebook_page_removed_callback (GtkWidget       *notebook,
                                 TerminalScreen  *screen,
+                                guint            page_num,
                                 TerminalWindow  *window)
-{
-  /* Reset the tab menu before detaching the tab, in case the tab changed
-   * position before it was detached (bug #330246). */
-  reset_tab_menuitems (window);
-
-  detach_tab (screen, window);
-}
-
-static void
-notebook_tab_removed_callback (GtkWidget       *notebook,
-                               TerminalScreen  *screen,
-                               TerminalWindow  *window)
 {  
   gboolean single;
-  /* Called from terminal_notebook_move_tab() */
-  if (find_screen (window, screen) != NULL) {
-    g_assert (terminal_screen_get_window (screen) == window);
-  
-    window->priv->terms = g_list_remove (window->priv->terms, screen);
-    terminal_screen_set_window (screen, NULL);
-  }
-  
+
+  g_printerr ("page_removed: screen: %p; window: %p\n", screen, window);
+
   g_signal_handlers_disconnect_by_func (G_OBJECT (screen),
                                         G_CALLBACK (profile_set_callback),
                                         window);
-
   g_signal_handlers_disconnect_by_func (G_OBJECT (screen),
                                         G_CALLBACK (title_changed_callback),
                                         window);
-
   g_signal_handlers_disconnect_by_func (G_OBJECT (screen),
                                         G_CALLBACK (icon_title_changed_callback),
                                         window);
-
   g_signal_handlers_disconnect_by_func (G_OBJECT (screen),
                                         G_CALLBACK (selection_changed_callback),
                                         window);
 
+  terminal_screen_set_window (screen, NULL);
+
   screen_set_menuitem (screen, NULL);
   
   update_notebook (window);
 
   reset_tab_menuitems (window);
@@ -1880,14 +2020,16 @@ notebook_tab_removed_callback (GtkWidget
   if (window->priv->terms == NULL)
     gtk_widget_destroy (GTK_WIDGET (window));
 }
 
 static void
-notebook_tabs_reordered_callback (GtkWidget       *notebook,
-                                 TerminalWindow  *window)
+notebook_page_reordered_callback (GtkWidget       *notebook,
+                                  GtkWidget       *child,
+                                  guint            page_num,
+                                  TerminalWindow  *window)
 {
-	reset_tab_menuitems(window);
+  reset_tab_menuitems(window);
 }
 
 void
 terminal_window_update_icon (TerminalWindow *window)
 {
@@ -2748,16 +2890,11 @@ move_left_tab_callback(GtkWidget      *m
   notebook = GTK_NOTEBOOK (window->priv->notebook);
   page_num = gtk_notebook_get_current_page (notebook);
   last_page = gtk_notebook_get_n_pages (notebook) - 1;
   page = gtk_notebook_get_nth_page (notebook, page_num);
   
-  if (page_num == 0)
-    terminal_notebook_move_tab (TERMINAL_NOTEBOOK (notebook), NULL,
-                                TERMINAL_SCREEN (page), last_page);
-  else
-    terminal_notebook_move_tab (TERMINAL_NOTEBOOK (notebook), NULL,
-                                TERMINAL_SCREEN (page), page_num-1);
+  gtk_notebook_reorder_child (notebook, page, page_num == 0 ? last_page : page_num - 1);
 
   update_tab_sensitivity (window);
   reset_tab_menuitems (window);
 }
 
@@ -2772,16 +2909,11 @@ move_right_tab_callback(GtkWidget      *
   notebook = GTK_NOTEBOOK (window->priv->notebook);
   page_num = gtk_notebook_get_current_page (notebook);
   last_page = gtk_notebook_get_n_pages (notebook) - 1;
   page = gtk_notebook_get_nth_page (notebook, page_num);
   
-  if (page_num == last_page)
-    terminal_notebook_move_tab (TERMINAL_NOTEBOOK (notebook), NULL,
-                                TERMINAL_SCREEN (page), 0);
-  else
-    terminal_notebook_move_tab (TERMINAL_NOTEBOOK (notebook), NULL,
-                                TERMINAL_SCREEN (page), page_num+1);
+  gtk_notebook_reorder_child (notebook, page, page_num == last_page ? 0 : page_num + 1);
 
   update_tab_sensitivity (window);
   reset_tab_menuitems (window);
 }
 
Index: terminal-window.h
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal-window.h,v
retrieving revision 1.12
diff -U5 -p -r1.12 terminal-window.h
--- terminal-window.h	10 Jul 2006 18:32:21 -0000	1.12
+++ terminal-window.h	1 Sep 2006 04:33:57 -0000
@@ -57,10 +57,15 @@ TerminalWindow* terminal_window_new (GCo
 void terminal_window_add_screen (TerminalWindow *window,
                                  TerminalScreen *screen);
 
 void terminal_window_remove_screen (TerminalWindow *window,
                                     TerminalScreen *screen);
+void 
+terminal_window_adopt_screen (TerminalWindow *window,
+                              TerminalWindow *orig_window,
+                              TerminalScreen *screen,
+                              guint           dest_position);
 
 /* Menubar visibility is part of session state, except that
  * if it isn't restored from session, the window gets the setting
  * from the profile of the first screen added to the window
  */
@@ -97,9 +102,14 @@ void terminal_window_reread_profile_list
 
 void terminal_window_set_startup_id (TerminalWindow *window,
                                      const char     *startup_id);
 
 gboolean terminal_window_uses_argb_visual (TerminalWindow *window);
+
+//TESTING
+void realize_trace (GtkWidget *w);
+void unrealize_trace (GtkWidget *w);
+
 
 G_END_DECLS
 
 #endif /* TERMINAL_WINDOW_H */
Index: terminal.c
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal.c,v
retrieving revision 1.98
diff -U5 -p -r1.98 terminal.c
--- terminal.c	24 Jul 2006 22:05:38 -0000	1.98
+++ terminal.c	1 Sep 2006 04:33:57 -0000
@@ -23,11 +23,10 @@
 
 #include "terminal-intl.h"
 #include "terminal.h"
 #include "terminal-accels.h"
 #include "terminal-window.h"
-#include "terminal-notebook.h"
 #include "terminal-widget.h"
 #include "profile-editor.h"
 #include "encoding.h"
 #include <gconf/gconf-client.h>
 #include <bonobo-activation/bonobo-activation-activate.h>
@@ -1973,15 +1972,13 @@ terminal_app_new_terminal (TerminalApp  
     
       terminal_window_set_active (window, screen);
     }
   else
    {
-      TerminalWindow *src_win = terminal_screen_get_window (screen);
-      TerminalNotebook *src_notebook = TERMINAL_NOTEBOOK (terminal_window_get_notebook (src_win));
-      TerminalNotebook *dest_notebook = TERMINAL_NOTEBOOK (terminal_window_get_notebook (window));
+      TerminalWindow *src_window = terminal_screen_get_window (screen);
       
-      terminal_notebook_move_tab (src_notebook, dest_notebook, screen, 0);
+      terminal_window_adopt_screen (window, src_window, screen, 0);
     }
 
   if (geometry)
     {
       if (!gtk_window_parse_geometry (GTK_WINDOW (window),
@@ -3872,5 +3869,18 @@ terminal_invoke_factory (int argc, char 
     g_printerr (_("Failed to retrieve terminal server from activation server\n"));
 
   return FALSE;
 }
 
+#ifdef TRACE_SIZE
+void
+realize_trace (GtkWidget *w)
+{
+  g_printerr ("Realized: %s (%p)\n", g_type_name_from_instance (w), w);
+}
+
+void
+unrealize_trace (GtkWidget *w)
+{
+  g_printerr ("Unrealized: %s (%p)\n", g_type_name_from_instance (w), w);
+}
+#endif
Index: terminal.h
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal.h,v
retrieving revision 1.21
diff -U5 -p -r1.21 terminal.h
--- terminal.h	1 Jan 2006 21:07:57 -0000	1.21
+++ terminal.h	1 Sep 2006 04:33:57 -0000
@@ -79,7 +79,11 @@ void terminal_util_set_atk_name_descript
                                              const char *desc);
 GladeXML* terminal_util_load_glade_file (const char *filename,
                                          const char *widget_root,
                                          GtkWindow  *error_dialog_parent);
 
+#ifdef TRACE_SIZE
+void realize_trace (GtkWidget *w);
+void unrealize_trace (GtkWidget *w);
+#endif
 
 #endif /* TERMINAL_H */
