Commit 17b7d331 authored by Christian Hergert's avatar Christian Hergert
Browse files

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.
parent bb8610f9
......@@ -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;
}
......@@ -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 */
<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>
......
......@@ -17,6 +17,7 @@
*/
#include <glib/gi18n.h>
#include <ide.h>
#include "egg-binding-group.h"
#include "egg-signal-group.h"
......@@ -265,6 +266,36 @@ gbp_build_panel_device_activated (GbpBuildPanel *self,
gtk_widget_hide (GTK_WIDGET (self->device_popover));
}
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)
{
......@@ -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",
......
......@@ -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 */
......@@ -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;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment