diff --git a/src/client/application/application-plugin-manager.vala b/src/client/application/application-plugin-manager.vala index 0f0c9622..a4ceabd7 100644 --- a/src/client/application/application-plugin-manager.vala +++ b/src/client/application/application-plugin-manager.vala @@ -380,12 +380,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) { @@ -411,6 +417,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 0b256316..9b5ca74d 100644 --- a/src/client/composer/composer-widget.vala +++ b/src/client/composer/composer-widget.vala @@ -1104,6 +1104,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 9765ef13..269ed2be 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); + + }