[gnome-builder] testui: Improve unit test output panel



commit 0f0a47e9ac8491e9e70f7af159cb2effc45e48c9
Author: Daniel Buch Hansen <boogiewasthere gmail com>
Date:   Thu Feb 28 19:36:34 2019 +0100

    testui: Improve unit test output panel
    
    Do this by copying the clear/save buttons layout from build output.

 src/plugins/testui/gbp-test-output-panel.c  | 104 +++++++++++++++++++++++++---
 src/plugins/testui/gbp-test-output-panel.h  |   3 +-
 src/plugins/testui/gbp-test-output-panel.ui |  68 ++++++++++++++++++
 src/plugins/testui/testui.gresource.xml     |   1 +
 4 files changed, 164 insertions(+), 12 deletions(-)
---
diff --git a/src/plugins/testui/gbp-test-output-panel.c b/src/plugins/testui/gbp-test-output-panel.c
index f764ed9f6..f79561f51 100644
--- a/src/plugins/testui/gbp-test-output-panel.c
+++ b/src/plugins/testui/gbp-test-output-panel.c
@@ -23,36 +23,118 @@
 #include "config.h"
 
 #include <glib/gi18n.h>
-#include <libide-gui.h>
-#include <libide-editor.h>
 #include <libide-terminal.h>
 
 #include "gbp-test-output-panel.h"
 
 struct _GbpTestOutputPanel
 {
-  DzlDockWidget    parent_instance;
-  IdeTerminalPage *terminal;
+  IdePane      parent_instance;
+  IdeTerminal *terminal;
 };
 
-G_DEFINE_TYPE (GbpTestOutputPanel, gbp_test_output_panel, DZL_TYPE_DOCK_WIDGET)
+G_DEFINE_TYPE (GbpTestOutputPanel, gbp_test_output_panel, IDE_TYPE_PANE)
 
 static void
 gbp_test_output_panel_class_init (GbpTestOutputPanelClass *klass)
 {
+  GtkWidgetClass *widget_class = (GtkWidgetClass*)klass;
+
+  gtk_widget_class_set_template_from_resource (widget_class, "/plugins/testui/gbp-test-output-panel.ui");
+  gtk_widget_class_bind_template_child (widget_class, GbpTestOutputPanel, terminal);
+}
+
+static void
+gbp_testui_output_panel_save_in_file (GSimpleAction *action,
+                                      GVariant      *param,
+                                      gpointer       user_data)
+{
+  GbpTestOutputPanel *self = user_data;
+  g_autoptr(GtkFileChooserNative) native = NULL;
+  GtkWidget *window;
+  gint res;
+
+  IDE_ENTRY;
+
+  g_assert (G_IS_SIMPLE_ACTION (action));
+  g_assert (GBP_IS_TEST_OUTPUT_PANEL (self));
+
+  window = gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_WINDOW);
+  native = gtk_file_chooser_native_new (_("Save File"),
+                                        GTK_WINDOW (window),
+                                        GTK_FILE_CHOOSER_ACTION_SAVE,
+                                        _("_Save"),
+                                        _("_Cancel"));
+
+  res = gtk_native_dialog_run (GTK_NATIVE_DIALOG (native));
+
+  if (res == GTK_RESPONSE_ACCEPT)
+    {
+      g_autoptr(GFile) file = NULL;
+
+      file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (native));
+
+      if (file != NULL)
+        {
+          g_autoptr(GFileOutputStream) stream = NULL;
+          g_autoptr(GError) error = NULL;
+
+          stream = g_file_replace (file,
+                                   NULL,
+                                   FALSE,
+                                   G_FILE_CREATE_REPLACE_DESTINATION,
+                                   NULL,
+                                   &error);
+
+          if (stream != NULL)
+            {
+              vte_terminal_write_contents_sync (VTE_TERMINAL (self->terminal),
+                                                G_OUTPUT_STREAM (stream),
+                                                VTE_WRITE_DEFAULT,
+                                                NULL,
+                                                &error);
+              g_output_stream_close (G_OUTPUT_STREAM (stream), NULL, NULL);
+            }
+
+          if (error != NULL)
+            g_warning ("Failed to write contents: %s", error->message);
+        }
+    }
+
+  IDE_EXIT;
+
+}
+
+static void
+gbp_testui_output_panel_clear_activate (GSimpleAction *action,
+                                        GVariant      *param,
+                                        gpointer       user_data)
+{
+  GbpTestOutputPanel *self = user_data;
+
+  g_assert (GBP_IS_TEST_OUTPUT_PANEL (self));
+  g_assert (G_IS_SIMPLE_ACTION (action));
+
+  vte_terminal_reset(VTE_TERMINAL (self->terminal), TRUE, TRUE);
 }
 
 static void
 gbp_test_output_panel_init (GbpTestOutputPanel *self)
 {
+  g_autoptr(GSimpleActionGroup) actions = NULL;
+  static const GActionEntry entries[] = {
+    { "clear", gbp_testui_output_panel_clear_activate },
+    { "save", gbp_testui_output_panel_save_in_file },
+  };
+
+  gtk_widget_init_template (GTK_WIDGET(self));
+
   dzl_dock_widget_set_title (DZL_DOCK_WIDGET (self), _("Unit Test Output"));
   dzl_dock_widget_set_icon_name (DZL_DOCK_WIDGET (self), "builder-unit-tests-symbolic");
 
-  self->terminal = g_object_new (IDE_TYPE_TERMINAL_PAGE,
-                                 "manage-spawn", FALSE,
-                                 "visible", TRUE,
-                                 NULL);
-  gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (self->terminal));
+  actions = g_simple_action_group_new ();
+  g_action_map_add_action_entries (G_ACTION_MAP (actions), entries, G_N_ELEMENTS (entries), self);
+  gtk_widget_insert_action_group (GTK_WIDGET (self), "test-output", G_ACTION_GROUP (actions));
 }
 
 GtkWidget *
@@ -63,7 +145,7 @@ gbp_test_output_panel_new (VtePty *pty)
   g_return_val_if_fail (VTE_IS_PTY (pty), NULL);
 
   self = g_object_new (GBP_TYPE_TEST_OUTPUT_PANEL, NULL);
-  ide_terminal_page_set_pty (self->terminal, pty);
+  vte_terminal_set_pty (VTE_TERMINAL (self->terminal), pty);
 
   return GTK_WIDGET (self);
 }
diff --git a/src/plugins/testui/gbp-test-output-panel.h b/src/plugins/testui/gbp-test-output-panel.h
index 98f2afe18..e22147bdb 100644
--- a/src/plugins/testui/gbp-test-output-panel.h
+++ b/src/plugins/testui/gbp-test-output-panel.h
@@ -20,6 +20,7 @@
 
 #pragma once
 
+#include <libide-gui.h>
 #include <dazzle.h>
 #include <vte/vte.h>
 
@@ -27,7 +28,7 @@ G_BEGIN_DECLS
 
 #define GBP_TYPE_TEST_OUTPUT_PANEL (gbp_test_output_panel_get_type())
 
-G_DECLARE_FINAL_TYPE (GbpTestOutputPanel, gbp_test_output_panel, GBP, TEST_OUTPUT_PANEL, DzlDockWidget)
+G_DECLARE_FINAL_TYPE (GbpTestOutputPanel, gbp_test_output_panel, GBP, TEST_OUTPUT_PANEL, IdePane)
 
 GtkWidget *gbp_test_output_panel_new (VtePty *pty);
 
diff --git a/src/plugins/testui/gbp-test-output-panel.ui b/src/plugins/testui/gbp-test-output-panel.ui
new file mode 100644
index 000000000..9327c464c
--- /dev/null
+++ b/src/plugins/testui/gbp-test-output-panel.ui
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="GbpTestOutputPanel" parent="IdePane">
+    <child>
+      <object class="GtkBox">
+        <property name="orientation">horizontal</property>
+        <property name="visible">true</property>
+        <child>
+          <object class="IdeTerminal" id="terminal">
+            <property name="audible-bell">false</property>
+            <property name="expand">true</property>
+            <property name="visible">true</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkScrollbar" id="scrollbar">
+            <property name="orientation">vertical</property>
+            <property name="visible">true</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkBox">
+            <property name="border-width">2</property>
+            <property name="hexpand">false</property>
+            <property name="orientation">vertical</property>
+            <property name="spacing">2</property>
+            <property name="vexpand">true</property>
+            <property name="visible">true</property>
+            <child>
+              <object class="GtkButton" id="clear_button">
+                <property name="action-name">test-output.clear</property>
+                <property name="expand">false</property>
+                <property name="tooltip-text" translatable="yes">Clear test output</property>
+                <property name="visible">true</property>
+                <style>
+                  <class name="flat"/>
+                </style>
+                <child>
+                  <object class="GtkImage">
+                    <property name="icon-name">edit-clear-all-symbolic</property>
+                    <property name="visible">true</property>
+                  </object>
+                </child>
+              </object>
+            </child>
+            <child>
+              <object class="GtkButton" id="save_button">
+                <property name="action-name">test-output.save</property>
+                <property name="expand">false</property>
+                <property name="tooltip-text" translatable="yes">Save test output</property>
+                <property name="visible">true</property>
+                <style>
+                  <class name="flat"/>
+                </style>
+                <child>
+                  <object class="GtkImage">
+                    <property name="icon-name">document-save-symbolic</property>
+                    <property name="visible">true</property>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/plugins/testui/testui.gresource.xml b/src/plugins/testui/testui.gresource.xml
index 1c245e26e..e26f525cc 100644
--- a/src/plugins/testui/testui.gresource.xml
+++ b/src/plugins/testui/testui.gresource.xml
@@ -2,5 +2,6 @@
 <gresources>
   <gresource prefix="/plugins/testui">
     <file>testui.plugin</file>
+    <file preprocess="xml-stripblanks">gbp-test-output-panel.ui</file>
   </gresource>
 </gresources>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]