[gnome-builder] genesis: use infobar for error messages



commit 24f43835a466ba340a83ed3820c8758d3332357e
Author: Christian Hergert <christian hergert me>
Date:   Wed Apr 27 14:53:18 2016 -0700

    genesis: use infobar for error messages
    
    We were using a dialog that was rather annoying for handling the error
    case when generating a project. Instead, we can use an info bar to let
    the user know the error.

 data/ui/ide-genesis-perspective.ui       |   59 +++++++++++++++++++++++-------
 libide/genesis/ide-genesis-perspective.c |   42 +++++++++++++---------
 2 files changed, 71 insertions(+), 30 deletions(-)
---
diff --git a/data/ui/ide-genesis-perspective.ui b/data/ui/ide-genesis-perspective.ui
index d1c2937..2dd4210 100644
--- a/data/ui/ide-genesis-perspective.ui
+++ b/data/ui/ide-genesis-perspective.ui
@@ -3,26 +3,59 @@
   <!-- interface-requires gtk+ 3.18 -->
   <template class="IdeGenesisPerspective" parent="GtkBin">
     <child>
-      <object class="GtkStack" id="stack">
-        <property name="transition-duration">250</property>
-        <property name="transition-type">crossfade</property>
-        <property name="expand">true</property>
+      <object class="GtkBox">
+        <property name="orientation">vertical</property>
         <property name="visible">true</property>
         <child>
-          <object class="EggBox" id="main_page">
-            <property name="halign">center</property>
-            <property name="width-request">550</property>
-            <property name="max-width-request">550</property>
-            <property name="valign">center</property>
+          <object class="GtkRevealer" id="info_bar_revealer">
+            <property name="reveal-child">false</property>
+            <property name="transition-type">slide-down</property>
             <property name="visible">true</property>
             <child>
-              <object class="GtkFrame">
+              <object class="GtkInfoBar" id="info_bar">
+                <property name="message-type">error</property>
+                <property name="show-close-button">true</property>
+                <property name="visible">true</property>
+                <child internal-child="content_area">
+                  <object class="GtkBox">
+                    <child>
+                      <object class="GtkLabel" id="info_bar_label">
+                        <property name="hexpand">true</property>
+                        <property name="label">Failure</property>
+                        <property name="visible">true</property>
+                        <property name="wrap">true</property>
+                        <property name="xalign">0</property>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkStack" id="stack">
+            <property name="transition-duration">250</property>
+            <property name="transition-type">crossfade</property>
+            <property name="expand">true</property>
+            <property name="visible">true</property>
+            <child>
+              <object class="EggBox" id="main_page">
+                <property name="halign">center</property>
+                <property name="width-request">550</property>
+                <property name="max-width-request">550</property>
+                <property name="valign">center</property>
                 <property name="visible">true</property>
                 <child>
-                  <object class="GtkListBox" id="list_box">
-                    <property name="hexpand">true</property>
-                    <property name="selection-mode">none</property>
+                  <object class="GtkFrame">
                     <property name="visible">true</property>
+                    <child>
+                      <object class="GtkListBox" id="list_box">
+                        <property name="hexpand">true</property>
+                        <property name="selection-mode">none</property>
+                        <property name="visible">true</property>
+                      </object>
+                    </child>
                   </object>
                 </child>
               </object>
diff --git a/libide/genesis/ide-genesis-perspective.c b/libide/genesis/ide-genesis-perspective.c
index 1d11c14..7b30fb9 100644
--- a/libide/genesis/ide-genesis-perspective.c
+++ b/libide/genesis/ide-genesis-perspective.c
@@ -35,6 +35,9 @@ struct _IdeGenesisPerspective
   IdeGenesisAddin  *current_addin;
 
   GtkHeaderBar     *header_bar;
+  GtkInfoBar       *info_bar;
+  GtkLabel         *info_bar_label;
+  GtkRevealer      *info_bar_revealer;
   GtkListBox       *list_box;
   GtkWidget        *main_page;
   GtkStack         *stack;
@@ -191,23 +194,8 @@ ide_genesis_perspective_run_cb (GObject      *object,
 
   if (!ide_genesis_addin_run_finish (addin, result, &error))
     {
-      GtkWidget *dialog;
-
-      dialog = gtk_message_dialog_new (NULL,
-                                       GTK_DIALOG_USE_HEADER_BAR,
-                                       GTK_MESSAGE_ERROR,
-                                       GTK_BUTTONS_CLOSE,
-                                       _("Failed to load the project"));
-      g_object_set (dialog,
-                    "secondary-text", error->message,
-                    NULL);
-
-      gtk_dialog_run (GTK_DIALOG (dialog));
-      gtk_widget_destroy (dialog);
-
-      /*
-       * TODO: Destroy workbench.
-       */
+      gtk_label_set_label (self->info_bar_label, error->message);
+      gtk_revealer_set_reveal_child (self->info_bar_revealer, TRUE);
     }
 }
 
@@ -226,6 +214,17 @@ ide_genesis_perspective_continue_clicked (IdeGenesisPerspective *self,
 }
 
 static void
+ide_genesis_perspective_info_bar_response (IdeGenesisPerspective *self,
+                                           int                    response_id,
+                                           GtkInfoBar            *info_bar)
+{
+  g_assert (IDE_IS_GENESIS_PERSPECTIVE (self));
+  g_assert (GTK_IS_INFO_BAR (info_bar));
+
+  gtk_revealer_set_reveal_child (self->info_bar_revealer, FALSE);
+}
+
+static void
 ide_genesis_perspective_constructed (GObject *object)
 {
   IdeGenesisPerspective *self = (IdeGenesisPerspective *)object;
@@ -281,6 +280,9 @@ ide_genesis_perspective_class_init (IdeGenesisPerspectiveClass *klass)
   gtk_widget_class_bind_template_child (widget_class, IdeGenesisPerspective, cancel_button);
   gtk_widget_class_bind_template_child (widget_class, IdeGenesisPerspective, continue_button);
   gtk_widget_class_bind_template_child (widget_class, IdeGenesisPerspective, header_bar);
+  gtk_widget_class_bind_template_child (widget_class, IdeGenesisPerspective, info_bar);
+  gtk_widget_class_bind_template_child (widget_class, IdeGenesisPerspective, info_bar_label);
+  gtk_widget_class_bind_template_child (widget_class, IdeGenesisPerspective, info_bar_revealer);
   gtk_widget_class_bind_template_child (widget_class, IdeGenesisPerspective, list_box);
   gtk_widget_class_bind_template_child (widget_class, IdeGenesisPerspective, main_page);
   gtk_widget_class_bind_template_child (widget_class, IdeGenesisPerspective, stack);
@@ -296,6 +298,12 @@ ide_genesis_perspective_init (IdeGenesisPerspective *self)
                            G_CALLBACK (ide_genesis_perspective_row_activated),
                            self,
                            G_CONNECT_SWAPPED);
+
+  g_signal_connect_object (self->info_bar,
+                           "response",
+                           G_CALLBACK (ide_genesis_perspective_info_bar_response),
+                           self,
+                           G_CONNECT_SWAPPED);
 }
 
 static gchar *


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