[Xfce4-commits] [apps/xfce4-terminal] 01/01: Add ability to save terminal contents to file

noreply at xfce.org noreply at xfce.org
Tue Aug 23 12:43:10 CEST 2016


This is an automated email from the git hooks/post-receive script.

f2404 pushed a commit to branch master
in repository apps/xfce4-terminal.

commit f0ba2f35176018905bed2a349b8f5bbba7c5e2f7
Author: Igor <f2404 at yandex.ru>
Date:   Tue Aug 23 13:42:35 2016 +0300

    Add ability to save terminal contents to file
    
    Based on gnome-terminal code
---
 terminal/terminal-screen.c      | 12 ++++++++
 terminal/terminal-screen.h      |  4 +++
 terminal/terminal-window-ui.xml |  4 +++
 terminal/terminal-window.c      | 67 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 87 insertions(+)

diff --git a/terminal/terminal-screen.c b/terminal/terminal-screen.c
index 3bde8b5..81ac92a 100644
--- a/terminal/terminal-screen.c
+++ b/terminal/terminal-screen.c
@@ -2316,3 +2316,15 @@ terminal_screen_set_input_enabled (TerminalScreen *screen,
   terminal_return_if_fail (TERMINAL_IS_SCREEN (screen));
   vte_terminal_set_input_enabled (VTE_TERMINAL (screen->terminal), enabled);
 }
+
+
+
+void
+terminal_screen_save_contents (TerminalScreen *screen,
+                               GOutputStream  *stream,
+                               GError         *error)
+{
+  terminal_return_if_fail (TERMINAL_IS_SCREEN (screen));
+  vte_terminal_write_contents_sync (VTE_TERMINAL (screen->terminal),
+                                    stream, VTE_WRITE_DEFAULT, NULL, &error);
+}
diff --git a/terminal/terminal-screen.h b/terminal/terminal-screen.h
index a5bf9d1..8db3f8d 100644
--- a/terminal/terminal-screen.h
+++ b/terminal/terminal-screen.h
@@ -114,6 +114,10 @@ void         terminal_screen_update_font                  (TerminalScreen *scree
 void         terminal_screen_set_input_enabled            (TerminalScreen *screen,
                                                            gboolean        enabled);
 
+void         terminal_screen_save_contents                (TerminalScreen *screen,
+                                                           GOutputStream  *stream,
+                                                           GError         *error);
+
 G_END_DECLS
 
 #endif /* !TERMINAL_SCREEN_H */
diff --git a/terminal/terminal-window-ui.xml b/terminal/terminal-window-ui.xml
index 9e50e82..614507c 100644
--- a/terminal/terminal-window-ui.xml
+++ b/terminal/terminal-window-ui.xml
@@ -49,6 +49,8 @@
       <separator/>
       <menuitem action="read-only"/>
       <separator/>
+      <menuitem action="save-contents"/>
+      <separator/>
       <menuitem action="reset"/>
       <menuitem action="reset-and-clear"/>
     </menu>
@@ -83,6 +85,8 @@
     <menuitem action="zoom-out"/>
     <menuitem action="zoom-reset"/>
     <separator/>
+    <menuitem action="save-contents"/>
+    <separator/>
     <menuitem action="preferences"/>
   </popup>
 
diff --git a/terminal/terminal-window.c b/terminal/terminal-window.c
index 93301e0..fa0969f 100644
--- a/terminal/terminal-window.c
+++ b/terminal/terminal-window.c
@@ -199,6 +199,8 @@ static void         terminal_window_action_search_next            (GtkAction
                                                                    TerminalWindow         *window);
 static void         terminal_window_action_search_prev            (GtkAction              *action,
                                                                    TerminalWindow         *window);
+static void         terminal_window_action_save_contents          (GtkAction              *action,
+                                                                   TerminalWindow         *window);
 static void         terminal_window_action_reset                  (GtkAction              *action,
                                                                    TerminalWindow         *window);
 static void         terminal_window_action_reset_and_clear        (GtkAction              *action,
@@ -247,6 +249,7 @@ static const GtkActionEntry action_entries[] =
     { "search", "edit-find", N_ ("_Find..."), "<control><shift>f", N_ ("Search terminal contents"), G_CALLBACK (terminal_window_action_search), },
     { "search-next", NULL, N_ ("Find Ne_xt"), NULL, NULL, G_CALLBACK (terminal_window_action_search_next), },
     { "search-prev", NULL, N_ ("Find Pre_vious"), NULL, NULL, G_CALLBACK (terminal_window_action_search_prev), },
+    { "save-contents", "document-save-as", N_ ("Sa_ve Contents..."), NULL, NULL, G_CALLBACK (terminal_window_action_save_contents), },
     { "reset", NULL, N_ ("_Reset"), NULL, NULL, G_CALLBACK (terminal_window_action_reset), },
     { "reset-and-clear", NULL, N_ ("_Clear Scrollback and Reset"), NULL, NULL, G_CALLBACK (terminal_window_action_reset_and_clear), },
   { "tabs-menu", NULL, N_ ("T_abs"), NULL, NULL, NULL, },
@@ -1958,6 +1961,70 @@ terminal_window_action_search_prev (GtkAction      *action,
 
 
 static void
+terminal_window_action_save_contents (GtkAction      *action,
+                                      TerminalWindow *window)
+{
+  GtkWidget     *dialog;
+  GFile         *file;
+  GOutputStream *stream;
+  GError        *error = NULL;
+  gchar         *filename_uri;
+  gint           response;
+
+  terminal_return_if_fail (window->active != NULL);
+
+  dialog = gtk_file_chooser_dialog_new (_("Save contents..."),
+                                        GTK_WINDOW (window),
+                                        GTK_FILE_CHOOSER_ACTION_SAVE,
+                                        _("_Cancel"), GTK_RESPONSE_CANCEL,
+                                        _("_Save"), GTK_RESPONSE_ACCEPT,
+                                        NULL);
+  gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
+
+  /* save to current working directory */
+  gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog),
+                                       terminal_screen_get_working_directory (TERMINAL_SCREEN (window->active)));
+
+  gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window));
+  gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
+  gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
+
+  gtk_widget_show_all (dialog);
+
+  response = gtk_dialog_run (GTK_DIALOG (dialog));
+  if (response != GTK_RESPONSE_ACCEPT)
+    {
+      gtk_widget_destroy (dialog);
+      return;
+    }
+
+  filename_uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
+  gtk_widget_destroy (dialog);
+
+  if (filename_uri == NULL)
+    return;
+
+  file = g_file_new_for_uri (filename_uri);
+  stream = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, &error));
+  if (stream)
+    {
+      terminal_screen_save_contents (TERMINAL_SCREEN (window->active), stream, error);
+      g_object_unref (stream);
+    }
+
+  if (error)
+  {
+    xfce_dialog_show_error (GTK_WINDOW (window), error, _("Failed to save terminal contents"));
+    g_error_free (error);
+  }
+
+  g_object_unref (file);
+  g_free (filename_uri);
+}
+
+
+
+static void
 terminal_window_action_reset (GtkAction      *action,
                               TerminalWindow *window)
 {

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list