[gnome-builder/wip/chergert/layout] layout-view: add API to report errors



commit b332f523db979bdc16745470d2f08bae42dc36a2
Author: Christian Hergert <chergert redhat com>
Date:   Tue Jul 11 14:19:36 2017 -0700

    layout-view: add API to report errors
    
    This at least gives us a way to report errors to the user even
    if it isn't how we want to do things long term.
    
    This is still one downside to this, if set_failed() is set to
    TRUE, the we will obscure these errors. But that all needs more
    design anyway so I'm not going to stress about it yet.

 libide/layout/ide-layout-view.c |   58 +++++++++++++++++++++++++++++++++++++++
 libide/layout/ide-layout-view.h |    3 ++
 2 files changed, 61 insertions(+), 0 deletions(-)
---
diff --git a/libide/layout/ide-layout-view.c b/libide/layout/ide-layout-view.c
index 7e1e320..11efd9a 100644
--- a/libide/layout/ide-layout-view.c
+++ b/libide/layout/ide-layout-view.c
@@ -682,3 +682,61 @@ ide_layout_view_set_primary_color_fg (IdeLayoutView *self,
       !gdk_rgba_equal (&old, &priv->primary_color_fg))
     g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_PRIMARY_COLOR_FG]);
 }
+
+/**
+ * ide_layout_view_report_error:
+ * @self: a #IdeLayoutView
+ * @format: a printf-style format string
+ *
+ * This function reports an error to the user in the layout view.
+ *
+ * @format should be a printf-style format string followed by the
+ * arguments for the format.
+ *
+ * Since: 3.26
+ */
+void
+ide_layout_view_report_error (IdeLayoutView *self,
+                              const gchar   *format,
+                              ...)
+{
+  g_autofree gchar *message = NULL;
+  GtkInfoBar *infobar;
+  GtkWidget *content_area;
+  GtkLabel *label;
+  va_list args;
+
+  g_return_if_fail (IDE_IS_LAYOUT_VIEW (self));
+
+  va_start (args, format);
+  message = g_strdup_vprintf (format, args);
+  va_end (args);
+
+  infobar = g_object_new (GTK_TYPE_INFO_BAR,
+                          "message-type", GTK_MESSAGE_WARNING,
+                          "show-close-button", TRUE,
+                          "visible", TRUE,
+                          NULL);
+  g_signal_connect (infobar,
+                    "response",
+                    G_CALLBACK (gtk_widget_destroy),
+                    NULL);
+  g_signal_connect (infobar,
+                    "close",
+                    G_CALLBACK (gtk_widget_destroy),
+                    NULL);
+
+  label = g_object_new (GTK_TYPE_LABEL,
+                        "label", message,
+                        "visible", TRUE,
+                        "wrap", TRUE,
+                        "xalign", 0.0f,
+                        NULL);
+
+  content_area = gtk_info_bar_get_content_area (infobar);
+  gtk_container_add (GTK_CONTAINER (content_area), GTK_WIDGET (label));
+
+  gtk_container_add_with_properties (GTK_CONTAINER (self), GTK_WIDGET (infobar),
+                                     "position", 0,
+                                     NULL);
+}
diff --git a/libide/layout/ide-layout-view.h b/libide/layout/ide-layout-view.h
index 67bfe99..3c69143 100644
--- a/libide/layout/ide-layout-view.h
+++ b/libide/layout/ide-layout-view.h
@@ -86,5 +86,8 @@ void           ide_layout_view_agree_to_close_async  (IdeLayoutView        *self
 gboolean       ide_layout_view_agree_to_close_finish (IdeLayoutView        *self,
                                                       GAsyncResult         *result,
                                                       GError              **error);
+void           ide_layout_view_report_error          (IdeLayoutView        *self,
+                                                      const gchar          *format,
+                                                      ...) G_GNUC_PRINTF (2, 3);
 
 G_END_DECLS


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