[baobab/wip/vala] Use a GtkInfoBar to display errors.



commit 7928bd294e54dc955bc137b9d02bde0d81807df4
Author: Paolo Borelli <pborelli gnome org>
Date:   Sun Feb 5 14:07:58 2012 +0100

    Use a GtkInfoBar to display errors.

 data/baobab-main-window.ui |   64 ++++++++++++++++++++++++++++++++++++++++++-
 src/baobab-window.vala     |   22 +++++++++++----
 2 files changed, 78 insertions(+), 8 deletions(-)
---
diff --git a/data/baobab-main-window.ui b/data/baobab-main-window.ui
index 9c06782..35a4726 100644
--- a/data/baobab-main-window.ui
+++ b/data/baobab-main-window.ui
@@ -141,7 +141,67 @@
       <packing>
         <property name="left_attach">0</property>
         <property name="top_attach">0</property>
-        <property name="width">2</property>
+        <property name="width">1</property>
+        <property name="height">1</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkInfoBar" id="infobar">
+        <property name="visible">False</property>
+        <child internal-child="content_area">
+          <object class="GtkBox" id="infobar-content-area">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="border_width">8</property>
+            <property name="orientation">vertical</property>
+            <property name="spacing">16</property>
+            <child>
+              <object class="GtkLabel" id="infobar-primary-label">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="label" translatable="yes">label</property>
+                <property name="selectable">True</property>
+                <property name="use-markup">True</property>
+                <property name="halign">GTK_ALIGN_START</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="infobar-secondary-label">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="label" translatable="yes">label</property>
+                <property name="selectable">True</property>
+                <property name="use-markup">True</property>
+                <property name="halign">GTK_ALIGN_START</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+        </child>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="infobar-action-area">
+            <property name="visible">False</property>
+            <property name="can_focus">False</property>
+            <property name="border_width">5</property>
+            <property name="orientation">vertical</property>
+            <property name="spacing">6</property>
+            <property name="layout_style">end</property>
+          </object>
+        </child>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">1</property>
+        <property name="width">1</property>
         <property name="height">1</property>
       </packing>
     </child>
@@ -363,7 +423,7 @@
       <packing>
         <property name="left_attach">0</property>
         <property name="top_attach">2</property>
-        <property name="width">2</property>
+        <property name="width">1</property>
         <property name="height">1</property>
       </packing>
     </child>
diff --git a/src/baobab-window.vala b/src/baobab-window.vala
index 6f8a1bd..b2f6345 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -1,6 +1,9 @@
 namespace Baobab {
 	public class Window : Gtk.ApplicationWindow {
 		Settings ui_settings;
+		Gtk.InfoBar infobar;
+		Gtk.Label infobar_primary;
+		Gtk.Label infobar_secondary;
 		Gtk.TreeView treeview;
 		Gtk.Notebook chart_notebook;
 		Chart rings_chart;
@@ -77,6 +80,9 @@ namespace Baobab {
 			}
 
 			// Cache some objects from the builder.
+			infobar = builder.get_object ("infobar") as Gtk.InfoBar;
+			infobar_primary = builder.get_object ("infobar-primary-label") as Gtk.Label;
+			infobar_secondary = builder.get_object ("infobar-secondary-label") as Gtk.Label;
 			treeview = builder.get_object ("treeview") as Gtk.TreeView;
 			chart_notebook = builder.get_object ("chart-notebook") as Gtk.Notebook;
 			rings_chart = builder.get_object ("rings-chart") as Chart;
@@ -337,11 +343,14 @@ namespace Baobab {
 		}
 
 		void message (string primary_msg, string secondary_msg, Gtk.MessageType type) {
-			var dialog = new Gtk.MessageDialog (this, Gtk.DialogFlags.DESTROY_WITH_PARENT, type,
-			                                    Gtk.ButtonsType.OK, "%s", primary_msg);
-			dialog.format_secondary_text ("%s", secondary_msg);
-			dialog.run (); /* XXX kill it with fire */
-			dialog.destroy ();
+			infobar.message_type = type;
+			infobar_primary.set_label ("<b>%s</b>".printf (_(primary_msg)));
+			infobar_secondary.set_label ("<small>%s</small>".printf (_(secondary_msg)));
+			infobar.show ();
+		}
+
+		void clear_message () {
+			infobar.hide ();
 		}
 
 		void set_busy (bool busy) {
@@ -426,6 +435,7 @@ namespace Baobab {
 			                                    Scanner.Columns.PERCENT,
 			                                    Scanner.Columns.ELEMENTS, null);
 
+			clear_message ();
 			set_busy (true);
 			scanner.completed.connect(() => {
 				try {
@@ -435,7 +445,7 @@ namespace Baobab {
 					scanner.clear ();
 				} catch (Error e) {
 					var primary = _("Could not scan folder \"%s\"").printf (scanner.directory.get_parse_name ());
-					message (primary, e.message, Gtk.MessageType.INFO);
+					message (primary, e.message, Gtk.MessageType.WARNING);
 					scanner.clear ();
 				} finally {
 					set_busy (false);



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