[geary/mjog/493-undo-send: 21/25] Make Application.Controller's composer command re-usable



commit 142d50a894c76e145c8ad71756d6d1c87fffee37
Author: Michael Gratton <mike vee net>
Date:   Tue Nov 12 14:31:53 2019 +1100

    Make Application.Controller's composer command re-usable
    
    Rename ::send_email to ::send_composed_email and SendCommand to
    SendComposerCommand to better reflect what they do. Rework the command
    to use an abstratc base class with some generic composer management
    methods.

 src/client/application/application-controller.vala | 52 +++++++++++++++-------
 src/client/composer/composer-widget.vala           |  2 +-
 2 files changed, 38 insertions(+), 16 deletions(-)
---
diff --git a/src/client/application/application-controller.vala 
b/src/client/application/application-controller.vala
index aab69fdb..7b8b5c6e 100644
--- a/src/client/application/application-controller.vala
+++ b/src/client/application/application-controller.vala
@@ -448,7 +448,7 @@ public class Application.Controller : Geary.BaseObject {
     }
 
     /** Queues the email in a composer for delivery. */
-    public async void send_email(Composer.Widget composer) {
+    public async void send_composed_email(Composer.Widget composer) {
         AccountContext? context = this.accounts.get(
             composer.account.information
         );
@@ -2624,20 +2624,44 @@ private class Application.EmptyFolderCommand : Command {
 }
 
 
-private class Application.SendComposerCommand : Command {
+private abstract class Application.ComposerCommand : Command {
 
 
-    public override bool can_undo {
-        get { return this.application.config.undo_send_delay > 0; }
-    }
-
     public override bool can_redo {
         get { return false; }
     }
 
+    protected Composer.Widget? composer { get; private set; }
+
+
+    public ComposerCommand(Composer.Widget composer) {
+        this.composer = composer;
+    }
+
+    protected void clear_composer() {
+        this.composer = null;
+    }
+
+    protected void close_composer() {
+        // Calling close then immediately erasing the reference looks
+        // sketchy, but works since Controller still maintains a
+        // reference to the composer until it destroys itself.
+        this.composer.close.begin();
+        this.composer = null;
+    }
+
+}
+
+
+private class Application.SendComposerCommand : ComposerCommand {
+
+
+    public override bool can_undo {
+        get { return this.application.config.undo_send_delay > 0; }
+    }
+
     private GearyApplication application;
     private Controller.AccountContext context;
-    private Composer.Widget? composer;
     private Geary.Smtp.ClientService smtp;
     private Geary.TimeoutManager commit_timer;
     private Geary.EmailIdentifier? saved = null;
@@ -2646,9 +2670,9 @@ private class Application.SendComposerCommand : Command {
     public SendComposerCommand(GearyApplication application,
                                Controller.AccountContext context,
                                Composer.Widget composer) {
+        base(composer);
         this.application = application;
         this.context = context;
-        this.composer = composer;
         this.smtp = (Geary.Smtp.ClientService) context.account.outgoing;
 
         int send_delay = this.application.config.undo_send_delay;
@@ -2673,6 +2697,7 @@ private class Application.SendComposerCommand : Command {
         } else {
             yield this.smtp.send_email(email, cancellable);
         }
+        close_composer();
     }
 
     public override async void undo(GLib.Cancellable? cancellable)
@@ -2682,20 +2707,17 @@ private class Application.SendComposerCommand : Command {
             Geary.Collection.single(this.saved),
             cancellable
         );
+        this.saved = null;
+
         this.composer.set_enabled(true);
         this.application.controller.show_composer(this.composer, null);
-        this.composer = null;
-        this.saved = null;
+        clear_composer();
     }
 
     private void on_commit_timeout() {
         this.smtp.queue_email(this.saved);
-        // Calling close then immediately erasing the reference looks
-        // sketchy, but works since Controller still maintains a
-        // reference to the composer until it destroys itself.
-        this.composer.close.begin();
-        this.composer = null;
         this.saved = null;
+        close_composer();
     }
 
 }
diff --git a/src/client/composer/composer-widget.vala b/src/client/composer/composer-widget.vala
index 93b6a799..f184eb02 100644
--- a/src/client/composer/composer-widget.vala
+++ b/src/client/composer/composer-widget.vala
@@ -1446,7 +1446,7 @@ public class Composer.Widget : Gtk.EventBox, Geary.BaseInterface {
 
         try {
             yield this.editor.clean_content();
-            yield this.application.controller.send_email(this);
+            yield this.application.controller.send_composed_email(this);
 
             if (this.draft_manager != null) {
                 yield discard_draft();


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