[gnome-builder/gnome-builder-3-18] editor: show warning in header when diagnostics are present



commit d9b2f68841a9af9d47e272e82da0c0258525e4d9
Author: Christian Hergert <christian hergert me>
Date:   Sun Oct 4 10:29:43 2015 -0700

    editor: show warning in header when diagnostics are present
    
    If the buffer indicates that there are diagnostics, show a warning button
    that may be clicked to jump to the next diagnostic.

 data/ui/gb-editor-view.ui           |   14 ++++++++++++++
 src/editor/gb-editor-view-private.h |    1 +
 src/editor/gb-editor-view.c         |   25 +++++++++++++++++++++++++
 3 files changed, 40 insertions(+), 0 deletions(-)
---
diff --git a/data/ui/gb-editor-view.ui b/data/ui/gb-editor-view.ui
index 3d77c8f..04f5e00 100644
--- a/data/ui/gb-editor-view.ui
+++ b/data/ui/gb-editor-view.ui
@@ -88,6 +88,20 @@
         <child internal-child="controls">
           <object class="GtkBox">
             <child>
+              <object class="GtkButton" id="warning_button">
+                <property name="visible">false</property>
+                <child>
+                  <object class="GtkImage">
+                    <property name="icon-name">dialog-warning-symbolic</property>
+                    <property name="visible">true</property>
+                    <style>
+                      <class name="dim-label"/>
+                    </style>
+                  </object>
+                </child>
+              </object>
+            </child>
+            <child>
               <object class="GtkSeparator">
                 <property name="margin-start">3</property>
                 <property name="margin-end">3</property>
diff --git a/src/editor/gb-editor-view-private.h b/src/editor/gb-editor-view-private.h
index ee90953..9222212 100644
--- a/src/editor/gb-editor-view-private.h
+++ b/src/editor/gb-editor-view-private.h
@@ -51,6 +51,7 @@ struct _GbEditorView
   GbEditorTweakWidget *tweak_widget;
   GtkMenuButton       *goto_line_button;
   GbSimplePopover     *goto_line_popover;
+  GtkButton           *warning_button;
 };
 
 G_END_DECLS
diff --git a/src/editor/gb-editor-view.c b/src/editor/gb-editor-view.c
index 29fbf29..f2fba8d 100644
--- a/src/editor/gb-editor-view.c
+++ b/src/editor/gb-editor-view.c
@@ -394,6 +394,10 @@ gb_editor_view_set_document (GbEditorView     *self,
 
       g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_DOCUMENT]);
 
+      g_object_bind_property (document, "has-diagnostics",
+                              self->warning_button, "visible",
+                              G_BINDING_SYNC_CREATE);
+
       gb_editor_view__buffer_notify_language (self, NULL, document);
       gb_editor_view__buffer_notify_title (self, NULL, IDE_BUFFER (document));
 
@@ -720,6 +724,20 @@ gb_editor_view__extension_removed (PeasExtensionSet  *set,
 }
 
 static void
+gb_editor_view_warning_button_clicked (GbEditorView *self,
+                                       GtkButton    *button)
+{
+  GbEditorFrame *frame;
+
+  g_assert (GB_IS_EDITOR_VIEW (self));
+  g_assert (GTK_IS_BUTTON (button));
+
+  frame = gb_editor_view_get_last_focused (self);
+  gtk_widget_grab_focus (GTK_WIDGET (frame));
+  g_signal_emit_by_name (frame->source_view, "move-error", GTK_DIR_DOWN);
+}
+
+static void
 gb_editor_view_constructed (GObject *object)
 {
   GbEditorView *self = (GbEditorView *)object;
@@ -860,6 +878,7 @@ gb_editor_view_class_init (GbEditorViewClass *klass)
   GB_WIDGET_CLASS_BIND (klass, GbEditorView, tweak_widget);
   GB_WIDGET_CLASS_BIND (klass, GbEditorView, goto_line_button);
   GB_WIDGET_CLASS_BIND (klass, GbEditorView, goto_line_popover);
+  GB_WIDGET_CLASS_BIND (klass, GbEditorView, warning_button);
 
   g_type_ensure (GB_TYPE_EDITOR_FRAME);
   g_type_ensure (GB_TYPE_EDITOR_TWEAK_WIDGET);
@@ -921,4 +940,10 @@ gb_editor_view_init (GbEditorView *self)
                            G_CALLBACK (gb_editor_view_goto_line_changed),
                            self,
                            G_CONNECT_SWAPPED);
+
+  g_signal_connect_object (self->warning_button,
+                           "clicked",
+                           G_CALLBACK (gb_editor_view_warning_button_clicked),
+                           self,
+                           G_CONNECT_SWAPPED);
 }


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