[gnome-builder] build-tools: add panel to show build output



commit 94f89aa8750625549e75fa009e52aa251775e07f
Author: Christian Hergert <chergert redhat com>
Date:   Tue Dec 22 01:23:17 2015 -0800

    build-tools: add panel to show build output

 plugins/build-tools/Makefile.am                   |    2 +
 plugins/build-tools/gbp-build-log-panel.c         |  186 +++++++++++++++++++++
 plugins/build-tools/gbp-build-log-panel.h         |   36 ++++
 plugins/build-tools/gbp-build-log-panel.ui        |   19 ++
 plugins/build-tools/gbp-build-tools.gresource.xml |    1 +
 plugins/build-tools/gbp-build-workbench-addin.c   |   17 ++
 plugins/build-tools/theme/shared.css              |    4 +
 7 files changed, 265 insertions(+), 0 deletions(-)
---
diff --git a/plugins/build-tools/Makefile.am b/plugins/build-tools/Makefile.am
index 5fadfa7..dcd2b8c 100644
--- a/plugins/build-tools/Makefile.am
+++ b/plugins/build-tools/Makefile.am
@@ -10,6 +10,8 @@ plugin_LTLIBRARIES = libbuild-tools-plugin.la
 dist_plugin_DATA = build-tools.plugin
 
 libbuild_tools_plugin_la_SOURCES = \
+       gbp-build-log-panel.c \
+       gbp-build-log-panel.h \
        gbp-build-panel.c \
        gbp-build-panel.h \
        gbp-build-panel-row.c \
diff --git a/plugins/build-tools/gbp-build-log-panel.c b/plugins/build-tools/gbp-build-log-panel.c
new file mode 100644
index 0000000..ba23ff5
--- /dev/null
+++ b/plugins/build-tools/gbp-build-log-panel.c
@@ -0,0 +1,186 @@
+/* gbp-build-log-panel.c
+ *
+ * Copyright (C) 2015 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib/gi18n.h>
+#include <ide.h>
+
+#include "egg-signal-group.h"
+
+#include "gbp-build-log-panel.h"
+
+struct _GbpBuildLogPanel
+{
+  GtkBin          parent_instance;
+
+  IdeBuildResult *result;
+  EggSignalGroup *signals;
+
+  GtkTextBuffer  *buffer;
+  GtkTextView    *text_view;
+  GtkTextTag     *stderr_tag;
+};
+
+enum {
+  PROP_0,
+  PROP_RESULT,
+  LAST_PROP
+};
+
+G_DEFINE_TYPE (GbpBuildLogPanel, gbp_build_log_panel, GTK_TYPE_BIN)
+
+static GParamSpec *properties [LAST_PROP];
+
+static void
+gbp_build_log_panel_log (GbpBuildLogPanel  *self,
+                         IdeBuildResultLog  log,
+                         const gchar       *message,
+                         IdeBuildResult    *result)
+{
+  GtkTextIter iter;
+
+  g_assert (GBP_IS_BUILD_LOG_PANEL (self));
+  g_assert (message != NULL);
+  g_assert (IDE_IS_BUILD_RESULT (result));
+
+  gtk_text_buffer_get_end_iter (self->buffer, &iter);
+
+  if (G_LIKELY (log == IDE_BUILD_RESULT_LOG_STDOUT))
+    {
+      gtk_text_buffer_insert (self->buffer, &iter, message, -1);
+    }
+  else
+    {
+      GtkTextIter begin;
+      guint offset;
+
+      offset = gtk_text_iter_get_offset (&iter);
+      gtk_text_buffer_insert (self->buffer, &iter, message, -1);
+      gtk_text_buffer_get_iter_at_offset (self->buffer, &begin, offset);
+      gtk_text_buffer_apply_tag (self->buffer, self->stderr_tag, &begin, &iter);
+    }
+
+  gtk_text_view_scroll_mark_onscreen (self->text_view,
+                                      gtk_text_buffer_get_insert (self->buffer));
+}
+
+void
+gbp_build_log_panel_set_result (GbpBuildLogPanel *self,
+                                IdeBuildResult   *result)
+{
+  g_return_if_fail (GBP_IS_BUILD_LOG_PANEL (self));
+
+  if (g_set_object (&self->result, result))
+    {
+      gtk_text_buffer_set_text (self->buffer, "", 0);
+      egg_signal_group_set_target (self->signals, result);
+    }
+}
+
+static void
+gbp_build_log_panel_finalize (GObject *object)
+{
+  GbpBuildLogPanel *self = (GbpBuildLogPanel *)object;
+
+  g_clear_object (&self->result);
+  g_clear_object (&self->signals);
+
+  G_OBJECT_CLASS (gbp_build_log_panel_parent_class)->finalize (object);
+}
+
+static void
+gbp_build_log_panel_get_property (GObject    *object,
+                                  guint       prop_id,
+                                  GValue     *value,
+                                  GParamSpec *pspec)
+{
+  GbpBuildLogPanel *self = GBP_BUILD_LOG_PANEL (object);
+
+  switch (prop_id)
+    {
+    case PROP_RESULT:
+      g_value_set_object (value, self->result);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gbp_build_log_panel_set_property (GObject      *object,
+                                  guint         prop_id,
+                                  const GValue *value,
+                                  GParamSpec   *pspec)
+{
+  GbpBuildLogPanel *self = GBP_BUILD_LOG_PANEL (object);
+
+  switch (prop_id)
+    {
+    case PROP_RESULT:
+      gbp_build_log_panel_set_result (self, g_value_get_object (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gbp_build_log_panel_class_init (GbpBuildLogPanelClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->finalize = gbp_build_log_panel_finalize;
+  object_class->get_property = gbp_build_log_panel_get_property;
+  object_class->set_property = gbp_build_log_panel_set_property;
+
+  gtk_widget_class_set_css_name (widget_class, "buildlogpanel");
+  gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/builder/plugins/build-tools-plugin/gbp-build-log-panel.ui");
+  gtk_widget_class_bind_template_child (widget_class, GbpBuildLogPanel, text_view);
+  gtk_widget_class_bind_template_child (widget_class, GbpBuildLogPanel, buffer);
+
+  properties [PROP_RESULT] =
+    g_param_spec_object ("result",
+                         _("Result"),
+                         _("Result"),
+                         IDE_TYPE_BUILD_RESULT,
+                         (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, LAST_PROP, properties);
+}
+
+static void
+gbp_build_log_panel_init (GbpBuildLogPanel *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+
+  self->stderr_tag = gtk_text_buffer_create_tag (self->buffer,
+                                                 "stderr-tag",
+                                                 "foreground", "#ff0000",
+                                                 "weight", PANGO_WEIGHT_BOLD,
+                                                 NULL);
+
+  self->signals = egg_signal_group_new (IDE_TYPE_BUILD_RESULT);
+
+  egg_signal_group_connect_object (self->signals,
+                                   "log",
+                                   G_CALLBACK (gbp_build_log_panel_log),
+                                   self,
+                                   G_CONNECT_SWAPPED);
+}
diff --git a/plugins/build-tools/gbp-build-log-panel.h b/plugins/build-tools/gbp-build-log-panel.h
new file mode 100644
index 0000000..9cc1a58
--- /dev/null
+++ b/plugins/build-tools/gbp-build-log-panel.h
@@ -0,0 +1,36 @@
+/* gbp-build-log-panel.h
+ *
+ * Copyright (C) 2015 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GBP_BUILD_LOG_PANEL_H
+#define GBP_BUILD_LOG_PANEL_H
+
+#include <gtk/gtk.h>
+#include <ide.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_BUILD_LOG_PANEL (gbp_build_log_panel_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpBuildLogPanel, gbp_build_log_panel, GBP, BUILD_LOG_PANEL, GtkBin)
+
+void gbp_build_log_panel_set_result (GbpBuildLogPanel *self,
+                                     IdeBuildResult   *result);
+
+G_END_DECLS
+
+#endif /* GBP_BUILD_LOG_PANEL_H */
diff --git a/plugins/build-tools/gbp-build-log-panel.ui b/plugins/build-tools/gbp-build-log-panel.ui
new file mode 100644
index 0000000..ed50bb8
--- /dev/null
+++ b/plugins/build-tools/gbp-build-log-panel.ui
@@ -0,0 +1,19 @@
+<interface>
+  <template class="GbpBuildLogPanel" parent="GtkBin">
+    <child>
+      <object class="GtkScrolledWindow">
+        <property name="visible">true</property>
+        <child>
+          <object class="GtkTextView" id="text_view">
+            <property name="cursor-visible">false</property>
+            <property name="editable">false</property>
+            <property name="buffer">buffer</property>
+            <property name="visible">true</property>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+  <object class="GtkTextBuffer" id="buffer">
+  </object>
+</interface>
diff --git a/plugins/build-tools/gbp-build-tools.gresource.xml 
b/plugins/build-tools/gbp-build-tools.gresource.xml
index 6c6a860..fa21ac1 100644
--- a/plugins/build-tools/gbp-build-tools.gresource.xml
+++ b/plugins/build-tools/gbp-build-tools.gresource.xml
@@ -3,6 +3,7 @@
   <gresource prefix="/org/gnome/builder/plugins/build-tools-plugin">
     <file>gtk/menus.ui</file>
     <file>theme/shared.css</file>
+    <file>gbp-build-log-panel.ui</file>
     <file>gbp-build-panel.ui</file>
     <file>gbp-build-panel-row.ui</file>
   </gresource>
diff --git a/plugins/build-tools/gbp-build-workbench-addin.c b/plugins/build-tools/gbp-build-workbench-addin.c
index 6cafeea..7fc4b21 100644
--- a/plugins/build-tools/gbp-build-workbench-addin.c
+++ b/plugins/build-tools/gbp-build-workbench-addin.c
@@ -21,6 +21,7 @@
 #include "egg-binding-group.h"
 
 #include "gbp-build-panel.h"
+#include "gbp-build-log-panel.h"
 #include "gbp-build-workbench-addin.h"
 
 struct _GbpBuildWorkbenchAddin
@@ -30,6 +31,7 @@ struct _GbpBuildWorkbenchAddin
   /* Unowned */
   GbpBuildPanel      *panel;
   IdeWorkbench       *workbench;
+  GbpBuildLogPanel   *build_log_panel;
 
   /* Owned */
   EggBindingGroup    *bindings;
@@ -133,6 +135,7 @@ gbp_build_workbench_addin_save_all_cb (GObject      *object,
                            g_object_ref (state->self));
 
   gbp_build_workbench_addin_set_result (state->self, build_result);
+  gbp_build_log_panel_set_result (state->self->build_log_panel, build_result);
 
   g_object_unref (state->self);
   g_object_unref (state->builder);
@@ -181,6 +184,14 @@ gbp_build_workbench_addin_do_build (GbpBuildWorkbenchAddin *self,
                                      self->cancellable,
                                      gbp_build_workbench_addin_save_all_cb,
                                      state);
+
+  /* Ensure the build output is visible */
+  /* XXX: we might want to find a way to add a "hold" on the panel
+   *      visibility so that it can be hidden after a timeout.
+   */
+  gtk_widget_show (GTK_WIDGET (self->build_log_panel));
+  ide_workbench_focus (workbench, GTK_WIDGET (self->build_log_panel));
+
 }
 
 static void
@@ -319,6 +330,12 @@ gbp_build_workbench_addin_load (IdeWorkbenchAddin *addin,
                             GTK_WIDGET (self->panel),
                             _("Build"), NULL);
 
+  pane = ide_layout_get_bottom_pane (IDE_LAYOUT (editor));
+  self->build_log_panel = g_object_new (GBP_TYPE_BUILD_LOG_PANEL, NULL);
+  ide_layout_pane_add_page (IDE_LAYOUT_PANE (pane),
+                            GTK_WIDGET (self->build_log_panel),
+                            _("Build Output"), NULL);
+
   gtk_widget_insert_action_group (GTK_WIDGET (workbench), "build-tools",
                                   G_ACTION_GROUP (self->actions));
 
diff --git a/plugins/build-tools/theme/shared.css b/plugins/build-tools/theme/shared.css
index a8a974e..793985d 100644
--- a/plugins/build-tools/theme/shared.css
+++ b/plugins/build-tools/theme/shared.css
@@ -34,3 +34,7 @@ buildpanel list row label.file {
 buildpanel list row image {
   opacity: 0.5;
 }
+
+buildlogpanel textview {
+  padding: 3px;
+}


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