[gnome-builder/wip/chergert/debugger] debugger: add debug log panel to debugger perspective



commit 8cd8f7be10f686458c75acdbaa4fc2a85179a8e3
Author: Christian Hergert <chergert redhat com>
Date:   Sun Mar 26 17:47:19 2017 -0700

    debugger: add debug log panel to debugger perspective

 libide/debugger/ide-debugger-perspective.c     |  131 +++++++++++++++++++++++-
 libide/debugger/ide-debugger-perspective.ui    |   27 +++++
 libide/debugger/ide-debugger-workbench-addin.c |    3 +
 3 files changed, 159 insertions(+), 2 deletions(-)
---
diff --git a/libide/debugger/ide-debugger-perspective.c b/libide/debugger/ide-debugger-perspective.c
index a2dd8e5..992fc3e 100644
--- a/libide/debugger/ide-debugger-perspective.c
+++ b/libide/debugger/ide-debugger-perspective.c
@@ -18,17 +18,29 @@
 
 #define G_LOG_DOMAIN "ide-debugger-perspective"
 
+#include <egg-signal-group.h>
 #include <glib/gi18n.h>
 
-#include "ide-debugger-perspective.h"
+#include "debugger/ide-debugger.h"
+#include "debugger/ide-debugger-perspective.h"
+#include "util/ide-pango.h"
 
 struct _IdeDebuggerPerspective
 {
-  IdeLayout parent_instance;
+  IdeLayout       parent_instance;
+
+  IdeDebugger    *debugger;
+  EggSignalGroup *debugger_signals;
+  GSettings      *terminal_settings;
+  GtkCssProvider *log_css;
+
+  GtkTextBuffer  *log_buffer;
+  GtkTextView    *log_text_view;
 };
 
 enum {
   PROP_0,
+  PROP_DEBUGGER,
   N_PROPS
 };
 
@@ -71,8 +83,79 @@ G_DEFINE_TYPE_EXTENDED (IdeDebuggerPerspective, ide_debugger_perspective, IDE_TY
 static GParamSpec *properties [N_PROPS];
 
 static void
+on_debugger_log (IdeDebuggerPerspective *self,
+                 const gchar            *message,
+                 IdeDebugger            *debugger)
+{
+  GtkTextIter iter;
+
+  g_assert (IDE_IS_DEBUGGER_PERSPECTIVE (self));
+  g_assert (IDE_IS_DEBUGGER (debugger));
+
+  gtk_text_buffer_get_end_iter (self->log_buffer, &iter);
+  gtk_text_buffer_insert (self->log_buffer, &iter, message, -1);
+  gtk_text_buffer_select_range (self->log_buffer, &iter, &iter);
+  gtk_text_view_scroll_to_iter (self->log_text_view, &iter, 0.0, FALSE, 1.0, 1.0);
+}
+
+static void
+ide_debugger_perspective_set_debugger (IdeDebuggerPerspective *self,
+                                       IdeDebugger            *debugger)
+{
+  g_return_if_fail (IDE_IS_DEBUGGER_PERSPECTIVE (self));
+  g_return_if_fail (!debugger || IDE_IS_DEBUGGER (debugger));
+
+  if (g_set_object (&self->debugger, debugger))
+    {
+      egg_signal_group_set_target (self->debugger_signals, debugger);
+      gtk_text_buffer_set_text (self->log_buffer, "", 0);
+      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_DEBUGGER]);
+    }
+}
+
+static void
+log_panel_changed_font_name (IdeDebuggerPerspective *self,
+                             const gchar            *key,
+                             GSettings              *settings)
+{
+  gchar *font_name;
+  PangoFontDescription *font_desc;
+
+  g_assert (IDE_IS_DEBUGGER_PERSPECTIVE (self));
+  g_assert (g_strcmp0 (key, "font-name") == 0);
+  g_assert (G_IS_SETTINGS (settings));
+
+  font_name = g_settings_get_string (settings, key);
+  font_desc = pango_font_description_from_string (font_name);
+
+  if (font_desc != NULL)
+    {
+      gchar *fragment;
+      gchar *css;
+
+      fragment = ide_pango_font_description_to_css (font_desc);
+      css = g_strdup_printf ("textview { %s }", fragment);
+
+      gtk_css_provider_load_from_data (self->log_css, css, -1, NULL);
+
+      pango_font_description_free (font_desc);
+      g_free (fragment);
+      g_free (css);
+    }
+
+  g_free (font_name);
+}
+
+static void
 ide_debugger_perspective_finalize (GObject *object)
 {
+  IdeDebuggerPerspective *self = (IdeDebuggerPerspective *)object;
+
+  g_clear_object (&self->debugger);
+  g_clear_object (&self->debugger_signals);
+  g_clear_object (&self->terminal_settings);
+  g_clear_object (&self->log_css);
+
   G_OBJECT_CLASS (ide_debugger_perspective_parent_class)->finalize (object);
 }
 
@@ -86,6 +169,10 @@ ide_debugger_perspective_get_property (GObject    *object,
 
   switch (prop_id)
     {
+    case PROP_DEBUGGER:
+      g_value_set_object (value, self->debugger);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -101,6 +188,10 @@ ide_debugger_perspective_set_property (GObject      *object,
 
   switch (prop_id)
     {
+    case PROP_DEBUGGER:
+      ide_debugger_perspective_set_debugger (self, g_value_get_object (value));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -116,11 +207,47 @@ ide_debugger_perspective_class_init (IdeDebuggerPerspectiveClass *klass)
   object_class->get_property = ide_debugger_perspective_get_property;
   object_class->set_property = ide_debugger_perspective_set_property;
 
+  properties [PROP_DEBUGGER] =
+    g_param_spec_object ("debugger",
+                         "Debugger",
+                         "The current debugger instance",
+                         IDE_TYPE_DEBUGGER,
+                         (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+
   gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/builder/ui/ide-debugger-perspective.ui");
+
+  gtk_widget_class_bind_template_child (widget_class, IdeDebuggerPerspective, log_text_view);
+  gtk_widget_class_bind_template_child (widget_class, IdeDebuggerPerspective, log_buffer);
 }
 
 static void
 ide_debugger_perspective_init (IdeDebuggerPerspective *self)
 {
+  GtkStyleContext *context;
+
   gtk_widget_init_template (GTK_WIDGET (self));
+
+  self->debugger_signals = egg_signal_group_new (IDE_TYPE_DEBUGGER);
+
+  egg_signal_group_connect_object (self->debugger_signals,
+                                   "log",
+                                   G_CALLBACK (on_debugger_log),
+                                   self,
+                                   G_CONNECT_SWAPPED);
+
+  self->log_css = gtk_css_provider_new ();
+  context = gtk_widget_get_style_context (GTK_WIDGET (self->log_text_view));
+  gtk_style_context_add_provider (context,
+                                  GTK_STYLE_PROVIDER (self->log_css),
+                                  GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+
+  self->terminal_settings = g_settings_new ("org.gnome.builder.terminal");
+  g_signal_connect_object (self->terminal_settings,
+                           "changed::font-name",
+                           G_CALLBACK (log_panel_changed_font_name),
+                           self,
+                           G_CONNECT_SWAPPED);
+  log_panel_changed_font_name (self, "font-name", self->terminal_settings);
 }
diff --git a/libide/debugger/ide-debugger-perspective.ui b/libide/debugger/ide-debugger-perspective.ui
index 6e5eedb..1dc644e 100644
--- a/libide/debugger/ide-debugger-perspective.ui
+++ b/libide/debugger/ide-debugger-perspective.ui
@@ -1,5 +1,32 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <template class="IdeDebuggerPerspective" parent="IdeLayout">
+    <child internal-child="bottom">
+      <object class="PnlDockBinEdge">
+        <property name="reveal-child">true</property>
+        <child>
+          <object class="PnlDockWidget">
+            <property name="title">Debug Log</property>
+            <property name="visible">true</property>
+            <child>
+              <object class="GtkScrolledWindow">
+                <property name="visible">true</property>
+                <child>
+                  <object class="GtkTextView" id="log_text_view">
+                    <property name="buffer">log_buffer</property>
+                    <property name="editable">false</property>
+                    <property name="monospace">true</property>
+                    <property name="vexpand">true</property>
+                    <property name="visible">true</property>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
   </template>
+  <object class="GtkTextBuffer" id="log_buffer">
+  </object>
 </interface>
diff --git a/libide/debugger/ide-debugger-workbench-addin.c b/libide/debugger/ide-debugger-workbench-addin.c
index ad5a94c..93d46aa 100644
--- a/libide/debugger/ide-debugger-workbench-addin.c
+++ b/libide/debugger/ide-debugger-workbench-addin.c
@@ -164,6 +164,9 @@ ide_debugger_workbench_addin_load (IdeWorkbenchAddin *addin,
   self->perspective = g_object_new (IDE_TYPE_DEBUGGER_PERSPECTIVE,
                                     "visible", TRUE,
                                     NULL);
+  g_object_bind_property (debug_manager, "debugger",
+                          self->perspective, "debugger",
+                          G_BINDING_SYNC_CREATE);
   ide_workbench_add_perspective (workbench, IDE_PERSPECTIVE (self->perspective));
 
   self->message = g_object_new (IDE_TYPE_WORKBENCH_MESSAGE,


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