[gnome-builder] messages: add a messages panel, hidden by default



commit e9c2c9a2357807abf74712c1fa13147dc05e964f
Author: Christian Hergert <chergert redhat com>
Date:   Fri Jan 5 20:17:29 2018 -0800

    messages: add a messages panel, hidden by default
    
    This adds a new utilities panel that will show log messages
    from Builder and it's plugins. Not much currently proxies
    messages to the context yet, but we'll improve that going
    forward so that they show up here.

 src/plugins/meson.build                          |    1 +
 src/plugins/messages/gbp-messages-editor-addin.c |   86 ++++++++++++++++++
 src/plugins/messages/gbp-messages-editor-addin.h |   29 ++++++
 src/plugins/messages/gbp-messages-panel.c        |  102 ++++++++++++++++++++++
 src/plugins/messages/gbp-messages-panel.h        |   29 ++++++
 src/plugins/messages/gbp-messages-panel.ui       |   29 ++++++
 src/plugins/messages/gbp-messages-plugin.c       |   30 +++++++
 src/plugins/messages/meson.build                 |   16 ++++
 src/plugins/messages/messages.gresource.xml      |    9 ++
 src/plugins/messages/messages.plugin             |   10 ++
 10 files changed, 341 insertions(+), 0 deletions(-)
---
diff --git a/src/plugins/meson.build b/src/plugins/meson.build
index dac8ef7..2c63078 100644
--- a/src/plugins/meson.build
+++ b/src/plugins/meson.build
@@ -43,6 +43,7 @@ subdir('jhbuild')
 subdir('make')
 subdir('meson')
 subdir('meson-templates')
+subdir('messages')
 subdir('mingw')
 subdir('mono')
 subdir('newcomers')
diff --git a/src/plugins/messages/gbp-messages-editor-addin.c 
b/src/plugins/messages/gbp-messages-editor-addin.c
new file mode 100644
index 0000000..f7ca618
--- /dev/null
+++ b/src/plugins/messages/gbp-messages-editor-addin.c
@@ -0,0 +1,86 @@
+/* gbp-messages-editor-addin.c
+ *
+ * Copyright © 2018 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/>.
+ */
+
+#define G_LOG_DOMAIN "gbp-messages-editor-addin"
+
+#include <ide.h>
+
+#include "gbp-messages-editor-addin.h"
+#include "gbp-messages-panel.h"
+
+struct _GbpMessagesEditorAddin
+{
+  GObject           parent_instance;
+  GbpMessagesPanel *panel;
+};
+
+static void
+gbp_messages_editor_addin_load (IdeEditorAddin       *addin,
+                                IdeEditorPerspective *editor)
+{
+  GbpMessagesEditorAddin *self = (GbpMessagesEditorAddin *)addin;
+  GtkWidget *utilities;
+
+  g_assert (GBP_IS_MESSAGES_EDITOR_ADDIN (self));
+  g_assert (IDE_IS_EDITOR_PERSPECTIVE (editor));
+
+  utilities = ide_editor_perspective_get_utilities (editor);
+
+  /* hidden by default */
+  self->panel = g_object_new (GBP_TYPE_MESSAGES_PANEL, NULL);
+  g_signal_connect (self->panel,
+                    "destroy",
+                    G_CALLBACK (gtk_widget_destroyed),
+                    &self->panel);
+  gtk_container_add (GTK_CONTAINER (utilities), GTK_WIDGET (self->panel));
+}
+
+static void
+gbp_messages_editor_addin_unload (IdeEditorAddin       *addin,
+                                  IdeEditorPerspective *editor)
+{
+  GbpMessagesEditorAddin *self = (GbpMessagesEditorAddin *)addin;
+
+  g_assert (GBP_IS_MESSAGES_EDITOR_ADDIN (self));
+  g_assert (IDE_IS_EDITOR_PERSPECTIVE (editor));
+
+  if (self->panel != NULL)
+    gtk_widget_destroy (GTK_WIDGET (self->panel));
+
+  g_assert (self->panel == NULL);
+}
+
+static void
+editor_addin_iface_init (IdeEditorAddinInterface *iface)
+{
+  iface->load = gbp_messages_editor_addin_load;
+  iface->unload = gbp_messages_editor_addin_unload;
+}
+
+G_DEFINE_TYPE_WITH_CODE (GbpMessagesEditorAddin, gbp_messages_editor_addin, G_TYPE_OBJECT,
+                         G_IMPLEMENT_INTERFACE (IDE_TYPE_EDITOR_ADDIN, editor_addin_iface_init))
+
+static void
+gbp_messages_editor_addin_class_init (GbpMessagesEditorAddinClass *klass)
+{
+}
+
+static void
+gbp_messages_editor_addin_init (GbpMessagesEditorAddin *self)
+{
+}
diff --git a/src/plugins/messages/gbp-messages-editor-addin.h 
b/src/plugins/messages/gbp-messages-editor-addin.h
new file mode 100644
index 0000000..5693e6d
--- /dev/null
+++ b/src/plugins/messages/gbp-messages-editor-addin.h
@@ -0,0 +1,29 @@
+/* gbp-messages-editor-addin.h
+ *
+ * Copyright © 2018 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/>.
+ */
+
+#pragma once
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_MESSAGES_EDITOR_ADDIN (gbp_messages_editor_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpMessagesEditorAddin, gbp_messages_editor_addin, GBP, MESSAGES_EDITOR_ADDIN, GObject)
+
+G_END_DECLS
diff --git a/src/plugins/messages/gbp-messages-panel.c b/src/plugins/messages/gbp-messages-panel.c
new file mode 100644
index 0000000..fbfa7fa
--- /dev/null
+++ b/src/plugins/messages/gbp-messages-panel.c
@@ -0,0 +1,102 @@
+/* gbp-messages-panel.c
+ *
+ * Copyright © 2018 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/>.
+ */
+
+#define G_LOG_DOMAIN "gbp-messages-panel"
+
+#include <ide.h>
+
+#include "gbp-messages-panel.h"
+
+struct _GbpMessagesPanel
+{
+  DzlDockWidget parent_instance;
+
+  GtkScrollbar *scrollbar;
+  IdeTerminal  *terminal;
+};
+
+G_DEFINE_TYPE (GbpMessagesPanel, gbp_messages_panel, DZL_TYPE_DOCK_WIDGET)
+
+static void
+gbp_messages_panel_log_cb (GbpMessagesPanel *self,
+                           GLogLevelFlags    log_level,
+                           const gchar      *message,
+                           IdeContext       *context)
+{
+  g_assert (GBP_IS_MESSAGES_PANEL (self));
+  g_assert (message != NULL);
+  g_assert (IDE_IS_CONTEXT (context));
+
+  vte_terminal_feed (VTE_TERMINAL (self->terminal), message, -1);
+  vte_terminal_feed (VTE_TERMINAL (self->terminal), "\r\n", 2);
+  gtk_widget_show (GTK_WIDGET (self));
+}
+
+#if 0
+static gboolean
+do_log (gpointer data)
+{
+  ide_context_warning (data, "(some log message here)");
+  return G_SOURCE_CONTINUE;
+}
+#endif
+
+static void
+gbp_messages_panel_set_context (GtkWidget  *widget,
+                                IdeContext *context)
+{
+  GbpMessagesPanel *self = (GbpMessagesPanel *)widget;
+
+  g_assert (GBP_IS_MESSAGES_PANEL (self));
+  g_assert (!context || IDE_IS_CONTEXT (context));
+
+#if 0
+  g_timeout_add (1000, do_log, context);
+#endif
+
+  if (context != NULL)
+    g_signal_connect_object (context,
+                             "log",
+                             G_CALLBACK (gbp_messages_panel_log_cb),
+                             self,
+                             G_CONNECT_SWAPPED);
+}
+
+static void
+gbp_messages_panel_class_init (GbpMessagesPanelClass *klass)
+{
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  gtk_widget_class_set_template_from_resource (widget_class,
+                                               
"/org/gnome/builder/plugins/messages-plugin/gbp-messages-panel.ui");
+  gtk_widget_class_bind_template_child (widget_class, GbpMessagesPanel, scrollbar);
+  gtk_widget_class_bind_template_child (widget_class, GbpMessagesPanel, terminal);
+}
+
+static void
+gbp_messages_panel_init (GbpMessagesPanel *self)
+{
+  GtkAdjustment *vadj;
+
+  gtk_widget_init_template (GTK_WIDGET (self));
+
+  ide_widget_set_context_handler (GTK_WIDGET (self), gbp_messages_panel_set_context);
+
+  vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (self->terminal));
+  gtk_range_set_adjustment (GTK_RANGE (self->scrollbar), vadj);
+}
diff --git a/src/plugins/messages/gbp-messages-panel.h b/src/plugins/messages/gbp-messages-panel.h
new file mode 100644
index 0000000..e90a8b2
--- /dev/null
+++ b/src/plugins/messages/gbp-messages-panel.h
@@ -0,0 +1,29 @@
+/* gbp-messages-panel.h
+ *
+ * Copyright © 2018 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/>.
+ */
+
+#pragma once
+
+#include <dazzle.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_MESSAGES_PANEL (gbp_messages_panel_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpMessagesPanel, gbp_messages_panel, GBP, MESSAGES_PANEL, DzlDockWidget)
+
+G_END_DECLS
diff --git a/src/plugins/messages/gbp-messages-panel.ui b/src/plugins/messages/gbp-messages-panel.ui
new file mode 100644
index 0000000..d643f93
--- /dev/null
+++ b/src/plugins/messages/gbp-messages-panel.ui
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="GbpMessagesPanel" parent="DzlDockWidget">
+    <property name="icon-name">dialog-information-symbolic</property>
+    <property name="title" translatable="yes">Messages</property>
+    <child>
+      <object class="GtkBox" id="box">
+        <property name="hexpand">true</property>
+        <property name="orientation">horizontal</property>
+        <property name="visible">true</property>
+        <child>
+          <object class="IdeTerminal" id="terminal">
+            <property name="hexpand">true</property>
+            <property name="scrollback-lines">1000</property>
+            <property name="scroll-on-output">false</property>
+            <property name="visible">true</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkScrollbar" id="scrollbar">
+            <property name="hexpand">false</property>
+            <property name="orientation">vertical</property>
+            <property name="visible">true</property>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/plugins/messages/gbp-messages-plugin.c b/src/plugins/messages/gbp-messages-plugin.c
new file mode 100644
index 0000000..5169d9b
--- /dev/null
+++ b/src/plugins/messages/gbp-messages-plugin.c
@@ -0,0 +1,30 @@
+/* gbp-messages-plugin.c
+ *
+ * Copyright © 2018 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 <libpeas/peas.h>
+#include <ide.h>
+
+#include "gbp-messages-editor-addin.h"
+
+void
+gbp_messages_register_types (PeasObjectModule *module)
+{
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_EDITOR_ADDIN,
+                                              GBP_TYPE_MESSAGES_EDITOR_ADDIN);
+}
diff --git a/src/plugins/messages/meson.build b/src/plugins/messages/meson.build
new file mode 100644
index 0000000..96afadb
--- /dev/null
+++ b/src/plugins/messages/meson.build
@@ -0,0 +1,16 @@
+messages_resources = gnome.compile_resources(
+  'messages-resources',
+  'messages.gresource.xml',
+  c_name: 'gbp_messages',
+)
+
+messages_sources = [
+  'gbp-messages-editor-addin.c',
+  'gbp-messages-editor-addin.h',
+  'gbp-messages-panel.c',
+  'gbp-messages-panel.h',
+  'gbp-messages-plugin.c',
+]
+
+gnome_builder_plugins_sources += files(messages_sources)
+gnome_builder_plugins_sources += messages_resources[0]
diff --git a/src/plugins/messages/messages.gresource.xml b/src/plugins/messages/messages.gresource.xml
new file mode 100644
index 0000000..d32baf5
--- /dev/null
+++ b/src/plugins/messages/messages.gresource.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/builder/plugins">
+    <file>messages.plugin</file>
+  </gresource>
+  <gresource prefix="/org/gnome/builder/plugins/messages-plugin">
+    <file preprocess="xml-stripblanks">gbp-messages-panel.ui</file>
+  </gresource>
+</gresources>
diff --git a/src/plugins/messages/messages.plugin b/src/plugins/messages/messages.plugin
new file mode 100644
index 0000000..438ff36
--- /dev/null
+++ b/src/plugins/messages/messages.plugin
@@ -0,0 +1,10 @@
+[Plugin]
+Module=messages-plugin
+Name=Internal Logging
+Description=Show internal warning logs
+Authors=Christian Hergert <christian hergert me>
+Copyright=Copyright © 2018 Christian Hergert
+Depends=editor;
+Hidden=true
+Builtin=true
+Embedded=gbp_messages_register_types


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