[gnome-builder] build-panel: add diagnostics list and jump to error



commit 17b7d3315d5f61814548221ef65a9d403dfb31ed
Author: Christian Hergert <chergert redhat com>
Date:   Fri Dec 18 04:01:44 2015 -0800

    build-panel: add diagnostics list and jump to error
    
    When a diagnostic is added, we add it to our list. Also, when clicking on
    a row, jump to that location in the editor.

 plugins/build-tools/gbp-build-panel-row.c  |   50 ++++++++++++++++++++++++----
 plugins/build-tools/gbp-build-panel-row.h  |   10 ++++-
 plugins/build-tools/gbp-build-panel-row.ui |   26 +++++++++++++-
 plugins/build-tools/gbp-build-panel.c      |   37 ++++++++++++++++++++
 plugins/build-tools/gbp-build-panel.h      |    5 ++-
 plugins/build-tools/theme/shared.css       |   17 +++++++++
 6 files changed, 133 insertions(+), 12 deletions(-)
---
diff --git a/plugins/build-tools/gbp-build-panel-row.c b/plugins/build-tools/gbp-build-panel-row.c
index 4fffa0c..b194471 100644
--- a/plugins/build-tools/gbp-build-panel-row.c
+++ b/plugins/build-tools/gbp-build-panel-row.c
@@ -16,6 +16,9 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#define G_LOG_DOMAIN "build-panel"
+
+#include <glib/gi18n.h>
 #include <ide.h>
 
 #include "gbp-build-panel-row.h"
@@ -44,14 +47,39 @@ static void
 gbp_build_panel_row_set_diagnostic (GbpBuildPanelRow *self,
                                     IdeDiagnostic    *diagnostic)
 {
-  gchar *text;
-
   g_return_if_fail (GBP_IS_BUILD_PANEL_ROW (self));
-  g_return_if_fail (diagnostic != NULL);
 
-  text = ide_diagnostic_get_text_for_display (diagnostic);
-  gtk_label_set_label (self->message_label, text);
-  g_free (text);
+  if ((diagnostic != NULL) && (self->diagnostic != diagnostic))
+    {
+      IdeSourceLocation *location;
+      const gchar *path = NULL;
+      IdeFile *file;
+      const gchar *text;
+
+      self->diagnostic = ide_diagnostic_ref (diagnostic);
+
+      if ((location = ide_diagnostic_get_location (diagnostic)) &&
+          (file = ide_source_location_get_file (location)))
+        path = ide_file_get_path (file);
+
+      if (path)
+        gtk_label_set_label (self->file_label, path);
+      else
+        gtk_label_set_label (self->file_label, _("Unknown file"));
+
+      text = ide_diagnostic_get_text (diagnostic);
+      gtk_label_set_label (self->message_label, text);
+    }
+}
+
+static void
+gbp_build_panel_row_finalize (GObject *object)
+{
+  GbpBuildPanelRow *self = (GbpBuildPanelRow *)object;
+
+  g_clear_pointer (&self->diagnostic, ide_diagnostic_unref);
+
+  G_OBJECT_CLASS (gbp_build_panel_row_parent_class)->finalize (object);
 }
 
 static void
@@ -98,6 +126,7 @@ gbp_build_panel_row_class_init (GbpBuildPanelRowClass *klass)
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
+  object_class->finalize = gbp_build_panel_row_finalize;
   object_class->get_property = gbp_build_panel_row_get_property;
   object_class->set_property = gbp_build_panel_row_set_property;
 
@@ -111,7 +140,6 @@ gbp_build_panel_row_class_init (GbpBuildPanelRowClass *klass)
   g_object_class_install_properties (object_class, LAST_PROP, properties);
 
   gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/builder/plugins/build-tools-plugin/gbp-build-panel-row.ui");
-  gtk_widget_class_set_css_name (widget_class, "buildpanelrow");
   gtk_widget_class_bind_template_child (widget_class, GbpBuildPanelRow, file_label);
   gtk_widget_class_bind_template_child (widget_class, GbpBuildPanelRow, message_label);
 }
@@ -121,3 +149,11 @@ gbp_build_panel_row_init (GbpBuildPanelRow *self)
 {
   gtk_widget_init_template (GTK_WIDGET (self));
 }
+
+IdeDiagnostic *
+gbp_build_panel_row_get_diagnostic (GbpBuildPanelRow *self)
+{
+  g_return_val_if_fail (GBP_IS_BUILD_PANEL_ROW (self), NULL);
+
+  return self->diagnostic;
+}
diff --git a/plugins/build-tools/gbp-build-panel-row.h b/plugins/build-tools/gbp-build-panel-row.h
index afd2d9b..fe83240 100644
--- a/plugins/build-tools/gbp-build-panel-row.h
+++ b/plugins/build-tools/gbp-build-panel-row.h
@@ -16,14 +16,20 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GBP_BUILD_PANEL_ROW_H
+#define GBP_BUILD_PANEL_ROW_H
 
 #include <gtk/gtk.h>
+#include <ide.h>
 
 G_BEGIN_DECLS
 
 #define GBP_TYPE_BUILD_PANEL_ROW (gbp_build_panel_row_get_type())
 
-G_DECLARE_FINAL_TYPE (GbpBuildPanelRow, gbp_build_panel_row, GBP, BUILD_PANEL_ROW, GObject)
+G_DECLARE_FINAL_TYPE (GbpBuildPanelRow, gbp_build_panel_row, GBP, BUILD_PANEL_ROW, GtkListBoxRow)
+
+IdeDiagnostic *gbp_build_panel_row_get_diagnostic (GbpBuildPanelRow *self);
 
 G_END_DECLS
+
+#endif /* GBP_BUILD_PANEL_ROW_H */
diff --git a/plugins/build-tools/gbp-build-panel-row.ui b/plugins/build-tools/gbp-build-panel-row.ui
index 5079030..2c650ca 100644
--- a/plugins/build-tools/gbp-build-panel-row.ui
+++ b/plugins/build-tools/gbp-build-panel-row.ui
@@ -1,20 +1,42 @@
 <interface>
   <template class="GbpBuildPanelRow" parent="GtkListBoxRow">
     <child>
-      <object class="GtkBox">
-        <property name="orientation">vertical</property>
+      <object class="GtkGrid">
         <property name="visible">true</property>
         <child>
+          <object class="GtkImage" id="image">
+            <property name="icon-name">dialog-warning-symbolic</property>
+            <property name="visible">true</property>
+            <property name="yalign">0.5</property>
+            <property name="xalign">0.5</property>
+            <property name="vexpand">true</property>
+            <property name="xpad">6</property>
+          </object>
+          <packing>
+            <property name="height">2</property>
+          </packing>
+        </child>
+        <child>
           <object class="GtkLabel" id="file_label">
             <property name="visible">true</property>
             <property name="xalign">0.0</property>
+            <style>
+              <class name="file"/>
+            </style>
           </object>
+          <packing>
+            <property name="left-attach">1</property>
+          </packing>
         </child>
         <child>
           <object class="GtkLabel" id="message_label">
             <property name="visible">true</property>
             <property name="xalign">0.0</property>
           </object>
+          <packing>
+            <property name="left-attach">1</property>
+            <property name="top-attach">1</property>
+          </packing>
         </child>
       </object>
     </child>
diff --git a/plugins/build-tools/gbp-build-panel.c b/plugins/build-tools/gbp-build-panel.c
index b9e689f..c10b4ce 100644
--- a/plugins/build-tools/gbp-build-panel.c
+++ b/plugins/build-tools/gbp-build-panel.c
@@ -17,6 +17,7 @@
  */
 
 #include <glib/gi18n.h>
+#include <ide.h>
 
 #include "egg-binding-group.h"
 #include "egg-signal-group.h"
@@ -266,6 +267,36 @@ gbp_build_panel_device_activated (GbpBuildPanel *self,
 }
 
 static void
+gbp_build_panel_diagnostic_activated (GbpBuildPanel *self,
+                                      GtkListBoxRow *row,
+                                      GtkListBox    *list_box)
+{
+  g_autoptr(IdeUri) uri = NULL;
+  IdeDiagnostic *diagnostic;
+  IdeSourceLocation *loc;
+  IdeWorkbench *workbench;
+
+  g_assert (GBP_IS_BUILD_PANEL (self));
+  g_assert (GTK_IS_LIST_BOX_ROW (row));
+  g_assert (GTK_IS_LIST_BOX (list_box));
+
+  diagnostic = gbp_build_panel_row_get_diagnostic (GBP_BUILD_PANEL_ROW (row));
+  if (diagnostic == NULL)
+    return;
+
+  loc = ide_diagnostic_get_location (diagnostic);
+  if (loc == NULL)
+    return;
+
+  uri = ide_source_location_get_uri (loc);
+  if (uri == NULL)
+    return;
+
+  workbench = ide_widget_get_workbench (GTK_WIDGET (self));
+  ide_workbench_open_uri_async (workbench, uri, "editor", NULL, NULL, NULL);
+}
+
+static void
 gbp_build_panel_destroy (GtkWidget *widget)
 {
   GbpBuildPanel *self = (GbpBuildPanel *)widget;
@@ -401,6 +432,12 @@ gbp_build_panel_init (GbpBuildPanel *self)
                            self,
                            G_CONNECT_SWAPPED);
 
+  g_signal_connect_object (self->diagnostics,
+                           "row-activated",
+                           G_CALLBACK (gbp_build_panel_diagnostic_activated),
+                           self,
+                           G_CONNECT_SWAPPED);
+
   self->bindings = egg_binding_group_new ();
 
   egg_binding_group_bind (self->bindings, "mode",
diff --git a/plugins/build-tools/gbp-build-panel.h b/plugins/build-tools/gbp-build-panel.h
index e7a9b5f..5d2f8bc 100644
--- a/plugins/build-tools/gbp-build-panel.h
+++ b/plugins/build-tools/gbp-build-panel.h
@@ -16,7 +16,8 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GBP_BUILD_PANEL_H
+#define GBP_BUILD_PANEL_H
 
 #include <gtk/gtk.h>
 #include <ide.h>
@@ -33,3 +34,5 @@ void gbp_build_panel_add_error  (GbpBuildPanel  *self,
                                  const gchar    *message);
 
 G_END_DECLS
+
+#endif /* GBP_BUILD_PANEL_H */
diff --git a/plugins/build-tools/theme/shared.css b/plugins/build-tools/theme/shared.css
index e5f0e08..a8a974e 100644
--- a/plugins/build-tools/theme/shared.css
+++ b/plugins/build-tools/theme/shared.css
@@ -17,3 +17,20 @@ list.buildpanel row {
 list.buildpanel row:last-child {
   border-bottom: none;
 }
+
+buildpanel list row {
+  padding: 6px;
+  border-bottom: 1px solid alpha(@borders, 0.4);
+}
+
+buildpanel list row:last-child {
+  border-bottom: none;
+}
+
+buildpanel list row label.file {
+  opacity: 0.5;
+}
+
+buildpanel list row image {
+  opacity: 0.5;
+}


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