[geary/mjog/folder-actions: 6/7] Plugin.InfoBar: Allow plugins to add a button to info bars
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/mjog/folder-actions: 6/7] Plugin.InfoBar: Allow plugins to add a button to info bars
- Date: Fri, 20 Mar 2020 06:43:04 +0000 (UTC)
commit 27943e29a08374b6b6961855294c408b140e947d
Author: Michael Gratton <mike vee net>
Date: Fri Mar 20 15:20:06 2020 +1100
Plugin.InfoBar: Allow plugins to add a button to info bars
Add new InfoBar::primary_button property, construct it if provided
when constructing the Gtk Infobar.
.../application/application-folder-context.vala | 34 ++++++++++++++++++----
.../application/application-plugin-manager.vala | 3 +-
src/client/plugin/plugin-info-bar.vala | 11 +++++++
3 files changed, 41 insertions(+), 7 deletions(-)
---
diff --git a/src/client/application/application-folder-context.vala
b/src/client/application/application-folder-context.vala
index 6686e052..ab23bc83 100644
--- a/src/client/application/application-folder-context.vala
+++ b/src/client/application/application-folder-context.vala
@@ -18,10 +18,28 @@ internal class Application.FolderContext :
private Plugin.InfoBar plugin;
- public PluginInfoBar(Plugin.InfoBar plugin) {
+ public PluginInfoBar(Plugin.InfoBar plugin,
+ string action_group_name) {
base(plugin.status, plugin.description);
this.show_close_button = plugin.show_close_button;
this.plugin = plugin;
+
+ 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);
+ }
+
+ show_all();
}
}
@@ -30,13 +48,16 @@ internal class Application.FolderContext :
private unowned Client application;
private FolderStoreFactory folders_factory;
private Plugin.FolderStore folders;
+ private string action_group_name;
internal FolderContext(Client application,
- FolderStoreFactory folders_factory) {
+ FolderStoreFactory folders_factory,
+ string action_group_name) {
this.application = application;
this.folders_factory = folders_factory;
this.folders = folders_factory.new_folder_store();
+ this.action_group_name = action_group_name;
}
public async Plugin.FolderStore get_folders()
@@ -52,7 +73,7 @@ internal class Application.FolderContext :
foreach (MainWindow main in this.application.get_main_windows()) {
if (main.selected_folder == folder) {
main.conversation_list_info_bars.add(
- new PluginInfoBar(infobar)
+ new PluginInfoBar(infobar, this.action_group_name)
);
}
}
@@ -65,9 +86,10 @@ internal class Application.FolderContext :
if (folder != null) {
foreach (MainWindow main in this.application.get_main_windows()) {
if (main.selected_folder == folder) {
- main.conversation_list_info_bars.remove(
- new PluginInfoBar(infobar)
- );
+ // XXX implement this
+ //main.conversation_list_info_bars.remove(
+ // XXX
+ //);
}
}
}
diff --git a/src/client/application/application-plugin-manager.vala
b/src/client/application/application-plugin-manager.vala
index 50988d48..84a30921 100644
--- a/src/client/application/application-plugin-manager.vala
+++ b/src/client/application/application-plugin-manager.vala
@@ -276,7 +276,8 @@ public class Application.PluginManager : GLib.Object {
if (folder != null) {
folder.folders = new FolderContext(
this.application,
- this.folders_factory
+ this.folders_factory,
+ plugin_application.action_group_name
);
}
diff --git a/src/client/plugin/plugin-info-bar.vala b/src/client/plugin/plugin-info-bar.vala
index 9e4e3937..a8f81902 100644
--- a/src/client/plugin/plugin-info-bar.vala
+++ b/src/client/plugin/plugin-info-bar.vala
@@ -33,6 +33,17 @@ public class Plugin.InfoBar : Geary.BaseObject {
/** Determines if a close button is displayed by the info bar. */
public bool show_close_button { get; set; default = false; }
+ /**
+ * An optional primary button for the info bar.
+ *
+ * The info bar is not automatically dismissed when the 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 Button? primary_button { get; set; default = null; }
+
/** 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]