[geary/mjog/email-templates: 66/72] Plugin.Composer: Add support for editing an email in the composer



commit 00d7d3b95bf6f2a6fd85f9bff11b3fd39af008ec
Author: Michael Gratton <mike vee net>
Date:   Mon Apr 20 11:21:32 2020 +1000

    Plugin.Composer: Add support for editing an email in the composer
    
    Add `edit_email` method, and implement in the underlying implementation.

 .../application/application-plugin-manager.vala    | 41 +++++++++++++++++++---
 src/client/plugin/plugin-composer.vala             | 11 ++++++
 2 files changed, 47 insertions(+), 5 deletions(-)
---
diff --git a/src/client/application/application-plugin-manager.vala 
b/src/client/application/application-plugin-manager.vala
index b36e9e1a..765af474 100644
--- a/src/client/application/application-plugin-manager.vala
+++ b/src/client/application/application-plugin-manager.vala
@@ -52,15 +52,18 @@ public class Application.PluginManager : GLib.Object {
         private Peas.PluginInfo plugin;
         private Client backing;
         private FolderStoreFactory folders;
+        private EmailStoreFactory email;
         private GLib.SimpleActionGroup? action_group = null;
 
 
         public ApplicationImpl(Peas.PluginInfo plugin,
                                Client backing,
-                               FolderStoreFactory folders) {
+                               FolderStoreFactory folders,
+                               EmailStoreFactory email) {
             this.plugin = plugin;
             this.backing = backing;
             this.folders = folders;
+            this.email = email;
             this.action_group_name = plugin.get_module_name().replace(".", "_");
         }
 
@@ -70,7 +73,7 @@ public class Application.PluginManager : GLib.Object {
             if (impl == null) {
                 throw new Plugin.Error.NOT_SUPPORTED("Not a valid account");
             }
-            return new ComposerImpl(this.backing, impl.backing);
+            return new ComposerImpl(this.backing, impl.backing, this.email);
         }
 
         public void register_action(GLib.Action action) {
@@ -175,17 +178,45 @@ public class Application.PluginManager : GLib.Object {
 
         private Client application;
         private AccountContext account;
+        private EmailStoreFactory email;
+        private Geary.Email? to_load = null;
 
 
-        public ComposerImpl(Client application, AccountContext account) {
+        public ComposerImpl(Client application,
+                            AccountContext account,
+                            EmailStoreFactory email) {
             this.application = application;
             this.account = account;
+            this.email = email;
         }
 
         public void show() {
-            this.application.controller.compose_new_email.begin();
+            if (this.to_load == null) {
+                this.application.controller.compose_new_email.begin();
+            } else {
+                this.application.controller.compose_with_context_email.begin(
+                    EDIT, this.to_load, null
+                );
+            }
         }
 
+        public async void edit_email(Plugin.EmailIdentifier to_load)
+            throws Error {
+            Geary.EmailIdentifier? id = this.email.to_engine_id(to_load);
+            if (id == null) {
+                throw new Plugin.Error.NOT_FOUND("Email id not found");
+            }
+            Gee.Collection<Geary.Email>? email =
+                yield this.account.emails.list_email_by_sparse_id_async(
+                    Geary.Collection.single(id),
+                    Composer.Widget.REQUIRED_FIELDS,
+                    NONE,
+                    this.account.cancellable
+                );
+            if (email != null && !email.is_empty) {
+                this.to_load = Geary.Collection.first(email);
+            }
+        }
     }
 
 
@@ -381,7 +412,7 @@ public class Application.PluginManager : GLib.Object {
 
     private void on_load_plugin(Peas.PluginInfo info) {
         var plugin_application = new ApplicationImpl(
-            info, this.application, this.folders_factory
+            info, this.application, this.folders_factory, this.email_factory
         );
         var plugin = this.plugins.create_extension(
             info,
diff --git a/src/client/plugin/plugin-composer.vala b/src/client/plugin/plugin-composer.vala
index b399530c..c6980a64 100644
--- a/src/client/plugin/plugin-composer.vala
+++ b/src/client/plugin/plugin-composer.vala
@@ -10,6 +10,7 @@
  */
 public interface Plugin.Composer : Geary.BaseObject {
 
+
     /**
      * Causes the composer to be made visible.
      *
@@ -21,4 +22,14 @@ public interface Plugin.Composer : Geary.BaseObject {
      */
     public abstract void show();
 
+    /**
+     * Loads an email into the composer to be edited.
+     *
+     * Loads the given email, and sets it as the email to be edited in
+     * this composer. This must be called before calling {@link show},
+     * and has no effect if called afterwards.
+     */
+    public async abstract void edit_email(EmailIdentifier to_load)
+        throws GLib.Error;
+
 }


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