[geary/mjog/mail-merge-plugin: 57/71] Plugin.Composer: Add insert_text method




commit 5f0d201245c9f4192b29686448576b93f221ed45
Author: Michael Gratton <mike vee net>
Date:   Wed Jul 8 16:17:54 2020 +1000

    Plugin.Composer: Add insert_text method
    
    Supports plugins that insert text into the composer.

 src/client/application/application-plugin-manager.vala |  9 +++++++++
 src/client/plugin/plugin-composer.vala                 | 13 +++++++++++++
 2 files changed, 22 insertions(+)
---
diff --git a/src/client/application/application-plugin-manager.vala 
b/src/client/application/application-plugin-manager.vala
index 60ea7a48e..ce3acdeb5 100644
--- a/src/client/application/application-plugin-manager.vala
+++ b/src/client/application/application-plugin-manager.vala
@@ -416,6 +416,15 @@ public class Application.PluginManager : GLib.Object {
             this.application.backing.controller.present_composer(this.backing);
         }
 
+        public void insert_text(string plain_text) {
+            var entry = this.backing.focused_input_widget as Gtk.Entry;
+            if (entry != null) {
+                entry.insert_at_cursor(plain_text);
+            } else {
+                this.backing.editor.insert_text(plain_text);
+            }
+        }
+
         public void register_action(GLib.Action action) {
             if (this.action_group == null) {
                 this.action_group = new GLib.SimpleActionGroup();
diff --git a/src/client/plugin/plugin-composer.vala b/src/client/plugin/plugin-composer.vala
index 03a0d7471..e2fb71e4d 100644
--- a/src/client/plugin/plugin-composer.vala
+++ b/src/client/plugin/plugin-composer.vala
@@ -81,6 +81,19 @@ public interface Plugin.Composer : Geary.BaseObject {
      */
     public abstract void present();
 
+    /**
+     * Inserts text at the current cursor position.
+     *
+     * The given text is inserted at the current cursor position in
+     * the composer. Note that this may be in an address field,
+     * subject line, or message body, depending on which component is
+     * focused.
+     *
+     * If the text is inserted into the message body, any HTML markup
+     * present in the string will appear as-is.
+     */
+    public abstract void insert_text(string plain_text);
+
     /**
      * Sets the folder used to save the message being composed.
      *


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