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



commit fcf99443fde6aff3d3df0ca635ebe23628a57f86
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 2f24c234..bd6b3778 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -36,6 +36,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 242d6ec6..3284d38a 100644
--- a/src/client/meson.build
+++ b/src/client/meson.build
@@ -32,6 +32,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]