[geary/mjog/email-templates: 70/72] Plugin.InfoBar: Allow secondary buttons to be specified.



commit db494fb88cfec38af9f0b8d310121bf4e2c2ebff
Author: Michael Gratton <mike vee net>
Date:   Mon Apr 20 23:49:18 2020 +1000

    Plugin.InfoBar: Allow secondary buttons to be specified.

 src/client/components/components-info-bar.vala | 29 +++++++++++++++-----------
 src/client/plugin/plugin-info-bar.vala         | 15 +++++++++++++
 2 files changed, 32 insertions(+), 12 deletions(-)
---
diff --git a/src/client/components/components-info-bar.vala b/src/client/components/components-info-bar.vala
index 943218b2..f024b365 100644
--- a/src/client/components/components-info-bar.vala
+++ b/src/client/components/components-info-bar.vala
@@ -77,18 +77,14 @@ public class Components.InfoBar : Gtk.InfoBar {
         this(plugin.status, plugin.description);
         this.show_close_button = plugin.show_close_button;
 
-        var plugin_primary = plugin.primary_button;
-        if (plugin_primary != null) {
-            var gtk_primary = new Gtk.Button.with_label(plugin_primary.label);
-            gtk_primary.set_action_name(
-                action_group_name + "." + plugin_primary.action.name
-            );
-            if (plugin_primary.action_target != null) {
-                gtk_primary.set_action_target_value(
-                    plugin_primary.action_target
-                );
-            }
-            get_action_area().add(gtk_primary);
+        var secondaries = plugin.secondary_buttons.bidir_list_iterator();
+        bool has_prev = secondaries.last();
+        while (has_prev) {
+            add_plugin_button(secondaries.get(), action_group_name);
+            has_prev = secondaries.previous();
+        }
+        if (plugin.primary_button != null) {
+            add_plugin_button(plugin.primary_button, action_group_name);
         }
 
         show_all();
@@ -100,4 +96,13 @@ public class Components.InfoBar : Gtk.InfoBar {
         return (Gtk.Box) base.get_action_area();
     }
 
+    private void add_plugin_button(Plugin.Button plugin, string action_group_name) {
+        var gtk = new Gtk.Button.with_label(plugin.label);
+        gtk.set_action_name(action_group_name + "." + plugin.action.name);
+        if (plugin.action_target != null) {
+            gtk.set_action_target_value(plugin.action_target);
+        }
+        get_action_area().add(gtk);
+    }
+
 }
diff --git a/src/client/plugin/plugin-info-bar.vala b/src/client/plugin/plugin-info-bar.vala
index a8f81902..2dcfd186 100644
--- a/src/client/plugin/plugin-info-bar.vala
+++ b/src/client/plugin/plugin-info-bar.vala
@@ -44,6 +44,21 @@ public class Plugin.InfoBar : Geary.BaseObject {
      */
     public Button? primary_button { get; set; default = null; }
 
+    /**
+     * Optional secondary buttons for the info bar.
+     *
+     * Secondary buttons are either placed before the primary button,
+     * or on a drop-down menu under it, depending on available space.
+     *
+     * The info bar is not automatically dismissed when a button is
+     * clicked. If it should be hidden then the action's handler
+     * should explicitly do so by calling the appropriate context
+     * object's method, such as {@link
+     * FolderContext.remove_folder_info_bar}.
+     */
+    public Gee.BidirList<Button> secondary_buttons {
+        get; private set; default = new Gee.LinkedList<Button>();
+    }
 
     /** Constructs a new info bar with the given status. */
     public InfoBar(string status,


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