[geary/wip/draft-management: 20/27] Don't reopen drafts that are already open in a composer



commit 51ac4b7310fd01143304fb090a819e1937bfa936
Author: Michael Gratton <mike vee net>
Date:   Mon Jul 22 18:08:46 2019 +1000

    Don't reopen drafts that are already open in a composer
    
    See #72

 src/client/application/application-controller.vala | 25 ++++++++++++++++++----
 src/client/components/main-window.vala             |  2 +-
 src/client/composer/composer-widget.vala           | 12 +++++++++--
 3 files changed, 32 insertions(+), 7 deletions(-)
---
diff --git a/src/client/application/application-controller.vala 
b/src/client/application/application-controller.vala
index 1a25cf95..ee619996 100644
--- a/src/client/application/application-controller.vala
+++ b/src/client/application/application-controller.vala
@@ -1250,9 +1250,23 @@ public class Application.Controller : Geary.BaseObject {
         Geary.Email draft = activated.get_latest_recv_email(
             Geary.App.Conversation.Location.IN_FOLDER
         );
-        create_compose_widget(
-            ComposerWidget.ComposeType.NEW_MESSAGE, draft, null, null, true
-        );
+
+        bool already_open = false;
+        foreach (ComposerWidget composer in this.composer_widgets) {
+            if (composer.draft_id != null &&
+                composer.draft_id.equal_to(draft.id)) {
+                already_open = true;
+                composer.present();
+                composer.set_focus();
+                break;
+            }
+        }
+
+        if (!already_open) {
+            create_compose_widget(
+                ComposerWidget.ComposeType.NEW_MESSAGE, draft, null, null, true
+            );
+        }
     }
 
     private void on_special_folder_type_changed(Geary.Folder folder,
@@ -2027,7 +2041,10 @@ public class Application.Controller : Geary.BaseObject {
             );
         } else {
             widget = new ComposerWidget(
-                this.application, current_account, compose_type
+                this.application,
+                current_account,
+                is_draft ? referred.id : null,
+                compose_type
             );
         }
 
diff --git a/src/client/components/main-window.vala b/src/client/components/main-window.vala
index 6d04c416..2de8d35b 100644
--- a/src/client/components/main-window.vala
+++ b/src/client/components/main-window.vala
@@ -128,7 +128,7 @@ public class MainWindow : Gtk.ApplicationWindow, Geary.BaseInterface {
     public void open_composer_for_mailbox(Geary.RFC822.MailboxAddress to) {
         Application.Controller controller = this.application.controller;
         ComposerWidget composer = new ComposerWidget(
-            this.application, this.current_folder.account, NEW_MESSAGE
+            this.application, this.current_folder.account, null, NEW_MESSAGE
         );
         composer.to = to.to_full_display();
         controller.add_composer(composer);
diff --git a/src/client/composer/composer-widget.vala b/src/client/composer/composer-widget.vala
index 88904a7e..e3e331d7 100644
--- a/src/client/composer/composer-widget.vala
+++ b/src/client/composer/composer-widget.vala
@@ -170,6 +170,9 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
     public Geary.Account account { get; private set; }
     private Gee.Map<string, Geary.AccountInformation> accounts;
 
+    /** The identifier of the draft this composer holds, if any. */
+    public Geary.EmailIdentifier? draft_id { get; private set; default = null; }
+
     public Geary.RFC822.MailboxAddresses from { get; private set; }
 
     public string to {
@@ -399,11 +402,12 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
 
     public ComposerWidget(GearyApplication application,
                           Geary.Account initial_account,
+                          Geary.EmailIdentifier? draft_id,
                           ComposeType compose_type) {
         base_ref();
         this.application = application;
         this.account = initial_account;
-        this.account = account;
+        this.draft_id = draft_id;
 
         try {
             this.accounts = this.application.engine.get_accounts();
@@ -569,7 +573,7 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
     public ComposerWidget.from_mailto(GearyApplication application,
                                       Geary.Account initial_account,
                                       string mailto) {
-        this(application, initial_account, ComposeType.NEW_MESSAGE);
+        this(application, initial_account, null, ComposeType.NEW_MESSAGE);
 
         Gee.HashMultiMap<string, string> headers = new Gee.HashMultiMap<string, string>();
         if (mailto.length > Geary.ComposedEmail.MAILTO_SCHEME.length) {
@@ -819,6 +823,10 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
         return referred_quote;
     }
 
+    public void present() {
+        this.container.present();
+    }
+
     public void set_focus() {
         bool not_compact = (this.state != ComposerState.INLINE_COMPACT);
         if (not_compact && Geary.String.is_empty(to))


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