[geary/mjog/mail-merge-plugin: 21/28] Plugin.Composer: Support registering composer menu items
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/mjog/mail-merge-plugin: 21/28] Plugin.Composer: Support registering composer menu items
- Date: Tue, 7 Jul 2020 06:58:26 +0000 (UTC)
commit 65509e213b9336c298a1e4eee089682d4b396a88
Author: Michael Gratton <mike vee net>
Date: Fri Jul 3 18:03:47 2020 +1000
Plugin.Composer: Support registering composer menu items
Allow plugins to register per-composer actions and add menu items to
their own section in the composer's menu.
.../application/application-plugin-manager.vala | 37 ++++++++++++++++++++++
src/client/composer/composer-widget.vala | 10 ++++++
src/client/plugin/plugin-composer.vala | 35 ++++++++++++++++++++
3 files changed, 82 insertions(+)
---
diff --git a/src/client/application/application-plugin-manager.vala
b/src/client/application/application-plugin-manager.vala
index 82df12e70..5c3cf87ad 100644
--- a/src/client/application/application-plugin-manager.vala
+++ b/src/client/application/application-plugin-manager.vala
@@ -376,12 +376,18 @@ public class Application.PluginManager : GLib.Object {
private Composer.Widget backing;
private weak ApplicationImpl application;
+ private GLib.SimpleActionGroup? action_group = null;
+ private GLib.Menu? menu_items = null;
+ private string action_group_name;
+
+
public ComposerImpl(Composer.Widget backing,
ApplicationImpl application) {
this.backing = backing;
this.application = application;
+ this.action_group_name = application.plugin.action_group_name + "-cmp";
}
public void save_to_folder(Plugin.Folder? location) {
@@ -407,6 +413,37 @@ public class Application.PluginManager : GLib.Object {
this.application.backing.controller.present_composer(this.backing);
}
+ public void register_action(GLib.Action action) {
+ if (this.action_group == null) {
+ this.action_group = new GLib.SimpleActionGroup();
+ this.backing.insert_action_group(
+ this.action_group_name,
+ this.action_group
+ );
+ }
+
+ this.action_group.add_action(action);
+ }
+
+ public void deregister_action(GLib.Action action) {
+ this.action_group.remove_action(action.get_name());
+ }
+
+ public void append_menu_item(Plugin.Actionable menu_item) {
+ if (this.menu_items == null) {
+ this.menu_items = new GLib.Menu();
+ this.backing.insert_menu_section(this.menu_items);
+ }
+ this.menu_items.append(
+ menu_item.label,
+ GLib.Action.print_detailed_name(
+ this.action_group_name + "." + menu_item.action.name,
+ menu_item.action_target
+ )
+ );
+ }
+
+
}
diff --git a/src/client/composer/composer-widget.vala b/src/client/composer/composer-widget.vala
index 77330ca39..d51df99c4 100644
--- a/src/client/composer/composer-widget.vala
+++ b/src/client/composer/composer-widget.vala
@@ -1034,6 +1034,16 @@ public class Composer.Widget : Gtk.EventBox, Geary.BaseInterface {
}
}
+ /**
+ * Inserts a menu section into the composer's menu.
+ */
+ public void insert_menu_section(GLib.MenuModel section) {
+ var menu = this.more_options_button.menu_model as GLib.Menu;
+ if (menu != null) {
+ menu.insert_section(0, null, section);
+ }
+ }
+
/** Overrides the draft folder as a destination for saving. */
internal async void set_save_to_override(Geary.Folder? save_to)
throws GLib.Error {
diff --git a/src/client/plugin/plugin-composer.vala b/src/client/plugin/plugin-composer.vala
index 9765ef13d..269ed2be5 100644
--- a/src/client/plugin/plugin-composer.vala
+++ b/src/client/plugin/plugin-composer.vala
@@ -80,4 +80,39 @@ public interface Plugin.Composer : Geary.BaseObject {
*/
public abstract void save_to_folder(Plugin.Folder? location);
+ /**
+ * Registers a plugin action with this specific composer.
+ *
+ * Once registered, the action will be available for use in user
+ * interface elements such as {@link Actionable}.
+ *
+ * @see deregister_action
+ */
+ public abstract void register_action(GLib.Action action);
+
+ /**
+ * De-registers a plugin action, removing it from this composer.
+ *
+ * Makes a previously registered no longer available.
+ *
+ * @see register_action
+ */
+ public abstract void deregister_action(GLib.Action action);
+
+ /**
+ * Adds a menu item to the composer's menu.
+ *
+ * The menu item will be added to a section unique to this plugin
+ * on the composer's menu. The item's action must be registered
+ * either with the application via {@link
+ * Application.register_action} if it is a global action, or with
+ * the composer via {@link register_action} if it is
+ * composer-specific for it to be successfully activated.
+ *
+ * @see register_action
+ * @see Application.register_action
+ */
+ public abstract void append_menu_item(Actionable menu_item);
+
+
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]