[gnome-builder] build-tools: add headers above diagnostics of different types



commit 6b2f330993b7f7fabd582d96afb856c7cd6ddd73
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jun 27 00:54:00 2016 -0700

    build-tools: add headers above diagnostics of different types

 plugins/build-tools/gbp-build-panel-row.c |   10 ++++
 plugins/build-tools/gbp-build-panel-row.h |    2 +
 plugins/build-tools/gbp-build-panel.c     |   66 +++++++++++++++++++++++++++++
 3 files changed, 78 insertions(+), 0 deletions(-)
---
diff --git a/plugins/build-tools/gbp-build-panel-row.c b/plugins/build-tools/gbp-build-panel-row.c
index 394f4f3..5398a61 100644
--- a/plugins/build-tools/gbp-build-panel-row.c
+++ b/plugins/build-tools/gbp-build-panel-row.c
@@ -41,6 +41,16 @@ enum {
 
 static GParamSpec *properties [LAST_PROP];
 
+gint
+gbp_build_panel_row_compare (gconstpointer a,
+                             gconstpointer b)
+{
+  const GbpBuildPanelRow *rowa = a;
+  const GbpBuildPanelRow *rowb = b;
+
+  return ide_diagnostic_compare (rowa->diagnostic, rowb->diagnostic);
+}
+
 static void
 gbp_build_panel_row_set_diagnostic (GbpBuildPanelRow *self,
                                     IdeDiagnostic    *diagnostic)
diff --git a/plugins/build-tools/gbp-build-panel-row.h b/plugins/build-tools/gbp-build-panel-row.h
index fe83240..4a77974 100644
--- a/plugins/build-tools/gbp-build-panel-row.h
+++ b/plugins/build-tools/gbp-build-panel-row.h
@@ -29,6 +29,8 @@ G_BEGIN_DECLS
 G_DECLARE_FINAL_TYPE (GbpBuildPanelRow, gbp_build_panel_row, GBP, BUILD_PANEL_ROW, GtkListBoxRow)
 
 IdeDiagnostic *gbp_build_panel_row_get_diagnostic (GbpBuildPanelRow *self);
+gint           gbp_build_panel_row_compare        (gconstpointer     a,
+                                                   gconstpointer     b);
 
 G_END_DECLS
 
diff --git a/plugins/build-tools/gbp-build-panel.c b/plugins/build-tools/gbp-build-panel.c
index da2b113..7ca97a9 100644
--- a/plugins/build-tools/gbp-build-panel.c
+++ b/plugins/build-tools/gbp-build-panel.c
@@ -98,6 +98,8 @@ gbp_build_panel_diagnostic (GbpBuildPanel  *self,
                       "visible", TRUE,
                       NULL);
   gtk_container_add (GTK_CONTAINER (self->diagnostics), row);
+  gtk_list_box_invalidate_sort (self->diagnostics);
+  gtk_list_box_invalidate_headers (self->diagnostics);
 }
 
 static void
@@ -237,6 +239,65 @@ gbp_build_panel_diagnostic_activated (GbpBuildPanel *self,
   ide_workbench_open_uri_async (workbench, uri, "editor", flags, NULL, NULL, NULL);
 }
 
+static gchar *
+get_severity_title (IdeDiagnosticSeverity severity)
+{
+  switch ((int)severity)
+    {
+    case IDE_DIAGNOSTIC_ERROR:
+      return _("Errors");
+
+    case IDE_DIAGNOSTIC_WARNING:
+      return _("Warnings");
+
+    case IDE_DIAGNOSTIC_NOTE:
+      return _("Notes");
+
+    default:
+      return NULL;
+    }
+}
+
+static void
+update_header_func (GtkListBoxRow *row,
+                    GtkListBoxRow *before,
+                    gpointer       user_data)
+{
+  IdeDiagnostic *diag;
+  IdeDiagnostic *last = NULL;
+  IdeDiagnosticSeverity severitya = 0;
+  IdeDiagnosticSeverity severityb = 0;
+
+  g_assert (GTK_IS_LIST_BOX_ROW (row));
+  g_assert (!before || GTK_IS_LIST_BOX_ROW (before));
+
+  diag = gbp_build_panel_row_get_diagnostic (GBP_BUILD_PANEL_ROW (row));
+  severitya = ide_diagnostic_get_severity (diag);
+
+  if (before != NULL)
+    {
+      last = gbp_build_panel_row_get_diagnostic (GBP_BUILD_PANEL_ROW (before));
+      severityb = ide_diagnostic_get_severity (last);
+    }
+
+  if (last == NULL || severitya != severityb)
+    {
+      const gchar *str = get_severity_title (severitya);
+
+      if (str != NULL)
+        {
+          GtkWidget *widget;
+
+          widget = g_object_new (GTK_TYPE_LABEL,
+                                 "label", str,
+                                 "visible", TRUE,
+                                 "xalign", 0.0f,
+                                 NULL);
+          gtk_list_box_row_set_header (row, widget);
+        }
+    }
+}
+
 static void
 gbp_build_panel_destroy (GtkWidget *widget)
 {
@@ -346,6 +407,11 @@ gbp_build_panel_init (GbpBuildPanel *self)
                                    self,
                                    G_CONNECT_SWAPPED);
 
+  gtk_list_box_set_sort_func (self->diagnostics,
+                              (GtkListBoxSortFunc)gbp_build_panel_row_compare,
+                              NULL, NULL);
+  gtk_list_box_set_header_func (self->diagnostics, update_header_func, NULL, NULL);
+
   g_signal_connect_object (self->diagnostics,
                            "row-activated",
                            G_CALLBACK (gbp_build_panel_diagnostic_activated),


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