[geary] Handle multiple new compositions



commit 18d92ea9debae772e4c6f03f3af84bced28f5ae3
Author: Robert Schroll <rschroll gmail com>
Date:   Mon May 19 13:09:56 2014 -0700

    Handle multiple new compositions
    
    A second request for a new composition will open a new composer in a new
    window, unless the first new compostion has no content.

 src/client/application/geary-controller.vala       |   43 +++++++++++++++++---
 src/client/composer/composer-widget.vala           |    7 +++
 .../conversation-list/conversation-list-view.vala  |    2 +-
 3 files changed, 45 insertions(+), 7 deletions(-)
---
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index 83a96d0..11de436 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -1815,7 +1815,8 @@ public class GearyController : Geary.BaseObject {
         if (current_account == null)
             return;
         
-        if (!should_create_new_composer(compose_type, referred))
+        bool inline;
+        if (!should_create_new_composer(compose_type, referred, out inline))
             return;
         
         ComposerWidget widget;
@@ -1842,13 +1843,20 @@ public class GearyController : Geary.BaseObject {
         composer_widgets.add(widget);
         widget.destroy.connect(on_composer_widget_destroy);
         
-        new ComposerEmbed(widget, main_window.conversation_viewer, referred);
+        if (inline) {
+            new ComposerEmbed(widget, main_window.conversation_viewer, referred);
+        } else {
+            widget.state = ComposerWidget.ComposerState.DETACHED;
+            new ComposerWindow(widget);
+        }
     }
     
-    public bool should_create_new_composer(
-        ComposerWidget.ComposeType compose_type = ComposerWidget.ComposeType.NEW_MESSAGE,
-        Geary.Email? referred = null) {
-        if (compose_type != ComposerWidget.ComposeType.NEW_MESSAGE) {
+    private bool should_create_new_composer(ComposerWidget.ComposeType? compose_type,
+        Geary.Email? referred, out bool inline) {
+        inline = true;
+        
+        // In we're replying, see whether we already have a reply for that message.
+        if (compose_type != null && compose_type != ComposerWidget.ComposeType.NEW_MESSAGE) {
             foreach (ComposerWidget cw in composer_widgets) {
                 if (cw.state != ComposerWidget.ComposerState.DETACHED &&
                     referred != null && referred.id.equal_to(cw.referred_id)) {
@@ -1859,9 +1867,27 @@ public class GearyController : Geary.BaseObject {
             return true;
         }
         
+        // If there are no inline composers, go ahead!
         if (!any_inline_composers())
             return true;
         
+        // If we're creating a new message, and there's already a new message open, focus on
+        // it if it hasn't been modified; otherwise open a new composer in a new window.
+        if (compose_type == ComposerWidget.ComposeType.NEW_MESSAGE) {
+            foreach (ComposerWidget cw in composer_widgets) {
+                if (cw.state == ComposerWidget.ComposerState.INLINE_NEW) {
+                    if (!cw.blank) {
+                        inline = false;
+                        return true;
+                    } else {
+                        cw.change_compose_type(compose_type);  // To refocus
+                        return false;
+                    }
+                }
+            }
+        }
+        
+        // Find out what to do with the inline composers.
         // TODO: Remove this in favor of automatically saving drafts
         main_window.present();
         AlertDialog dialog;
@@ -1882,6 +1908,11 @@ public class GearyController : Geary.BaseObject {
         return false;
     }
     
+    public bool can_switch_conversation_view() {
+        bool inline;
+        return should_create_new_composer(null, null, out inline);
+    }
+    
     public bool any_inline_composers() {
         foreach (ComposerWidget cw in composer_widgets)
             if (cw.state != ComposerWidget.ComposerState.DETACHED)
diff --git a/src/client/composer/composer-widget.vala b/src/client/composer/composer-widget.vala
index 145e5d5..bb88db6 100644
--- a/src/client/composer/composer-widget.vala
+++ b/src/client/composer/composer-widget.vala
@@ -147,6 +147,13 @@ public class ComposerWidget : Gtk.EventBox {
     
     public Geary.EmailIdentifier? referred_id { get; private set; default = null; }
     
+    public bool blank {
+        get {
+            return to_entry.empty && cc_entry.empty && bcc_entry.empty &&
+                subject_entry.buffer.length == 0 && !editor.can_undo() && attachment_files.size == 0;
+        }
+    }
+    
     private ContactListStore? contact_list_store = null;
     
     private string? body_html = null;
diff --git a/src/client/conversation-list/conversation-list-view.vala 
b/src/client/conversation-list/conversation-list-view.vala
index 4aac993..55f3e7c 100644
--- a/src/client/conversation-list/conversation-list-view.vala
+++ b/src/client/conversation-list/conversation-list-view.vala
@@ -204,7 +204,7 @@ public class ConversationListView : Gtk.TreeView {
         }
         
         if (!get_selection().path_is_selected(path) &&
-            !GearyApplication.instance.controller.should_create_new_composer())
+            !GearyApplication.instance.controller.can_switch_conversation_view())
             return true;
         
         if (event.button == 3 && event.type == Gdk.EventType.BUTTON_PRESS) {


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