[geary/mjog/account-command-stacks: 23/27] Update Application.CommandSequence



commit 05e12e966f9ee625c89c0b297933c5966b3b92ce
Author: Michael Gratton <mike vee net>
Date:   Wed Oct 23 11:56:18 2019 +1100

    Update Application.CommandSequence
    
    Make its list of commands private, implement firing state signals for
    commands in its sequence.

 .../accounts/accounts-editor-servers-pane.vala     | 26 ++++++------
 src/client/application/application-command.vala    | 48 +++++++++++++++++++++-
 2 files changed, 59 insertions(+), 15 deletions(-)
---
diff --git a/src/client/accounts/accounts-editor-servers-pane.vala 
b/src/client/accounts/accounts-editor-servers-pane.vala
index 328d2aa6..1eb402c9 100644
--- a/src/client/accounts/accounts-editor-servers-pane.vala
+++ b/src/client/accounts/accounts-editor-servers-pane.vala
@@ -1079,14 +1079,14 @@ private class Accounts.ServiceOutgoingAuthRow :
                 );
             }
 
-            Application.CommandSequence seq = new Application.CommandSequence({
-                    new Application.PropertyCommand<Geary.Credentials?>(
-                        this.service, "credentials", new_creds
-                    ),
-                    new Application.PropertyCommand<uint>(
-                        this.service, "credentials-requirement", this.value.source
-                    )
-                });
+            Application.Command[] commands = {
+                new Application.PropertyCommand<Geary.Credentials?>(
+                    this.service, "credentials", new_creds
+                ),
+                new Application.PropertyCommand<uint>(
+                    this.service, "credentials-requirement", this.value.source
+                )
+            };
 
             // The default SMTP port also depends on the auth method
             // used, so also update the port here if we're currently
@@ -1099,14 +1099,14 @@ private class Accounts.ServiceOutgoingAuthRow :
                 Geary.ServiceInformation copy =
                     new Geary.ServiceInformation.copy(this.service);
                 copy.credentials_requirement = this.value.source;
-                seq.commands.add(
-                    new Application.PropertyCommand<uint>(
-                        this.service, "port", copy.get_default_port()
-                    )
+                commands += new Application.PropertyCommand<uint>(
+                    this.service, "port", copy.get_default_port()
                 );
             }
 
-            this.commands.execute.begin(seq, this.cancellable);
+            this.commands.execute.begin(
+                new Application.CommandSequence(commands), this.cancellable
+            );
         }
     }
 
diff --git a/src/client/application/application-command.vala b/src/client/application/application-command.vala
index 5a781a21..a348d584 100644
--- a/src/client/application/application-command.vala
+++ b/src/client/application/application-command.vala
@@ -155,14 +155,58 @@ public abstract class Application.Command : GLib.Object {
 
 /**
  * A command that executes a sequence of other commands.
+ *
+ * When initially executed or redone, commands will be processed
+ * individually in the given order. When undone, commands will be
+ * processed individually in reverse order.
  */
 public class Application.CommandSequence : Command {
 
 
-    public Gee.List<Command> commands {
-        get; private set; default = new Gee.LinkedList<Command>();
+    /**
+     * Emitted when the command was successfully executed.
+     *
+     * Ensures the same signal is emitted on all commands in the
+     * sequence, in order.
+     */
+    public override void executed() {
+       foreach (Command command in this.commands) {
+           command.executed();
+       }
     }
 
+    /**
+     * Emitted when the command was successfully undone.
+     *
+     * Ensures the same signal is emitted on all commands in the
+     * sequence, in reverse order.
+     */
+    public override void undone() {
+       Gee.LinkedList<Command> reversed = new Gee.LinkedList<Command>();
+       foreach (Command command in this.commands) {
+           reversed.insert(0, command);
+       }
+       foreach (Command command in reversed) {
+           command.undone();
+       }
+    }
+
+    /**
+     * Emitted when the command was successfully redone.
+     *
+     * Ensures the same signal is emitted on all commands in the
+     * sequence, in order.
+     */
+    public override void redone() {
+       foreach (Command command in this.commands) {
+           command.redone();
+       }
+    }
+
+
+    private Gee.List<Command> commands = new Gee.LinkedList<Command>();
+
+
     public CommandSequence(Command[]? commands = null) {
         if (commands != null) {
             this.commands.add_all_array(commands);


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