? o
Index: terminal-accels.c
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal-accels.c,v
retrieving revision 1.29
diff -u -p -r1.29 terminal-accels.c
--- terminal-accels.c	26 Apr 2004 05:46:24 -0000	1.29
+++ terminal-accels.c	2 Mar 2005 01:35:19 -0000
@@ -33,6 +33,7 @@
 #define KEY_NEW_TAB CONF_KEYS_PREFIX"/new_tab"
 #define KEY_NEW_WINDOW CONF_KEYS_PREFIX"/new_window"
 #define KEY_NEW_PROFILE CONF_KEYS_PREFIX"/new_profile"
+#define KEY_SAVE_TAB CONF_KEYS_PREFIX"/save_tab"
 #define KEY_CLOSE_TAB CONF_KEYS_PREFIX"/close_tab"
 #define KEY_CLOSE_WINDOW CONF_KEYS_PREFIX"/close_window"
 #define KEY_COPY CONF_KEYS_PREFIX"/copy"
@@ -78,6 +79,8 @@ static KeyEntry file_entries[] =
     KEY_NEW_WINDOW, ACCEL_PATH_NEW_WINDOW, 0, 0, NULL, FALSE },
   { N_("New Profile"),
     KEY_NEW_PROFILE, ACCEL_PATH_NEW_PROFILE, 0, 0, NULL, FALSE },
+  { N_("Save Tab"),
+    KEY_SAVE_TAB, ACCEL_PATH_SAVE_TAB, 0, 0, NULL, FALSE },
   { N_("Close Tab"),
     KEY_CLOSE_TAB, ACCEL_PATH_CLOSE_TAB, 0, 0, NULL, FALSE },
   { N_("Close Window"),
Index: terminal-accels.h
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal-accels.h,v
retrieving revision 1.9
diff -u -p -r1.9 terminal-accels.h
--- terminal-accels.h	4 Oct 2002 22:29:01 -0000	1.9
+++ terminal-accels.h	2 Mar 2005 01:35:19 -0000
@@ -32,6 +32,7 @@ GtkAccelGroup* terminal_accels_get_group
 #define ACCEL_PATH_NEW_TAB ACCEL_PATH_ROOT"/new_tab"
 #define ACCEL_PATH_NEW_WINDOW ACCEL_PATH_ROOT"/new_window"
 #define ACCEL_PATH_NEW_PROFILE ACCEL_PATH_ROOT"/new_profile"
+#define ACCEL_PATH_SAVE_TAB ACCEL_PATH_ROOT"/save_tab"
 #define ACCEL_PATH_CLOSE_TAB ACCEL_PATH_ROOT"/close_tab"
 #define ACCEL_PATH_CLOSE_WINDOW ACCEL_PATH_ROOT"/close_window"
 #define ACCEL_PATH_COPY ACCEL_PATH_ROOT"/copy"
Index: terminal-screen.c
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal-screen.c,v
retrieving revision 1.99
diff -u -p -r1.99 terminal-screen.c
--- terminal-screen.c	29 Nov 2004 09:40:19 -0000	1.99
+++ terminal-screen.c	2 Mar 2005 01:35:21 -0000
@@ -1129,6 +1129,13 @@ terminal_screen_launch_child (TerminalSc
   g_strfreev (env);
 }
 
+const char* 
+terminal_get_scrollback_text (TerminalScreen *screen)
+{
+  g_return_val_if_fail (screen->priv->window, NULL);
+  return terminal_widget_get_scrollback_text (screen->priv->term);
+}
+
 void
 terminal_screen_close (TerminalScreen *screen)
 {
Index: terminal-screen.h
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal-screen.h,v
retrieving revision 1.9
diff -u -p -r1.9 terminal-screen.h
--- terminal-screen.h	13 Oct 2003 02:49:18 -0000	1.9
+++ terminal-screen.h	2 Mar 2005 01:35:21 -0000
@@ -88,6 +88,8 @@ const char* terminal_screen_get_title   
 const char* terminal_screen_get_icon_title     (TerminalScreen *screen);
 gboolean    terminal_screen_get_icon_title_set (TerminalScreen *screen);
 
+const char* terminal_get_scrollback_text (TerminalScreen *screen);
+
 void terminal_screen_close (TerminalScreen *screen);
 
 gboolean terminal_screen_get_text_selected (TerminalScreen *screen);
Index: terminal-widget-vte.c
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal-widget-vte.c,v
retrieving revision 1.34
diff -u -p -r1.34 terminal-widget-vte.c
--- terminal-widget-vte.c	28 Jun 2004 07:44:02 -0000	1.34
+++ terminal-widget-vte.c	2 Mar 2005 01:35:21 -0000
@@ -539,6 +539,33 @@ terminal_widget_get_has_selection (GtkWi
   return vte_terminal_get_has_selection(VTE_TERMINAL(widget));
 }
 
+static gboolean
+always_selected(VteTerminal *terminal, glong row, glong column, gpointer data)
+{
+  return TRUE;
+}
+
+const char*
+terminal_widget_get_scrollback_text (GtkWidget *widget)
+{
+  GArray *array;
+  VteTerminal *terminal;
+  glong rows, cols;
+
+  terminal = VTE_TERMINAL (widget);
+  g_return_val_if_fail (VTE_IS_TERMINAL(terminal), NULL);
+
+  array = g_array_new(FALSE, TRUE, sizeof(struct _VteCharAttributes));
+  cols = vte_terminal_get_column_count (terminal);
+  rows = vte_terminal_get_current_scrollback_lines(terminal);
+
+  return vte_terminal_get_text_range (terminal,
+      0, 0,
+      rows, cols,
+      always_selected,
+      NULL,
+      array);
+}
 
 GtkAdjustment*
 terminal_widget_get_scroll_adjustment (GtkWidget *widget)
Index: terminal-widget.h
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal-widget.h,v
retrieving revision 1.10
diff -u -p -r1.10 terminal-widget.h
--- terminal-widget.h	28 Jun 2004 07:44:02 -0000	1.10
+++ terminal-widget.h	2 Mar 2005 01:35:21 -0000
@@ -142,6 +142,8 @@ const char* terminal_widget_get_title   
 const char* terminal_widget_get_icon_title    (GtkWidget *widget);
 gboolean    terminal_widget_get_has_selection (GtkWidget *widget);
 
+const char* terminal_widget_get_scrollback_text (GtkWidget *widget);
+
 GtkAdjustment* terminal_widget_get_scroll_adjustment (GtkWidget *widget);
 
 gboolean terminal_widget_fork_command      (GtkWidget   *widget,
Index: terminal-window.c
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal-window.c,v
retrieving revision 1.106
diff -u -p -r1.106 terminal-window.c
--- terminal-window.c	28 Feb 2005 23:27:11 -0000	1.106
+++ terminal-window.c	2 Mar 2005 01:35:23 -0000
@@ -47,6 +47,7 @@ struct _TerminalWindowPrivate
   GtkWidget *help_menuitem;
   GtkWidget *new_window_menuitem;
   GtkWidget *new_tab_menuitem;
+  GtkWidget *save_tab_menuitem;
   GtkWidget *close_tab_menuitem;
   GtkWidget *copy_menuitem;
   GtkWidget *paste_menuitem;
@@ -144,6 +145,8 @@ static void new_tab_callback            
                                            TerminalWindow *window);
 static void close_window_callback         (GtkWidget      *menuitem,
                                            TerminalWindow *window);
+static void save_tab_callback            (GtkWidget      *menuitem,
+                                           TerminalWindow *window);
 static void close_tab_callback            (GtkWidget      *menuitem,
                                            TerminalWindow *window);
 static void copy_callback                 (GtkWidget      *menuitem,
@@ -867,6 +870,11 @@ terminal_window_init (TerminalWindow *wi
   gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
 
   window->priv->close_tab_menuitem = 
+    append_menuitem (menu, _("_Save Tab"), ACCEL_PATH_SAVE_TAB,
+                     G_CALLBACK (save_tab_callback),
+                     window);
+  
+  window->priv->close_tab_menuitem = 
     append_menuitem (menu, _("C_lose Tab"), ACCEL_PATH_CLOSE_TAB,
                      G_CALLBACK (close_tab_callback),
                      window);
@@ -2355,6 +2363,43 @@ close_window_callback (GtkWidget      *m
 }
 
 static void
+save_tab_callback (GtkWidget      *menuitem,
+                    TerminalWindow *window)
+{
+  gchar *filename = NULL;
+  FILE  *fd;
+  GtkWidget *dialog = NULL;
+
+  // ask for file location
+  dialog = gtk_file_chooser_dialog_new ( _("Save as..."),
+      NULL,
+      GTK_FILE_CHOOSER_ACTION_SAVE,
+      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+      GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
+      NULL);
+
+  if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
+    filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+
+  gtk_widget_destroy (dialog);
+
+  g_return_if_fail (filename!=NULL);
+
+  // save all current scrollback lines
+  fd = fopen (filename,"w");
+
+  if (fd != NULL && window->priv->active_term)
+  {
+    fputs (terminal_get_scrollback_text (window->priv->active_term), fd);
+    fclose(fd);
+  } else {
+    g_warning ("Could not write file: %s\n", filename);
+  }
+
+  g_free(filename);
+}
+
+static void
 close_tab_callback (GtkWidget      *menuitem,
                     TerminalWindow *window)
 {
