? patch
Index: Makefile.am
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/Makefile.am,v
retrieving revision 1.43
diff -U5 -r1.43 Makefile.am
--- Makefile.am	12 Jan 2006 16:46:59 -0000	1.43
+++ Makefile.am	5 Sep 2006 01:37:11 -0000
@@ -44,12 +44,10 @@
 	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 -r1.127 terminal-screen.c
--- terminal-screen.c	30 Jul 2006 21:44:22 -0000	1.127
+++ terminal-screen.c	5 Sep 2006 01:37:12 -0000
@@ -454,14 +454,45 @@
   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;
+
+  screen = g_object_new (TERMINAL_TYPE_SCREEN, NULL);
+
+  g_signal_connect (G_OBJECT (screen), "parent-set", 
+                    G_CALLBACK (parent_set_callback), 
+                    NULL);
+
+  return screen;
 }
 
 static void
 terminal_screen_map (GtkWidget *widget)
 {
@@ -2244,19 +2275,23 @@
   TARGET_STRING,
   TARGET_COLOR,
   TARGET_BGIMAGE,
   TARGET_RESET_BG,
   TARGET_TEXT_PLAIN,
-  TARGET_MOZ_URL
+  TARGET_MOZ_URL,
+  TARGET_TAB
 };
 
-static void  
-drag_data_received  (GtkWidget *widget, GdkDragContext *context, 
-		     gint x, gint y,
-		     GtkSelectionData *selection_data, guint info,
-		     guint time,
-                     gpointer data)
+void        
+drag_data_received (TerminalScreen   *widget,
+                    GdkDragContext   *context,
+                    gint              x,
+                    gint              y,
+                    GtkSelectionData *selection_data,
+                    guint             info,
+                    guint             time,
+                    gpointer          data)
 {
   TerminalScreen *screen;
 
   screen = TERMINAL_SCREEN (data);
 
@@ -2527,10 +2562,11 @@
 
         g_strfreev (uris);
         g_free (uri_list);
       }
       break;
+
     case TARGET_RESET_BG:
       {
         TerminalProfile *profile;
 
         profile = terminal_screen_get_profile (screen);
@@ -2540,17 +2576,49 @@
             terminal_profile_set_background_type (profile,
                                                   TERMINAL_BACKGROUND_SOLID);
           }
       }
       break;
+
+    case TARGET_TAB:
+      {
+        TerminalScreen *moving_screen;
+        TerminalWindow *source_window;
+        TerminalWindow *dest_window;
+        GtkWidget *source_notebook;
+        GtkWidget *dest_notebook;
+        gint page_num;
+
+        moving_screen = *(TerminalScreen**) selection_data->data;
+
+        g_return_if_fail (TERMINAL_IS_SCREEN (moving_screen));
+
+        source_window = terminal_screen_get_window (moving_screen);
+        source_notebook = terminal_window_get_notebook (source_window);
+        dest_window = terminal_screen_get_window (screen);
+        dest_notebook = terminal_window_get_notebook (dest_window);
+        page_num = gtk_notebook_page_num (GTK_NOTEBOOK (dest_notebook), 
+                                          GTK_WIDGET (screen));
+
+        g_object_ref (G_OBJECT (moving_screen));
+        terminal_window_add_screen (dest_window, moving_screen, page_num);
+        g_object_unref (G_OBJECT (moving_screen));
+
+        gtk_drag_finish (context, TRUE, TRUE, time);
+      }
+      break;
+
+    default:
+      g_assert_not_reached ();
     }
 }
 
 static void
 terminal_screen_setup_dnd (TerminalScreen *screen)
 {
   static GtkTargetEntry target_table[] = {
+    { "GTK_NOTEBOOK_TAB", GTK_TARGET_SAME_APP, TARGET_TAB },
     { "application/x-color", 0, TARGET_COLOR },
     { "property/bgimage",    0, TARGET_BGIMAGE },
     { "x-special/gnome-reset-background", 0, TARGET_RESET_BG },
     { "text/uri-list",  0, TARGET_URI_LIST },
     { "text/x-moz-url",  0, TARGET_MOZ_URL },
Index: terminal-window.c
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal-window.c,v
retrieving revision 1.133
diff -U5 -r1.133 terminal-window.c
--- terminal-window.c	31 Aug 2006 23:34:03 -0000	1.133
+++ terminal-window.c	5 Sep 2006 01:37:13 -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>
@@ -63,14 +62,15 @@
   GtkWidget *move_right_tab_menuitem;
   GtkWidget *detach_tab_menuitem;
   GtkWidget *go_menu;
   GtkWidget *encoding_menuitem;
   GList *tab_menuitems;
-  GList *terms;
+  guint 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,13 @@
    */
   guint fullscreen : 1;
 
   /* Compositing manager integration */
   guint have_argb_visual : 1;
+
+  guint disposed : 1;
+  guint present_on_insert : 1;
 };
 
 enum {
   dummy, /* remove this when you add more signals */
   LAST_SIGNAL
@@ -98,12 +101,12 @@
 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);
 
@@ -112,28 +115,25 @@
 static GtkWidget* screen_get_menuitem  (TerminalScreen *screen);
 
 static TerminalScreen* find_screen (TerminalWindow *window,
                                     TerminalScreen *screen);
 
-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,
-                                             TerminalScreen  *screen,
-                                             TerminalWindow  *window);
-
-static void notebook_tab_removed_callback   (GtkWidget       *notebook,
-                                             TerminalScreen  *screen,
-                                             TerminalWindow  *window);
-
-static void notebook_tabs_reordered_callback (GtkWidget      *notebook,
+static void notebook_page_selected_callback  (GtkWidget       *notebook,
+                                              GtkNotebookPage *useless_crap,
+                                              guint            page_num,
+                                              TerminalWindow  *window);
+static void notebook_page_added_callback     (GtkWidget       *notebook,
+                                              TerminalScreen  *screen,
+                                              guint            page_num,
+                                              TerminalWindow  *window);
+static void notebook_page_removed_callback   (GtkWidget       *notebook,
+                                              TerminalScreen  *screen,
+                                              guint            page_num,
+                                              TerminalWindow  *window);
+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,
@@ -778,10 +778,51 @@
 {
   return window->priv->have_argb_visual;
 }
 
 static void
+update_tab_visibility (TerminalWindow *window,
+                        int             change)
+{
+  gboolean show_tabs;
+  guint num;
+
+  num = gtk_notebook_get_n_pages (GTK_NOTEBOOK (window->priv->notebook));
+
+  show_tabs = (num + change) > 1;
+  gtk_notebook_set_show_tabs (GTK_NOTEBOOK (window->priv->notebook), show_tabs);
+}
+
+static GtkNotebook *
+handle_tab_droped_on_desktop (GtkNotebook *source_notebook,
+                              GtkWidget   *child,
+                              gint         x,
+                              gint         y,
+                              gpointer     data)
+{
+  TerminalScreen *screen;
+  TerminalWindow *source_window;
+  TerminalWindow *dest_window;
+  double zoom;
+
+  screen = TERMINAL_SCREEN (child);
+  source_window = TERMINAL_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (source_notebook)));
+
+  g_return_val_if_fail (TERMINAL_IS_WINDOW (source_window), NULL);
+
+  zoom = terminal_screen_get_font_scale (screen);
+
+  dest_window = terminal_app_new_window (terminal_app_get (), NULL, NULL, NULL, -1);
+  dest_window->priv->present_on_insert = TRUE;
+
+  update_tab_visibility (source_window, -1);
+  update_tab_visibility (dest_window, +1);
+
+  return GTK_NOTEBOOK (dest_window->priv->notebook);
+}
+
+static void
 terminal_window_init (TerminalWindow *window)
 {
   GtkWidget *mi;
   GtkWidget *menu;
   GtkAccelGroup *accel_group;
@@ -792,27 +833,38 @@
                     G_CALLBACK(terminal_window_delete_event),
                     NULL);
 
   gtk_window_set_title (GTK_WINDOW (window), _("Terminal"));
   client = gconf_client_get_default();
+
+  gtk_notebook_set_window_creation_hook (handle_tab_droped_on_desktop, NULL, NULL);
   
   window->priv = g_new0 (TerminalWindowPrivate, 1);
-  window->priv->terms = NULL;
+  window->priv->terms = 0;
+  window->priv->disposed = FALSE;
   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_show_tabs (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);
 
@@ -835,32 +887,27 @@
   
   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),
+                          "page-added",
+                          G_CALLBACK (notebook_page_added_callback),
                           window);
 
   g_signal_connect_after (G_OBJECT (window->priv->notebook),
-                          "tab_detached",
-                          G_CALLBACK (notebook_tab_detached_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,65 +1161,82 @@
 
 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->finalize = terminal_window_finalize;
-  gtk_object_class->destroy = terminal_window_destroy;
+  object_class->dispose = terminal_window_dispose;
   widget_class->show = terminal_window_show;
 }
 
 static void
-terminal_window_finalize (GObject *object)
+terminal_window_dispose (GObject *object)
 {
   TerminalWindow *window;
 
   window = TERMINAL_WINDOW (object);
 
+  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_free (window->priv->startup_id);
-  
-  g_free (window->priv);
-  
-  G_OBJECT_CLASS (parent_class)->finalize (object);
+  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_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);
 
-  g_list_free (window->priv->tab_menuitems);
-  window->priv->tab_menuitems = NULL;
-  
-  /* 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->conf)
+    {
+      g_object_unref (G_OBJECT (window->priv->conf));
+    }
   
-  GTK_OBJECT_CLASS (parent_class)->destroy (object);  
+  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);
+    }
+
+  g_free (window->priv->startup_id);
+  g_free (window->priv);
+
+  G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static gboolean
 terminal_window_delete_event (GtkWidget *widget,
                               GdkEvent *event,
@@ -1318,11 +1382,11 @@
 static void
 update_notebook (TerminalWindow *window)
 {
   gboolean single;
 
-  single = g_list_length (window->priv->terms) == 1;
+  single = window->priv->terms == 1;
     
   gtk_notebook_set_show_border (GTK_NOTEBOOK (window->priv->notebook), !single);
 }
 
 static void
@@ -1385,10 +1449,16 @@
   GtkWidget *notebook;
   int num_pages, page_num;
   gboolean on_last_page;
 
   notebook = window->priv->notebook;
+
+  if (notebook == NULL)
+    {
+      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);
@@ -1422,15 +1492,104 @@
                             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)
+                            TerminalScreen *screen,
+                            gint            position)
 {
   TerminalWindow *old;
+  GtkWidget *tab_label;
  
   old = terminal_screen_get_window (screen);
 
   if (old == window)
     return;  
@@ -1438,50 +1597,58 @@
   g_object_ref (G_OBJECT (screen)); /* make our own new refcount */
 
   if (old)
     terminal_window_remove_screen (old, screen);
 
-  /* 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);
 
   gtk_widget_show_all (GTK_WIDGET (screen));
 
-  terminal_notebook_add_tab (TERMINAL_NOTEBOOK (window->priv->notebook),
-                             screen,
-                             -1,
-                             FALSE);
+  update_tab_visibility (window, +1);
+
+  tab_label = contruct_tab_label (window, screen);
+
+  gtk_notebook_insert_page (GTK_NOTEBOOK (window->priv->notebook),
+                            GTK_WIDGET (screen),
+                            tab_label,
+                            position);
+  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);
+  update_tab_visibility (window, -1);
+
+  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);
 }
 
 GList*
 terminal_window_list_screens (TerminalWindow *window)
 {
-  return g_list_copy (window->priv->terms);
+  /* We are trusting that GtkNotebook will return pages in order */
+  return gtk_container_get_children (GTK_CONTAINER (window->priv->notebook));
 }
 
 int    
 terminal_window_get_screen_count (TerminalWindow *window)
 {
-  return g_list_length (window->priv->terms);
+  return window->priv->terms;
 }
 
 void
 terminal_window_set_menubar_visible (TerminalWindow *window,
                                      gboolean        setting)
@@ -1607,10 +1774,11 @@
 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);
@@ -1635,13 +1803,12 @@
     }
 
   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
@@ -1675,32 +1842,14 @@
 screen_get_menuitem (TerminalScreen *screen)
 {
   return g_object_get_data (G_OBJECT (screen), "menuitem");
 }
 
-static TerminalScreen*
-find_screen (TerminalWindow *window,
-             TerminalScreen *screen)
-{
-  GList *tmp;
-
-  tmp = window->priv->terms;
-  while (tmp != NULL)
-    {
-      if (tmp->data == screen)
-        return tmp->data;
-
-      tmp = tmp->next;
-    }
-
-  return NULL;
-}
-
 static void
 notebook_page_selected_callback (GtkWidget       *notebook,
                                  GtkNotebookPage *useless_crap,
-                                 int              page_num,
+                                 guint            page_num,
                                  TerminalWindow  *window)
 {
   GtkWidget* page_widget;
   TerminalScreen *screen;
   GtkWidget *menu_item;
@@ -1744,31 +1893,22 @@
     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;
 
-  /* 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);
-  }
-  
+  terminal_screen_set_window (screen, window);
+  window->priv->terms++;
+
   g_signal_connect (G_OBJECT (screen),
-                    "profile_set",
+                    "profile-set",
                     G_CALLBACK (profile_set_callback),
                     window);
 
   g_signal_connect (G_OBJECT (screen),
                     "title-changed",
@@ -1789,11 +1929,12 @@
 
   update_notebook (window);
 
   reset_tab_menuitems (window);
   update_tab_sensitivity (window);
-  
+  update_tab_visibility (window, 0);
+
   term = terminal_screen_get_widget (screen);
 
   /* ZvtTerm is a broken POS and requires this realize to get
    * the size request right.
    */
@@ -1815,76 +1956,68 @@
   }
   
   /* Make the first-added screen the active one */
   if (window->priv->active_term == NULL)
     terminal_window_set_active (window, screen);
+
+  if (window->priv->present_on_insert)
+    {
+      gtk_widget_show_all (GTK_WIDGET (window));
+      window->priv->present_on_insert = FALSE;
+    }
 }
 
 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);
-  }
-  
+  int pages;
+
   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);
+  window->priv->terms--;
+
   screen_set_menuitem (screen, NULL);
   
   update_notebook (window);
 
   reset_tab_menuitems (window);
   update_tab_sensitivity (window);
+  update_tab_visibility (window, 0);
 
-  /* The tab bar may have disappeared */
-  single = g_list_length (window->priv->terms) == 1;
-  if (single)
-    terminal_window_set_size (window, window->priv->active_term, TRUE);
-
-  /* Close window if no more terminals */
-  if (window->priv->terms == NULL)
-    gtk_widget_destroy (GTK_WIDGET (window));
+  pages = terminal_window_get_screen_count (window);
+  if (pages == 1)
+    {
+      terminal_window_set_size (window, window->priv->active_term, TRUE);
+    }
+  else if (pages == 0)
+    {
+      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)
 {
@@ -2745,16 +2878,12 @@
   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);
 }
 
@@ -2769,16 +2898,11 @@
   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 -r1.12 terminal-window.h
--- terminal-window.h	10 Jul 2006 18:32:21 -0000	1.12
+++ terminal-window.h	5 Sep 2006 01:37:13 -0000
@@ -53,11 +53,12 @@
 GType terminal_window_get_type (void) G_GNUC_CONST;
 
 TerminalWindow* terminal_window_new (GConfClient *conf);
 
 void terminal_window_add_screen (TerminalWindow *window,
-                                 TerminalScreen *screen);
+                                 TerminalScreen *screen,
+                                 gint            position);
 
 void terminal_window_remove_screen (TerminalWindow *window,
                                     TerminalScreen *screen);
 
 /* Menubar visibility is part of session state, except that
Index: terminal.c
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal.c,v
retrieving revision 1.98
diff -U5 -r1.98 terminal.c
--- terminal.c	24 Jul 2006 22:05:38 -0000	1.98
+++ terminal.c	5 Sep 2006 01:37:14 -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>
@@ -1881,10 +1880,47 @@
     }
   
   return screen;
 }
 
+TerminalWindow *
+terminal_app_new_window   (TerminalApp *app,
+                           const char *role,
+                           const char *startup_id,
+                           const char *display_name,
+                           int screen_number)
+{
+  GdkScreen *gdk_screen;
+  TerminalWindow *window;
+  
+  window = terminal_window_new (conf);
+  g_object_ref (G_OBJECT (window));
+  
+  g_signal_connect (G_OBJECT (window), "destroy",
+                    G_CALLBACK (terminal_window_destroyed),
+                    app);
+  
+  app->windows = g_list_append (app->windows, window);
+
+  gdk_screen = find_screen_by_display_name (display_name, screen_number);
+  if (gdk_screen != NULL)
+    {
+      gtk_window_set_screen (GTK_WINDOW (window), gdk_screen);
+      g_object_unref (G_OBJECT (gdk_screen));
+    }
+
+  if (startup_id != NULL)
+    terminal_window_set_startup_id (window, startup_id);
+  
+  if (role == NULL)
+    terminal_util_set_unique_role (GTK_WINDOW (window), "gnome-terminal");
+  else
+    gtk_window_set_role (GTK_WINDOW (window), role);
+
+  return window;
+}
+
 void
 terminal_app_new_terminal (TerminalApp     *app,
                            TerminalProfile *profile,
                            TerminalWindow  *window,
                            TerminalScreen  *screen,
@@ -1907,81 +1943,47 @@
   g_return_if_fail (profile);
 
   window_created = FALSE;
   if (window == NULL)
     {
-      GdkScreen *gdk_screen;
-      
+      window = terminal_app_new_window (app, role, startup_id, display_name, screen_number);
       window_created = TRUE;
-      window = terminal_window_new (conf);
-      g_object_ref (G_OBJECT (window));
-      
-      g_signal_connect (G_OBJECT (window), "destroy",
-                        G_CALLBACK (terminal_window_destroyed),
-                        app);
-      
-      app->windows = g_list_append (app->windows, window);
-
-      gdk_screen = find_screen_by_display_name (display_name, screen_number);
-      if (gdk_screen != NULL)
-        {
-          gtk_window_set_screen (GTK_WINDOW (window), gdk_screen);
-          g_object_unref (G_OBJECT (gdk_screen));
-        }
-
-      if (startup_id != NULL)
-        terminal_window_set_startup_id (window, startup_id);
-      
-      if (role == NULL)
-        terminal_util_set_unique_role (GTK_WINDOW (window), "gnome-terminal");
-      else
-        gtk_window_set_role (GTK_WINDOW (window), role);
     }
 
   if (force_menubar_state)
     {
       terminal_window_set_menubar_visible (window, forced_menubar_state);
     }
 
-  screen_created = FALSE;
+  screen_created = NULL;
   if (screen == NULL)
-    {  
+    {
       screen_created = TRUE;
       screen = terminal_screen_new ();
       
       terminal_screen_set_profile (screen, profile);
-    
+
       if (title)
-	{
-	  terminal_screen_set_dynamic_title (screen, title, FALSE);
-	  terminal_screen_set_dynamic_icon_title (screen, title, FALSE);
-	}
+        {
+          terminal_screen_set_dynamic_title (screen, title, FALSE);
+          terminal_screen_set_dynamic_icon_title (screen, title, FALSE);
+        }
 
       if (working_dir)
         terminal_screen_set_working_dir (screen, working_dir);
       
       if (override_command)    
         terminal_screen_set_override_command (screen, override_command);
-    
+
       terminal_screen_set_font_scale (screen, zoom);
       terminal_screen_set_font (screen);
-    
-      terminal_window_add_screen (window, screen);
+
+      terminal_window_add_screen (window, screen, -1);
 
       terminal_screen_reread_profile (screen);
 
-      g_object_unref (G_OBJECT (screen));
-    
       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));
-      
-      terminal_notebook_move_tab (src_notebook, dest_notebook, screen, 0);
     }
 
   if (geometry)
     {
       if (!gtk_window_parse_geometry (GTK_WINDOW (window),
Index: terminal.h
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal.h,v
retrieving revision 1.21
diff -U5 -r1.21 terminal.h
--- terminal.h	1 Jan 2006 21:07:57 -0000	1.21
+++ terminal.h	5 Sep 2006 01:37:14 -0000
@@ -37,10 +37,16 @@
 
 void terminal_app_new_profile (TerminalApp     *app,
                                TerminalProfile *default_base_profile,
                                GtkWindow       *transient_parent);
 
+TerminalWindow * terminal_app_new_window   (TerminalApp *app,
+                                            const char *role,
+                                            const char *startup_id,
+                                            const char *display_name,
+                                            int screen_number);
+
 void terminal_app_new_terminal (TerminalApp     *app,
                                 TerminalProfile *profile,
                                 TerminalWindow  *window,
                                 TerminalScreen  *screen,
                                 gboolean         force_menubar_state,
