[geary/mjog/info-bar-cleanup: 46/50] Components.InfoBar: New subclass of Gtk InfoBars with labels



commit 88516377cae97cfbaff745abacab88641f472766
Author: Michael Gratton <mike vee net>
Date:   Mon Mar 16 12:06:45 2020 +1100

    Components.InfoBar: New subclass of Gtk InfoBars with labels

 po/POTFILES.in                                 |  1 +
 src/client/components/components-info-bar.vala | 75 ++++++++++++++++++++++++++
 src/client/meson.build                         |  1 +
 3 files changed, 77 insertions(+)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 9ece7de1..4db962c4 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -37,6 +37,7 @@ src/client/components/components-attachment-pane.vala
 src/client/components/components-entry-undo.vala
 src/client/components/components-in-app-notification.vala
 src/client/components/components-info-bar-stack.vala
+src/client/components/components-info-bar.vala
 src/client/components/components-inspector.vala
 src/client/components/components-placeholder-pane.vala
 src/client/components/components-preferences-window.vala
diff --git a/src/client/components/components-info-bar.vala b/src/client/components/components-info-bar.vala
new file mode 100644
index 00000000..0944cff8
--- /dev/null
+++ b/src/client/components/components-info-bar.vala
@@ -0,0 +1,75 @@
+/*
+ * Copyright © 2020 Michael Gratton <mike vee net>
+ *
+ * This software is licensed under the GNU Lesser General Public License
+ * (version 2.1 or later). See the COPYING file in this distribution.
+ */
+
+/**
+ * A standard info bar widget with status message and description.
+ */
+public class Components.InfoBar : Gtk.InfoBar {
+
+
+    /**
+     * A short, human-readable status message.
+     *
+     * This should ideally be less than 20 characters long.
+     */
+    public Gtk.Label status { get; private set; }
+
+    /**
+     * An optional, longer human-readable explanation of the status.
+     *
+     * This provides additional information and context for {@link
+     * status}.
+     */
+    public Gtk.Label? description { get; private set; default = null; }
+
+
+    /**
+     * Constructs a new info bar.
+     *
+     * @param status a short, human-readable status message, ideally
+     * less than 20 characters long
+     * @param description an optional, longer human-readable
+     * explanation of {@link status}.
+     */
+    public InfoBar(string status, string? description = null) {
+        this.status = new Gtk.Label(status);
+        this.status.halign = START;
+
+        var attrs = new Pango.AttrList();
+        attrs.change(Pango.attr_weight_new(BOLD));
+        this.status.attributes = attrs;
+
+        if (!Geary.String.is_empty_or_whitespace(description)) {
+            // There is both a status and a description, so they
+            // should be vertical-aligned next to each other in the
+            // centre
+            this.status.valign = END;
+
+            this.description = new Gtk.Label(description);
+            this.description.halign = START;
+            this.description.valign = START;
+
+            // Set the description to be ellipsised and set and the
+            // tool-tip to be the same, in case it is too long for the
+            // info bar's width
+            this.description.ellipsize = END;
+            this.description.tooltip_text = description;
+        }
+
+        var container = new Gtk.Grid();
+        container.orientation = VERTICAL;
+        container.valign = CENTER;
+        container.add(this.status);
+        if (this.description != null) {
+            container.add(this.description);
+        }
+        get_content_area().add(container);
+
+        show_all();
+    }
+
+}
diff --git a/src/client/meson.build b/src/client/meson.build
index 556e06ae..de4c651e 100644
--- a/src/client/meson.build
+++ b/src/client/meson.build
@@ -34,6 +34,7 @@ geary_client_vala_sources = files(
   'components/components-attachment-pane.vala',
   'components/components-entry-undo.vala',
   'components/components-info-bar-stack.vala',
+  'components/components-info-bar.vala',
   'components/components-inspector.vala',
   'components/components-in-app-notification.vala',
   'components/components-inspector-error-view.vala',


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