[geary/mjog/493-undo-send: 1/6] Make Application.Controller's composer command re-usable
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/mjog/493-undo-send: 1/6] Make Application.Controller's composer command re-usable
- Date: Sat, 16 Nov 2019 00:01:25 +0000 (UTC)
commit 0cd3c26a3ccfb9f0fd07f5e19207628ff1cbf786
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 | 51 +++++++++++++++-------
src/client/composer/composer-widget.vala | 2 +-
2 files changed, 37 insertions(+), 16 deletions(-)
---
diff --git a/src/client/application/application-controller.vala
b/src/client/application/application-controller.vala
index aab69fdb..eea14079 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; }
+
+
+ protected 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;
@@ -2682,20 +2706,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]